XGo*_*het 5 android opengl-es android-ndk
我正在尝试制作一个基于 NDK 的 OpenGL 应用程序。在我的代码中的某个时刻,我想检查设备上可用的 OpenGL 版本。
\n\n我正在使用以下代码:
\n\nconst char *version = (const char *) glGetString(GL_VERSION);\nif (strstr(version, "OpenGL ES 2.")) {\n // do something \n} else {\n __android_log_print(ANDROID_LOG_ERROR, "NativeGL", "Open GL 2 not available (%s)", version=;\n}\nRun Code Online (Sandbox Code Playgroud)\n\n问题是版本字符串始终等于"OpenGL ES-CM 1.1"。
我正在 Moto G (Android 4.4.4) 和 Samsung Galaxy Nexus (Android 4.3) 上进行测试,两者都兼容 OpenGL ES 2.0(moto G 也兼容 OpenGL ES 3.0)。
\n\nEGL_CONTEXT_CLIENT_VERSION我尝试在初始化显示时强制执行,但随后eglChooseConfig 返回 0 个配置。当我在默认配置中测试上下文客户端版本值时,它始终为 0 :
const EGLint attrib_list[] = {\n EGL_BLUE_SIZE, 8,\n EGL_GREEN_SIZE, 8,\n EGL_RED_SIZE, 8,\n EGL_NONE\n};\n\n// get the number of configs matching the attrib_list\nEGLint num_configs;\neglChooseConfig(display, attrib_list, NULL, 0, &num_configs);\nLOG_D(TAG, " \xe2\x80\xa2 %d EGL configurations found", num_configs);\n\n// find matching configurations\nEGLConfig configs[num_configs];\nEGLint client_version = 0, depth_size = 0, stencil_size = 0, surface_type = 0;\neglChooseConfig(display, requirements, configs, num_configs, &num_configs);\nfor(int i = 0; i < num_configs; ++i){\n\n eglGetConfigAttrib(display, configs[i], EGL_CONTEXT_CLIENT_VERSION, &client_version);\n\n\n LOG_D(TAG, " client version %d = 0x%08x", i, client_version);\n\n}\n\n// Update the window format from the configuration\nEGLint format;\neglGetConfigAttrib(display, config, EGL_NATIVE_VISUAL_ID, &format);\nANativeWindow_setBuffersGeometry(window, 0, 0, format);\n\n// create the surface and context\nEGLSurface surface = eglCreateWindowSurface(display, config, window, NULL);\nEGLContext context = eglCreateContext(display, config, NULL, NULL);\nRun Code Online (Sandbox Code Playgroud)\n\n我正在链接 Open GL ES 2.0 库:这是我的摘录Android.mk
LOCAL_LDLIBS := -landroid -llog -lEGL -lGLESv2\nRun Code Online (Sandbox Code Playgroud)\n
感谢 mstorsjo 给出的提示,我设法获得了正确的初始化代码,如果其他人遇到此问题,请在此处显示。
const EGLint attrib_list[] = {
// this specifically requests an Open GL ES 2 renderer
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
// (ommiting other configs regarding the color channels etc...
EGL_NONE
};
EGLConfig config;
EGLint num_configs;
eglChooseConfig(display, attrib_list, &config, 1, &num_configs);
// ommiting other codes
const EGLint context_attrib_list[] = {
// request a context using Open GL ES 2.0
EGL_CONTEXT_CLIENT_VERSION, 2,
EGL_NONE
};
EGLContext context = eglCreateContext(display, config, NULL, context_attrib_list);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5352 次 |
| 最近记录: |