在Android上,onDrawFrame未被调用

6

我遇到了一个问题,渲染器对象似乎根本没有调用它的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无法正常渲染?


你的程序中的其他断点是否正常工作?如果你在onDrawFrame的第一行添加glClearColor(1,0,1,1),它是否仍然是黑色的?其他渲染器回调函数是否有触发? - Tim
GLES20.glClearColor(1, 0, 1, 1);,没有任何作用。 - Serguei Fedorov
其他渲染器回调函数会被调用吗?例如onSurfaceCreated或onSurfaceChanged? - Tim
其他函数中没有任何断点被触发。当我在GLSurface中设置一个断点时,它会被触发。调试器已经连接并工作正常,因为activity中的断点可以正常触发。 - Serguei Fedorov
1个回答

3

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

教训就是要自己注意歧义,因为编译器/解析器不会告诉你!


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接