0
我需要通過Android本機代碼中的Open GLES渲染圖像。圖像的字節數組在Java代碼中生成並作爲參數發送給本機代碼。但通過本機代碼進行渲染時總是顯示黑屏。原生代碼是:渲染圖像打開GLES android ndk
JNIEXPORT int JNICALL
Java_com_example_hellojni_MyView_renderByEgl(JNIEnv *env, jobject instance, jobject surface,
jint width, jint height, jbyteArray byteArray_) {
EGLDisplay display;
EGLConfig config;
EGLContext context;
EGLSurface eglSurface;
ANativeWindow* pWindow = ANativeWindow_fromSurface(env, surface);
EGLint num_config;
display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
eglInitialize(display, NULL, NULL);
eglBindAPI(EGL_OPENGL_ES_API);
eglChooseConfig(display, attribute_list, &config, 1, &num_config);
context = eglCreateContext(display, config, EGL_NO_CONTEXT, NULL);
eglSurface = eglCreateWindowSurface(display, config, pWindow, NULL);
eglMakeCurrent(display, eglSurface, eglSurface, context);
jboolean isCopy;
unsigned char * pCData = (unsigned char*)(*env)->GetByteArrayElements(env, byteArray_, &isCopy);
if(isCopy)
{
(*env)-> ReleaseByteArrayElements(env, byteArray_, pCData, JNI_ABORT);
}
glTexImage2D(GL_TEXTURE_2D,0,10,10,width,height,GL_RGBA,GL_UNSIGNED_BYTE,pCData);
glFlush();
eglSwapBuffers(display, eglSurface);
sleep(10);
return EXIT_SUCCESS;
}
我只想渲染一個圖像。是否有一種方法可以將緩衝區寫入EGLSurface? –