为什么我的彩色立方体不能与 GL_BLEND 一起使用?
当我使用 GL_BLEND 时,我的立方体未按预期渲染。
glEnable(GL_CULL_FACE);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE);
我在前面绘制一些半透明顶点时也遇到了类似的问题,这很可能是相关的。
它应该是这样的:
普通立方体 http://img408.imageshack.us/img408/2853/normalcube.png
这是它实际的样子:
深色立方体 http://img7.imageshack.us/img7/7133/darkcube.png
立方体是这样绘制的:
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glLoadIdentity();
// ... do some translation, rotation, etc ...
drawCube();
glPopMatrix();
// ... swap the buffers ...
My cube isn't rendering as expected when I use GL_BLEND.
glEnable(GL_CULL_FACE);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE);
I'm also having a similar problem with drawing some semi-opaque vertices in front, which could well be related.
Related: Why do my semi-opaque vertices make background objects brighter in OpenGL?
Here's what it's supposed to look like:
Normal cube http://img408.imageshack.us/img408/2853/normalcube.png
And here's what it actually looks like:
Dark cube http://img7.imageshack.us/img7/7133/darkcube.png
Please see the code used to create the colored cube, and the code used to actually draw the cube.
The cube is being drawn like so:
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glLoadIdentity();
// ... do some translation, rotation, etc ...
drawCube();
glPopMatrix();
// ... swap the buffers ...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以尝试在绘制立方体之前禁用所有照明:
You could try disabling all lighting before drawing the cube:
看起来你在第二个上启用了照明,
在绘制之前尝试使用 glShadeModel( GL_FLAT ),
It looks like you have lighting enabled on the second one,
try with a glShadeModel( GL_FLAT ) before drawing,
这让我跺脚。 看起来有些顶点有一些不透明的 alpha 值。 但是,您发布的代码全部为 1. for alpha。 那么......为了进行更多调试,您是否尝试将透明颜色更改为非黑色? 说绿色?
从代码中,我怀疑照明是否打开,因为没有指定法线。
最后评论,题外话...你真的不应该使用
glBegin
/glEnd
(每个顶点 2 个函数调用 + 每个基元 2 个函数调用确实不是最近发展的一个好用法OpenGL)。 尝试使用glDrawElements
和QUAD_LIST
,或者更好的是TRIANGLE_LIST
。 您已经为此精心准备了数据。This has me stomped. What it looks like is that some vertices have some alpha values that are non-opaque. However the code you posted has all 1. for alpha. So... in order to debug more, did you try to change your clear color to something non-black ? Say green ?
From the code, I doubt lighting is turned on, since no normals were specified.
Last comment, offtopic... You should really not use
glBegin
/glEnd
(2 function calls per vertex + 2 per primitive is really not a good usage of the recent developments in OpenGL). TryglDrawElements
withQUAD_LIST
, or even better,TRIANGLE_LIST
. You already have the data nicely laid out for that.