Why does my colored cube not work with GL_BLEND?

假如想象 提交于 2019-12-08 05:18:53

问题


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 ...

回答1:


You could try disabling all lighting before drawing the cube:

glDisable(GL_LIGHTING);



回答2:


It looks like you have lighting enabled on the second one,

try with a glShadeModel( GL_FLAT ) before drawing,




回答3:


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). Try glDrawElements with QUAD_LIST, or even better, TRIANGLE_LIST. You already have the data nicely laid out for that.



来源:https://stackoverflow.com/questions/721998/why-does-my-colored-cube-not-work-with-gl-blend

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!