openGL 中的初学者透明度/不透明
我正在学习 OpenGL 的 NeHe 教程...我正在学习第 8 课(通过混合绘制立方体)。 http://nehe.gamedev.net/data/lessons/lesson.asp ?lesson=08
我想尝试并将一半的面更改为不透明,以便始终有一个与不透明面相对的半透明面,并且能够旋转立方体...
我更改了代码一点点,整个源代码都在那里: http://pastebin.com/uzfSk2wB 我更改了一些内容:
- 默认启用混合并将混合函数设置为 glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
- 更改了绘制脸部的顺序以及每个脸部的颜色。
- 我设置了深度测试
- 我画了所有不透明的脸
- 我禁用深度测试
- 我画了所有透明的面
现在,很难确切地说出了什么问题,但它看起来绝对不正确,我无法识别哪张脸与透明的相比是不透明的,有时有些脸在应该绘制的时候似乎没有被绘制...等等...
似乎计算前面的脸与后面的脸相比并不是微不足道的(尽管我确信可能),我希望有一种方法可以不需要这样做。
要么检查我的代码中有什么问题,要么检查这是否不是正确的做法。
I am going through the NeHe tutorials for OpenGL... I am at lesson 8 (drawing a cube with blending). http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=08
I wanted to experiment and change half of the faces to be opaque so that there is always a semi-transparent face opposite to an opaque one and be able to rotate the cube...
I changed the code a little bit, the entire source is there : http://pastebin.com/uzfSk2wB
I changed a few things :
- enable blending by default and set the blending function to glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
- changed the order of drawing the faces and colors for each face.
- I set the depth testing
- I draw all the opaque faces
- I disable depth test
- I draw all the transparent faces
Now, it's hard to tell exactly what is going wrong, but it definitely does not look right, I cannot recognize what face is opaque compared to the transparent ones, sometimes some faces do not seem to get drawn when they should...etc...
Seems like calculating what face is in front compared to back would not be trivial (although I am sure possible), I hope there is a way of doing that would not need to do that.
Looking either for what is wrong in my code or whether this is not the right way of doing it in the first place.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果在绘制透明面之前禁用深度测试,则绘制透明面时将不考虑其正确的 z 顺序。看起来透明的面可能被绘制在所有其他面的上方。保持深度测试开启。
If you disable depth testing before drawing the transparent faces, then they will be drawn with no regard for their correct z-ordering. It probably looks like the transparent faces are being drawn atop all the other faces. Leave depth testing on.