我有一个问题,渲染器对象似乎根本没有调用它的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);

}

主要 Activity 是:
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无法正确呈现?

最佳答案

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

经验教训,请自己避免歧义,因为编译器/解析器不会告诉您!

关于java - 在Android上未调用onDrawFrame,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/11279209/

10-09 04:37