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 不能正确渲染?

4

1 回答 1

3

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

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

于 2012-07-01T19:51:17.503 回答