当选择选项菜单中的项目时,我想调用GLES20方法.
public boolean onoptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.clear:
GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);
break;
// ...
}
}
这不起作用,因为我在主线程而不是GLThread.它说:
call to OpenGL ES API with no current
context (logged once per thread)
但是我需要做些什么才能让事情发挥作用?
解决方法
我自己找到了答案:
public boolean onoptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.clear:
// GLSurfaceView.queueEvent
surface.queueEvent(new Runnable() {
@Override
public void run() {
GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);
}
});
break;
// ...
}
}