2010-08-01 75 views
2

這就是Dalvik LogCat每當我取消註釋最後一行時所說的內容。因此,在某個地方,目前的情況根本不會被創建。爲什麼?謝謝你的幫助。」在沒有當前上下文的情況下調用OpenGL ES API「

final EGL10 egl = (EGL10) EGLContext.getEGL(); 
final EGLDisplay eglDisplay = egl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY); 
egl.eglInitialize(eglDisplay, version); 

int[] configSpec = { 
EGL10.EGL_NONE 
}; 

final EGLConfig[] config = new EGLConfig[1]; 
int num_configs[] = new int[1]; 
egl.eglChooseConfig(eglDisplay, configSpec, config, 1, num_configs); 

final EGLContext eglContext = egl.eglCreateContext(eglDisplay, config[0], EGL10.EGL_NO_CONTEXT, null); 
final GL10 gl = (GL10) eglContext.getGL(); 

int b[] = new int[w * (h)]; 
IntBuffer ib = IntBuffer.wrap(b); 
ib.position(0); 
gl.glReadPixels(w, 0, w, h, GL10.GL_RGB,GL10.GL_UNSIGNED_BYTE, ib); 

回答

4

在調用任何OpenGL函數之前,您應該使用EGL.eglMakeCurrent。這將使線程中的上下文成爲當前。

+1

感謝您幫助我Matias。我對此有個疑問:爲了獲得在EGL.eglMakeCurrent中使用的'window'arg,我必須獲取由eglCreateWindowSurface(display,config,native_window,attrib_list)返回的'window'值。我的問題是:什麼是native_window,我從哪裏獲得? – user225626 2010-08-02 04:48:05

+0

我該如何在android中做到這一點? – Maysam 2014-03-07 18:49:20

相關問題