Problem with transparent diffuse

I have a light and a transparent sphere. I set the diffuse material to make it transparent, but it doesn’t work at all viewing angles. At some (camera) angles, there are some weird darker patches.

Complete sourcecode here, the relevant bit (i think):

GLfloat diffuse[] = { 1.0, 0.0, 0.0, 0.5 };
glMaterialfv(GL_FRONT, GL_DIFFUSE, diffuse);

picture (but it does get arbitrary weird at other angles).
My only guess would be that this is the wrong way to make an object transparent, but it seemed logical to me.

First I see that you haven’t enabled the depth test. So in your display function call glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);.In your init function call glEnable(GL_DEPTH_TEST). In your main function call glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH); Now your display should work.

Edit: replace GLUT_RGB with GLUT_RGBA

I had depth on and off for testing, doesn’t change anything. Exactly the same code with depth test: clicky (still same problem).

looks like depth buffer to me to. its important to not only use depth test but also to supply the correct projection matrix with correct near/far values. other then that, do you use backface culling? try setting culling to FRONT and render the sphere once, then set culling to BACK and render sphere again.

_NK47 give you in part the solution, I have tested your code with glEnable(GL_CULL_FACE) and the output is ok.

Yes it works. I should have checked that, thanks a lot you two!