PDA

View Full Version : lighting problem



Vincent22
05-14-2012, 09:49 AM
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:
719

bad model with light:
720

bad model without light
721


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?

stefkos
05-14-2012, 01:03 PM
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.
http://www.opengl.org/discussion_boards/showthread.php/177607-Lighting-problem?p=1237367#post1237367

Vincent22
05-15-2012, 01:27 AM
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.
http://www.opengl.org/discussion_boards/showthread.php/177607-Lighting-problem?p=1237367#post1237367

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

Vincent22
05-15-2012, 01:43 AM
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

Vincent22
05-16-2012, 01:17 PM
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
726

wrong faces:
727

728

729


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

Vincent22
05-16-2012, 01:48 PM
Solved my problem! I didn't put GLUT_DEPTH in my glut window!