PDA

View Full Version : two sided lighting invalid



nkrobot
06-02-2009, 07:17 PM
Here is the problem. I use the methods
glLightModeli(GL_LIGHT_MODEL_TWO_SIDE,GL_TRUE); to make the polygon show both of the two sides. But actually if I add
a negtive matrixtransform when drawing a polygon ,both of the two sides will be unlit(dark actually)
. the question is I must use the two sided lighting and I have to use this type of matrix . Also the vetex's order I use is uncertain.
So Is there any way to solve the problem?
Thank you!
The code here...

//The matrix which may cause problem
GLfloat a[16] = {
1,0,0,0,
0,-1,0,0,//If a negtive matrix, an error accur.
0,0,1,0,
0,0,0,1
};//I know use the negtive num may cause the problem, but I have to use this because a lot of data I have contain this kind of matrix.

int InitGL(GLvoid)
{
//......
//enable light
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glFrontFace(GL_CCW);//it dosen't matter whether use GL_CW or GL_CCW
glLightModeli(GL_LIGHT_MODEL_TWO_SIDE,GL_TRUE);//if set two face show, sometimes the result is not as I expect.
//.....
}
//Draw scene
int DrawGLScene(GLvoid)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glMultMatrixf(a);//using the matrix causing problem

glTranslatef(-1.5f,0.0f,-12.0f);
glRotatef(rtri,0.0f,1.0f,0.0f);
//just draw a single triangle. but the light can effect neither of the two faces when I use the matrix which contains negtive num.
glBegin(GL_TRIANGLES);
glVertex3f( 0.0f, 1.0f, 0.0f);
glVertex3f(-1.0f,-1.0f, 0.0f);
glVertex3f( 1.0f,-1.0f, 0.0f);
glEnd();
return TRUE;
}

Dark Photon
06-03-2009, 05:00 AM
Please post responses off the duplicate post in the Beginner's forum here (http://www.opengl.org/discussion_boards/ubbthreads.php?ubb=showflat&Number=258345).