Using OpenGL from the main thread on Android

I would like to call the GLES20 method when an item is selected from the options menu.

 public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.clear: GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT); break; // ... } } 

This does not work, as I enter the main thread, not GLThread . It says:

OpenGL ES API call without current context (registered once per thread)

But what do I need to do to make everything work?

+6
android multithreading opengl-es
source share
1 answer

I found the answer myself:

 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; // ... } } 
+14
source share

All Articles