我试图创建 EGL 环境以在本地功能调用中绘制 OpenglES 的所有内容。 问题在于我需要访问本地WindowType 实例, 但我只能找到一个函数来创建它( 我无法找到如何连接它 ) 。 然而, 即使我创建了一个函数, 我怀疑这是错误的, 因为我真正需要的就是由我称之为本地功能的地平面观察实例创建的函数 。
这是代码:
static int egl_init() {
const EGLint attribs[] = {
EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
EGL_BLUE_SIZE, 8,
EGL_GREEN_SIZE, 8,
EGL_RED_SIZE, 8,
EGL_NONE
};
EGLint w, h, dummy, format;
EGLint egl_major_version, egl_minor_version;
EGLint numConfigs;
EGLConfig egl_config;
EGLSurface egl_surface;
EGLContext egl_context;
EGLDisplay egl_display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
// v--------- This is where I should get the display window
NativeWindowType display_window;
display_window = android_createDisplaySurface();
eglInitialize(egl_display, &egl_major_version, &egl_minor_version);
printf("GL Version: %d.%d
", egl_major_version, egl_minor_version);
if (!eglChooseConfig(egl_display, attribs, &egl_config, 1, &numConfigs))
{
printf("eglChooseConfig failed
");
if (egl_context == 0) printf("Error code: %x
", eglGetError());
}
eglGetConfigAttrib(egl_display, egl_config, EGL_NATIVE_VISUAL_ID, &format);
// v---------- This requires that I link libandroid, it is found in android/native_window.h
ANativeWindow_setBuffersGeometry(display_window, 0, 0, format);
egl_context = eglCreateContext(egl_display, egl_config, EGL_NO_CONTEXT, NULL);
if (egl_context == 0) LOGE("Error code: %x
", eglGetError());
egl_surface = eglCreateWindowSurface(egl_display, egl_config, display_window, NULL);
if (egl_surface == 0) LOGE("Error code: %x
", eglGetError());
if (eglMakeCurrent(egl_display, egl_surface, egl_surface, egl_context) == EGL_FALSE) {
LOGE("Unable to eglMakeCurrent");
return -1;
}
return 0;
}
谢谢你的帮忙