Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 2 of 2

Thread: two sided lighting invalid

  1. #1
    Junior Member Newbie
    Join Date
    Jun 2009
    Posts
    2

    two sided lighting invalid

    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...
    Code :
     //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;									
    }

  2. #2
    Senior Member OpenGL Guru Dark Photon's Avatar
    Join Date
    Oct 2004
    Location
    Druidia
    Posts
    2,882

    Re: two sided lighting invalid

    Quote Originally Posted by nkrobot
    ..if I add a negtive matrixtransform when drawing a polygon ,both of the two sides will be unlit...So Is there any way to solve the problem?
    Code :
    ...
    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();
    ...
    Where are your vertex normals? You need normals for OpenGL to evaluate the lighting at each vertex for you. See glNormal3f

    I never use two-sided lighting but my guess is you'll need to disable back-face culling: glDisable( GL_CULL_FACE ). Tweaking that alone may be enough. That y inversion in your MODELVIEW matrix is switching the winding order (i.e. whether your poly is front or back facing).

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •