lighting problem

Hi, I have a problem using openGL light.

I draw two 3D .obj model. Loader works fine, vertex and normals are correct. The problem is that when I enable light the effect on one of the model is bad:

good model with light:
[ATTACH=CONFIG]160[/ATTACH]

bad model with light:
[ATTACH=CONFIG]161[/ATTACH]

bad model without light
[ATTACH=CONFIG]162[/ATTACH]

Here is the light code in render function:

gluLookAt(20.0f, 5.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f);
    
glEnable(GL_LIGHT0);
glEnable(GL_LIGHTING);
float lightPos[] = {20.0, 10, 1, 0.0};
glLightfv(GL_LIGHT0, GL_POSITION, lightPos);

// here draw model

Any suggestions? Light params are incorrect?

I had similar problem, and i fixed it by setting znear parameter to 1.0.
Check My thread, maybe My code from it will help you to find solution.

[QUOTE=stefkos;1237551]I had similar problem, and i fixed it by setting znear parameter to 1.0.
Check My thread, maybe My code from it will help you to find solution.

Thank you, I’ve already read your topic but my znear value is 1.0 in reshape func

glViewport(0, 0, (GLsizei)width, (GLsizei)height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();  
	
gluPerspective(60, (GLfloat)width / (GLfloat)height, 1.0, 100.0);

I’ve also tried with different light position params but I didn’t solve the problem

Another information.

In my code I draw at first some objects without light, then I set up light and draw my 3D model.
Here is the code:

glEnable(GL_NORMALIZE);


   // glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
    
   // gluLookAt(0.0f, 0.0f, 7.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, -1.0f);
    gluLookAt(0.0f, 0.0f, 2.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, -1.0f);
    


    /**** init & render arena *****/
    
   // gluOrtho2D(-2.0,2.0,-2.0,2.0);
    glPushMatrix();
        glScalef(0.08, 0.08, 0.08);
        glTranslatef(11.0, 8.8, 0.0);
        if(!arenas[currArena].init()) {
            cout << "Impossibile init arena" << endl;
            return;
        }
        arenas[currArena].render();
    glPopMatrix();


    
 	//gluLookAt(0.0f, 0.0f, 2.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, -5.0f);
	


   // m_Background->render();






    glColor3f(1.0, 1.0, 1.0);
    
    if(currCycle>0) {
        left1->render();
    }
    if(currCycle<numCycles-1) {
        right1->render();
    }
    
    if(currArena>0) {
        left2->render();
    }
    if(currArena<numArena-1) {
        right2->render();
    }
    
    play->render();
    
    writeParams();
    glBegin(GL_QUADS);
        glColor3f(0.1,0.1,0.4);
        glVertex3f(-2.3,0.5,-1.0);
        glVertex3f(-0.1,0.5,-1.0);
        glVertex3f(-0.1,1.65,-1.0);
        glVertex3f(-2.3,1.65,-1.0);
    glEnd();

//here new gluLookAt
// set up light
// draw model


I’m trying to test light and my .obj loader in a simple scene using a simple .obj polygon ( a parallelepiped).
If I don’t enable light the polygon seems ok.
If I enable light I’ve noticed that one face is correct and other faces show the opposite not-illuminated face. Here are the images:

The right face
[ATTACH=CONFIG]165[/ATTACH]

wrong faces:
[ATTACH=CONFIG]166[/ATTACH]

[ATTACH=CONFIG]167[/ATTACH]

[ATTACH=CONFIG]168[/ATTACH]

I don’t understand if the normals are wrong or vertices or some other thing.
I printed several times data laoded from my objLoader and it seems ok

Solved my problem! I didn’t put GLUT_DEPTH in my glut window!