PDA

View Full Version : Has some transparency



Miglu
10-24-2010, 09:23 AM
I have this OpenGL initialization code:
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
glBlendFunc (GL_SRC_ALPHA, GL_ONE);
glEnable(GL_BLEND);
glEnable(GL_LINE_SMOOTH);

glEnable (GL_DEPTH_TEST);
glEnable (GL_LIGHT0);
glEnable(GL_LIGHTING);
glEnable (GL_COLOR_MATERIAL);
glColorMaterial (GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);

GLfloat mat_specular[] = { 1.0, 1.0, 1.0, 1.0 };
GLfloat mat_shininess[] = { 100.0 };
GLfloat light_position[] = { 1.0, 1.0, 1.0, 0.0 };

glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess);
glLightfv(GL_LIGHT0, GL_POSITION, light_position);
This is in my drawing method:
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
GLfloat light_position[] = { 1.0, 1.0, 1.0, 0.0 };
glLightfv(GL_LIGHT0, GL_POSITION, light_position);
glRotatef(rot, viewAspect*0.5, size.height*0.5, 0.0);The model has some transparency. What is the problem?

ZbuffeR
10-24-2010, 01:30 PM
Try instead to use :
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); // for premultiplied alpha
or
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // for classic blending

Miglu
10-24-2010, 01:55 PM
Those did not work. Could you compile my code to see what I mean.