0

我的主要活动如下。我将内容视图设置为 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..

}

}

4

1 回答 1

0

您缺少的一件大事是 gameView.setRenderer(new SFGameRenderer())。这里缺少很多东西,所以其中任何一个都可能导致事情崩溃。

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

于 2013-02-22T02:30:14.143 回答