Drawing a solid sphere with transparency in openGL

2019-05-10 08:00发布

问题:

I want to draw a glutSolidSphere with some transparency, but it doesn't seem to work.

glColor4f(1, 0, 0, 0); // should be completely invisible
glPushMatrix();
glTranslatef(position.x, position.y, position.z);
glutSolidSphere(3, 5, 5);
glPopMatrix();

In my main function, I initialize with the following display mode:

glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA | GLUT_ALPHA);

What am I missing here?

回答1:

You need to explicitely setup alpha blending . Another example.

glEnable (GL_BLEND);

glBlendFunc (GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);