简体   繁体   English

Android NDK C ++ openGL ES 2上下文显示不正确

[英]Android NDK C++ openGL ES 2 context gives bad display

I am trying to implement a openGL ES 2.0 game using NDK in C++ . 我正在尝试使用C ++中的NDK实现openGL ES 2.0游戏。 My test device was ASUS Zenphone 5 I am pretty sure it supports openGL ES 2.0 as it can run games based on openGL ES 2 from play store very smoothly and also the helloGl2 sample in androind NDK. 我的测试设备是ASUS Zenphone 5,我可以肯定它支持openGL ES 2.0,因为它可以非常流畅地运行来自Play商店的基于openGL ES 2的游戏,还可以运行androind NDK中的helloGl2示例。

When I called glCreateShader log cat gave an error "called unimplemented api" by googling a bit I found out it was because the app was using openGL ES 1 context by default. 当我调用glCreateShader日志猫通过glCreateShader了一个错误“未实现的api”,我发现这是因为该应用默认情况下使用的是openGL ES 1上下文。

So I modified the EGL context creation code from: 因此,我从以下位置修改了EGL上下文创建代码:

context = eglCreateContext(display, config, NULL, NULL);

to

EGLint contextAttrs[] = {
        EGL_CONTEXT_CLIENT_VERSION,2,EGL_NONE
};

context = eglCreateContext(display, config, NULL, contextAttrs);

Now this gave a different error 现在这给了另一个错误

 E/libEGL(12670): validate_display:257 error 3008 (EGL_BAD_DISPLAY)

However when I tested it on a galaxy s3 (GT-I9100) there was no BAD DISPLAY ERROR , but the app crashed on calling glCreateShader with fatal signal SIGSEV 但是,当我在银河s3(GT-I9100)上进行测试时,没有错误显示错误,但是应用程序在使用致命信号SIGSEV调用glCreateShader时崩溃

What is going on here? 这里发生了什么?

If you are creating an ES 2 context, you also need to include EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT in the attributes for the EGL config, it's not enough to add EGL_CONTEXT_CLIENT_VERSION, 2 to the context attributes. 如果要创建ES 2上下文,则还需要在EGL配置的属性中包括EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BITEGL_CONTEXT_CLIENT_VERSION, 2向上下文属性添加EGL_CONTEXT_CLIENT_VERSION, 2是不够的。

Also, make sure you are linking to libGLESv2.so ( -lGLESv2 in LOCAL_LDLIBS ), and make sure you aren't linking in libGLESv1_CM.so by accident. 另外,请确保您链接到libGLESv2.so( -lGLESv2中的LOCAL_LDLIBS ),并确保您没有偶然地链接到libGLESv1_CM.so。 (Using them both in the same process requires a bit of extra trickery.) (在相同的过程中使用它们都需要一些额外的技巧。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM