在Android上没有调用onDrawFrame

时间:2012-07-01 02:48:21

标签: java android

我遇到一个问题,渲染器对象似乎根本没有调用onDrawFrame。调试器永远不会在函数内部遇到断点。因此,我的广场不是画画。这是代码,如果您还需要其他信息,请告诉我们:

public class renderer implements GLSurfaceView.Renderer {

Square square;

public void onDrawFrame(GL10 unused) {
    GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);
    square.Draw();
}

public void onSurfaceChanged(GL10 gl, int width, int height) {
    GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);
}

public void onSurfaceCreated(GL10 unused, int width, int height) {
    GLES20.glViewport(0, 0, width, height);

}

public void onSurfaceCreated(GL10 gl, EGLConfig config) {
    square = new Square(5, 5);

}

主要活动是:

public class gameActivity extends Activity {
/** Called when the activity is first created. */

private GLSurfaceView mGLView;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    staticHolder.context = getApplicationContext();
    mGLView = new GLSurface(this);
    setContentView(mGLView);
}
@Override
protected void onPause() {
    super.onPause();
    // The following call pauses the rendering thread.
    // If your OpenGL application is memory intensive,
    // you should consider de-allocating objects that
    // consume significant memory here.
    mGLView.onPause();
}

@Override
protected void onResume() {
    mGLView.onResume();
}


class GLSurface extends GLSurfaceView
{
    renderer r = new renderer();
    public GLSurface(Context context)

    {
        super(context);

        setEGLContextClientVersion(2);
        setRenderer(r);
        setRenderMode(GLSurfaceView.RENDERMODE_CONTINUOUSLY);
    }
}

}

目前屏幕只是黑色。有没有想过为什么openGL没有正确渲染?

1 个答案:

答案 0 :(得分:3)

好的,这真的很愚蠢,但开始没有问题。问题是Eclipse / Java不关心像C#和其他语言那样的歧义(如果我错了,请纠正我)。问题是我设法在不同的位置复制相同的类,一个更新,另一个不更新。最终的结果是它抓住了它能找到的第一个。

经验教训,请注意自己的歧义,因为编译器/解析器不会告诉你!