我在OpenGL(非固定管道)中编写了一个应用程序。 我已经使用NDK将应用程序移植到Android,并且存在一些问题。 一切都比较暗,有些物体没有显示出来。
视窗
Windows http://vvcap.net/db/WF0ilLDB2D3F72UlbPjA.png
Android的
NDK http://vvcap.net/db/KhD0q9XHJc_q5vFsda10.png
右边的茶壶是黑色的,有一些奇怪的反射。 飞球的下半部分是黑色的 一切都是黑暗的 水看起来并不正确。 环保茶壶有粉红色。移植到OpenGL Es 2.0时有没有人遇到过类似的问题? 除纹理加载格式外,我没有更改着色器或代码中的任何内容:
#ifdef _NDK if (IsAlpha) glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, Width, Height, 0, GL_RGBA, GL_UNSIGNED_BYTE, Bits); else glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, Width, Height, 0, GL_RGB, GL_UNSIGNED_BYTE, Bits); #else if (IsAlpha) glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, Width, Height, 0, GL_BGRA, GL_UNSIGNED_BYTE, Bits); else glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, Width, Height, 0, GL_BGR, GL_UNSIGNED_BYTE, Bits); #endif谢谢!
I've written an application in OpenGL (not-fixed pipeline). I've ported the application to Android using NDK and there's a few problems. Everything is darker, and some objects don't show as they should.
Windows
Windows http://vvcap.net/db/WF0ilLDB2D3F72UlbPjA.png
Android
NDK http://vvcap.net/db/KhD0q9XHJc_q5vFsda10.png
The teapot on the right is black and has some strange reflections. Lower half of the flying ball is black Everything is dark Water doesn't look right at all. Teapot with environmental has a pink color.Did anyone have similiar problems while porting to OpenGL Es 2.0 ? I didn't change anything in the shaders or the code except texture loading format:
#ifdef _NDK if (IsAlpha) glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, Width, Height, 0, GL_RGBA, GL_UNSIGNED_BYTE, Bits); else glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, Width, Height, 0, GL_RGB, GL_UNSIGNED_BYTE, Bits); #else if (IsAlpha) glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, Width, Height, 0, GL_BGRA, GL_UNSIGNED_BYTE, Bits); else glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, Width, Height, 0, GL_BGR, GL_UNSIGNED_BYTE, Bits); #endifThanks!
最满意答案
在桌面代码路径中,您将BGR作为格式传递给TexImage2D ,而在Android代码路径中,您选择RGB 。
GL无法知道Bits包含哪些数据,只是简单地从数据中构造RGBA值(在RGB或BGR格式的情况下用1.0代替A组件。)如果不预处理数据以反映格式,如果布局RGB纹理的数据,GL将简单地获取R分量的B量值。
纠正格式,你会没事的。
In your desktop code path you pass BGR as the format to TexImage2D, while in you Android code path, you choose RGB.
The GL has no way to know what data Bits holds and simply constructs RGBA values from the data (substituting 1.0 for the A component in case of an RGB or a BGR format.) If you don't preprocess your data to reflect the format, the GL will simply take the B component values for the R component if you lay out the data for a RGB texture.
Correct the format and you'll be fine.
更多推荐
发布评论