我遇到了渲染器对象似乎根本没有被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 不能正确渲染?