在不透明对象内绘制透明对象
我试图在不透明的笼子内绘制一个透明的物体,但无论我尝试什么,我都无法做到正确。
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glClearColor( 0.0f, 0.0f, 0.0f, 0.0f );
glDisable(GL_BLEND);
glEnable(GL_DEPTH_TEST);
glEnable(GL_CULL_FACE);
glCullFace(GL_BACK);
glColor4f(1.0, 1.0, 1.0, 1.0);
drawCage();
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glColor4f(0.0, 0.0, 0.0, 0.5);
drawObject();
glPopAttrib();
这使得里面的透明物体出现在前面,尽管它在里面。
我做错了什么,可能与我使用的着色器有关
I'm trying to draw a transparent object inside an opaque cage, but what ever I seem to try I can't get it right.
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glClearColor( 0.0f, 0.0f, 0.0f, 0.0f );
glDisable(GL_BLEND);
glEnable(GL_DEPTH_TEST);
glEnable(GL_CULL_FACE);
glCullFace(GL_BACK);
glColor4f(1.0, 1.0, 1.0, 1.0);
drawCage();
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glColor4f(0.0, 0.0, 0.0, 0.5);
drawObject();
glPopAttrib();
This makes the transparent object within appear in front of the, despite it being inside it.
What am I doing wrong, could it be something to do with the shaders I am using
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
有几件事。
希望有帮助
A few things.
Hope that helps
那么你的透明度就不会有问题。如果您启用了深度测试,并且您的对象出现在另一个对象的前面,则说明您的几何图形或绘图例程出现了问题。可能是一百万件事,先尝试禁用剔除,然后看看会发生什么。
另一方面,您尝试渲染具有 1.0f alpha 的恒定颜色的透明对象。这意味着完全不透明。你确定吗?
Then you don't have a problem with your transparency. If you've got a depth test enabled, and your object appears in front of the other one, you've got a problem either in your geometry, or in your drawing routine. Could be a million things, try disabling culling first since and see what happens.
On the other hand, you're trying to render a transparent object with a constant colour that has 1.0f alpha. This means fully opaque. Are you sure about that?