将OpenGL应用程序移植到NDK。(Porting OpenGL application to NDK. Shaders effects look different [closed])

编程入门 行业动态 更新时间:2024-10-17 11:29:43
将OpenGL应用程序移植到NDK。(Porting OpenGL application to NDK. Shaders effects look different [closed])

我在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); #endif

Thanks!

最满意答案

在桌面代码路径中,您将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.

更多推荐

本文发布于:2023-08-01 23:05:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1365805.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:应用程序   Porting   NDK   OpenGL   effects

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!