问题
Is there a way to create gl textures outside of my implementation of GLSurfaceView.Renderer? I've only been able to create textures in the onSurfaceCreated method, since that's where I have access of the GL10 gl variable. It's limiting me because I can't create open gl textures on demand in my code and have to create everything in that method.
Alternatively, is there a way to get at the GL10 gl variable outside of the GLSurfaceView.Renderer? Or is there even another way to create gl textures?
回答1:
I found something that works, getting the EGLContext.
import javax.microedition.khronos.egl.EGLContext;
import javax.microedition.khronos.egl.EGL10;
import javax.microedition.khronos.opengles.GL10;
// in code.
EGL10 egl = (EGL10)EGLContext.getEGL();
GL10 gl = (GL10)egl.eglGetCurrentContext().getGL();
回答2:
you should keep your code separated. GL stuff should be done in gl related classes. logic should be done in logic related classes, having no idea about gl stuff...
so, no, you cant created gl textures if you dont have access to the GL10 variable. also, i think that onSurfaceCreated is the right method to do that stuff.
来源:https://stackoverflow.com/questions/5979069/creating-a-gl-texture-outside-of-glsurfaceview-renderer