当 alpha 为 1.0 时,OpenGL ES Faces 看起来是透明的?

发布于 2024-12-06 18:28:36 字数 804 浏览 1 评论 0原文

我正在为 iOS 上的应用程序开发一个对象(OBJ 文件)加载器,目前我已经成功读取了对象的顶点和面,现在我只是向导入的模型添加颜色。

我现在遇到了一个重大问题。立方体有六个面,除了两个相反的面为蓝色外,全部为红色。该立方体设置为旋转,以便我可以看到所有侧面,但颜色显示不正确,如下面的视频所示:

http ://youtu.be/0L2AIFkd2Qk

蓝色的面仅在两个蓝色部分重叠时显示,我不明白为什么 - 我习惯了 PC 版 OpenGL,是否有什么东西我遗漏了导致这种奇怪的颜色?

着色是通过为每个顶点发送 RGBA RGBA RGBA 等格式的大型浮点数组来实现的;

// colours is the name of the array of floats
glColorPointer(colorStride, GL_FLOAT, 0, colors);   
glEnableClientState(GL_COLOR_ARRAY);
glDrawArrays(renderStyle, 0, vertexCount);  

[编辑]

问题现已解决,我只是从模型中绘制所有三角形,

glColor4f(0.5f, 0.5f, 0.0f, 1.0f);
glDrawArrays(GL_TRIANGLES, 4, 4);

仅对整个数组调用一次,当我将其拆分为模型中的每个面时,它允许我使用 GL_DEPTH_TEST 而不会导致屏幕移动空白的!

I am working on an object (OBJ File) loader for my app on iOS, currently I have successfully read the vertices and the faces of the object, and I am now just adding colours to the imported models.

I am coming across a major problem now. Out of a cube with six faces, all coloured red apart from two opposite faces which are coloured blue. This cube is set to rotate so I can see all sides, but the colours do not appear correctly as shown in the video below:

http://youtu.be/0L2AIFkd2Qk

The blue faces only shows when the two blue sections overlap, I cannot figure out why - I am used to OpenGL for PC, is there something I am missing which is causing this strange colouring?

The colouring is achieved by sending a large float array of the format RGBA RGBA RGBA etc for each vertex;

// colours is the name of the array of floats
glColorPointer(colorStride, GL_FLOAT, 0, colors);   
glEnableClientState(GL_COLOR_ARRAY);
glDrawArrays(renderStyle, 0, vertexCount);  

[EDIT]

Problem has now been solved, I was just drawing all the triangles from the model calling

glColor4f(0.5f, 0.5f, 0.0f, 1.0f);
glDrawArrays(GL_TRIANGLES, 4, 4);

only once for the whole array, when I split this up for each face in the model it allowed me to use GL_DEPTH_TEST without causing the screen to go blank!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

ˉ厌 2024-12-13 18:28:36

问题是 GL_DEPTH_TEST 被禁用。 Opengl 没有进行任何深度测试,因此所有对象看起来都很奇怪。为了启用深度测试,您必须自己创建新的渲染缓冲区。这是关于如何创建此缓冲区的一个小片段:

// Create the depth buffer. 
glGenRenderbuffersOES(1, &m_depthRenderbuffer);
glBindRenderbufferOES(GL_RENDERBUFFER_OES, m_depthRenderbuffer); 
glRenderbufferStorageOES(GL_RENDERBUFFER_OES,
GL_DEPTH_COMPONENT16_OES, width, height);

此缓冲区是为 OpenGL ES 1.1 创建的,对于 2.0,只需删除所有“OES”扩展即可。创建深度缓冲区后,您现在可以启用深度测试,如下所示:

    glEnable(GL_DEPTH_TEST);

我自己也遇到过这个问题几次。

The problem is that GL_DEPTH_TEST is disabled. Opengl is not making any depth testing so all your objects look weird. In order to enable depth testing you must create yourself new render buffer. This is a small snippet on how to crate this buffer:

// Create the depth buffer. 
glGenRenderbuffersOES(1, &m_depthRenderbuffer);
glBindRenderbufferOES(GL_RENDERBUFFER_OES, m_depthRenderbuffer); 
glRenderbufferStorageOES(GL_RENDERBUFFER_OES,
GL_DEPTH_COMPONENT16_OES, width, height);

This buffer is created for OpenGL ES 1.1, for 2.0 just delete all "OES" extensions. When you have created depth buffer you may now enable depth testing like this:

    glEnable(GL_DEPTH_TEST);

Had this problem few times myself.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文