当 alpha 为 1.0 时,OpenGL ES Faces 看起来是透明的?
我正在为 iOS 上的应用程序开发一个对象(OBJ 文件)加载器,目前我已经成功读取了对象的顶点和面,现在我只是向导入的模型添加颜色。
我现在遇到了一个重大问题。立方体有六个面,除了两个相反的面为蓝色外,全部为红色。该立方体设置为旋转,以便我可以看到所有侧面,但颜色显示不正确,如下面的视频所示:
蓝色的面仅在两个蓝色部分重叠时显示,我不明白为什么 - 我习惯了 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:
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题是 GL_DEPTH_TEST 被禁用。 Opengl 没有进行任何深度测试,因此所有对象看起来都很奇怪。为了启用深度测试,您必须自己创建新的渲染缓冲区。这是关于如何创建此缓冲区的一个小片段:
此缓冲区是为 OpenGL ES 1.1 创建的,对于 2.0,只需删除所有“OES”扩展即可。创建深度缓冲区后,您现在可以启用深度测试,如下所示:
我自己也遇到过这个问题几次。
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:
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:
Had this problem few times myself.