PDA

View Full Version : GL_LIGHTING



Myrmidon
12-25-2009, 06:35 AM
I have a small problem when I set a light to act as a sun in my scene of objects.
I've put the light at some coordinates but when I rotate the scene (including the light) even a bit, the following thing happens:

http://img194.imageshack.us/gal.php?g=beforexf.jpg

Do you have any idea why this is happening ?

In initOpenGl I set the light
{

glEnable(GL_LIGHTING);
glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);
glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular);

}

and then in renderScene I have

{
// Some global trasformations (rotation,translation, etc).

glLightfv(GL_LIGHT0, GL_POSITION, light_position0);

// draw objects
}

The light parameters are basically the default ones :

GLfloat light_position0[] = { 15, 15, 0, 1.0 };

GLfloat light_ambient[] = { 0.0, 0.0, 0.0, 1.0 };
GLfloat light_diffuse[] = { 1.0, 1.0, 1.0, 1.0 };
GLfloat light_specular[] = { 1.0, 1.0, 1.0, 1.0 };

Dark Photon
12-25-2009, 09:51 AM
I have a small problem when I set a light to act as a sun in my scene of objects. ... The light parameters are basically the default ones :

GLfloat light_position0[] = { 15, 15, 0, 1.0 };
This is not a sun. The sun is a directional light source. Directional light sources have position.w = 0.0, not 1.0, and position.xyz is essentially a direction vector. position.w = 1.0 indicates a positional light source.


GLfloat light_ambient[] = { 0.0, 0.0, 0.0, 1.0 };
GLfloat light_diffuse[] = { 1.0, 1.0, 1.0, 1.0 };
GLfloat light_specular[] = { 1.0, 1.0, 1.0, 1.0 };
I would set specular to all 0.0s until you figure out what's going on with your lighting. Get diffuse working correctly first. I'd also set ambient to 0.5s and diffuse to 0.5s, so that you get some ambient illumination even when there's no diffuse given sun angle.

And of course your lighting is also going to depend on material propoperties you've specified, color material, texture mode, etc. You might disable your texturing until you get the lighting nailed down.

remdul
12-26-2009, 06:20 AM
Do you call glNormal when drawing the ground?

Myrmidon
12-26-2009, 09:01 AM
I draw the ground ( and all objects in my scene) in this way:


void drawGrass()
{
glPushMatrix();

//if (wireframe!=1) glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D,groundTexture[0].texID);
glTranslatef(0,-0.5,0);
glScalef(7,0,12);


glRotatef(90,0,0,1);
glRotatef(90,0,1,0);
if(!ground) {
ground=glmReadOBJ("obj/tanc/ground.obj");
if(!ground) exit(0);
glmUnitize(ground);
glmFacetNormals(ground);
glmVertexNormals(ground,90.0);
}
glmDraw(ground,GLM_SMOOTH|GLM_TEXTURE);
glPopMatrix();
//glDisable(GL_TEXTURE_2D);

}

Optik
12-27-2009, 03:16 AM
try disabling the light source when you apply the global transform and re-enable it again after that.

Myrmidon
12-27-2009, 02:35 PM
I tried that but with no success.

The flickering is not because i rotate the scene. There are positions in which the scene is illuminated in a totally different way than the scene rotated with a minimal angle.

Dark Photon
12-27-2009, 06:58 PM
I tried that but with no success.

The flickering is not because i rotate the scene. There are positions in which the scene is illuminated in a totally different way than the scene rotated with a minimal angle.
Time to post a short GLUT test program. I suspect while you're cooking it, you'll figure out what you've done.