PDA

View Full Version : Problem with transparent diffuse



SebastianPh
11-11-2008, 03:13 PM
Hellos,
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 (http://pastebin.com/m761a661b), the relevant bit (i think):

GLfloat diffuse[] = { 1.0, 0.0, 0.0, 0.5 };
glMaterialfv(GL_FRONT, GL_DIFFUSE, diffuse);
picture (http://bayimg.com/gaLAMAaBO) (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.

trinitrotoluene
11-11-2008, 03:34 PM
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

SebastianPh
11-11-2008, 11:27 PM
I had depth on and off for testing, doesn't change anything. Exactly the same code with depth test: clicky (http://pastebin.com/mc90b95e) (still same problem).

_NK47
11-12-2008, 02:37 AM
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.

trinitrotoluene
11-12-2008, 06:45 AM
_NK47 give you in part the solution, I have tested your code with glEnable(GL_CULL_FACE) and the output is ok.

SebastianPh
11-12-2008, 06:51 AM
Yes it works. I should have checked that, thanks a lot you two!