OpenGL ES CustomView扩展了GLSurfaceView内容

时间:2012-12-23 15:45:46

标签: android opengl-es

我的主要活动如下。我将内容视图设置为sfgameview的实例。我也有一个渲染器有点像(在底部),但我错过了sfgameview的内容(99%的几率)或者让我的应用程序崩溃的东西。

package ---;

imports ---;    

public class Main extends Activity {

private SFGameView gameView;

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    gameView = new SFGameView(this);
    setContentView(gameView);

}

@Override
protected void onPause() {
    // TODO Auto-generated method stub
    super.onPause();
    gameView.onPause();
}

@Override
protected void onResume() {
    // TODO Auto-generated method stub
    super.onResume();
    gameView.onResume();
}

}

渲染器:

package ---;

imports ---;

public class SFGameRenderer implements Renderer {

variables---;

@Override
public void onDrawFrame(GL10 gl) {
    // TODO Auto-generated method stub
    try {
        Thread.sleep(1000/60);
    } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    gl.glClear(GL10.GL_COLOR_BUFFER_BIT|GL10.GL_DEPTH_BUFFER_BIT);



    gl.glEnable(GL10.GL_BLEND);
    gl.glBlendFunc(GL10.GL_ONE, GL10.GL_ONE);
}

@Override
public void onSurfaceChanged(GL10 gl, int width, int height) {
    gl.glViewport(0, 0, width, height);
    gl.glMatrixMode(GL10.GL_PROJECTION);
    gl.glLoadIdentity();
    gl.glOrthof(0f, 1f, 0f, 1f, -1f, 1f);

}

@Override
public void onSurfaceCreated(GL10 gl, EGLConfig arg1) {

    gl.glEnable(GL10.GL_TEXTURE_2D);

    gl.glClearDepthf(1.0f);
    gl.glEnable(GL10.GL_DEPTH_TEST);
    gl.glDepthFunc(GL10.GL_LEQUAL);

    gl.glEnable(GL10.GL_BLEND);
    gl.glBlendFunc(GL10.GL_ONE, GL10.GL_ONE);

    variable.loadTexture(gl, BACKGROUND_LAYER_ONE,
            context);
    variable2.loadTexture(gl, BACKGROUND_LAYER_TWO,
            context);
}

}

SFGameView:

package com.proandroidgames;

imports---;

public class SFGameView extends GLSurfaceView {

public SFGameView(Context context) {
    super(context);
    //this is empty and i dont know what to put..

}

}

1 个答案:

答案 0 :(得分:0)

你遗失的一件大事是gameView.setRenderer(新的SFGameRenderer())。这里有很多东西丢失,所以这些都可能导致事情崩溃。

您可以从Android OpenGL TrainingAndroid Lesson One: Getting Started获取正在运行的示例。免责声明:我维护第二个链接网站。