本文介绍了在Android的主线程中使用OpenGL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
从选项菜单中选择一个项目后,我想调用 GLES20
方法.
I would like to call a GLES20
method when an item from the options menu is selected.
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.clear:
GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);
break;
// ...
}
}
这不起作用,因为我在 main
线程中,而不是在 GLThread
中.它说:
This does not work since I am in the main
thread and not in GLThread
. It says:
但是我要怎么做才能使工作正常?
But what do I have to do to get things working?
推荐答案
我自己找到了答案:
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;
// ...
}
}
这篇关于在Android的主线程中使用OpenGL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!