PDA

View Full Version : Opengl - Jumpy lighting



shawn619
03-21-2012, 06:52 AM
My one light seems to 'jump' and not flow smoothly across my floor tile texture.

It's much better explained in this short youtube video youtube link (http://www.youtube.com/watch?v=xlEw9cFsiio&context=C43aa93dADvjVQa1PpcFM3 qJwNPyPjDPNMhrHbNzlXxoi40j_--uc=)
Note that my light is not going somewhere and coming back; it is always located half way between the camera and the cube.

This is my function for drawing the floor tiles:


void drawFloor(){

float size = 20.0;
float startX = -60.0f;
float startZ = 60.0f;

glDisable(GL_COLOR_MATERIAL);

glPushMatrix();

glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, _textureId);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
//glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);

for(int x = 0;x < 6; x++){
for(int z = 0;z < 6; z++){

glBegin(GL_QUADS);

glNormal3f(0.0f, 1.0f, 0.0f);
glTexCoord2f(0.0f, 0.0f);
glVertex3f(startX + size*x, 0.0f, startZ + -size*z);//bottom-left
glTexCoord2f(1.0f, 0.0f);
glVertex3f(startX + size + size*x, 0.0f, startZ + -size*z);//bottom-right
glTexCoord2f(1.0f, 1.0f);
glVertex3f(startX + size + size*x, 0.0f, startZ + -size + -size*z);//top-right
glTexCoord2f(0.0f, 1.0f);
glVertex3f(startX + size*x, 0.0f, startZ + -size + -size*z);//top-left

glEnd();
}
}

glDisable(GL_TEXTURE_2D);

glPopMatrix();

glEnable(GL_COLOR_MATERIAL);

}


Question: How can i make my light not jump and light the tiles smoothly?

tanzanite
03-21-2012, 07:50 AM
It's much better explained in this short youtube video youtube (http://www.youtube.com/watch?v=VSrAJsWvEIc&amp;feature=player_detailpage)

O_o. I do not think it links to what you wanted it to.

shawn619
03-21-2012, 08:34 AM
Fixed*

Thanks for catching that, i was very tired when i posted this

shawn619
03-21-2012, 11:21 PM
Bump

BionicBytes
03-22-2012, 10:09 AM
and where's the code which handles the lighting? Can't fix lighting with seeing lighting code you know ;-)

tanzanite
03-22-2012, 04:06 PM
Random guess: you use per vertex lighting (http://en.wikipedia.org/wiki/Gouraud_shading) and your polygons are just too big for that.

V-man
03-22-2012, 11:30 PM
So use shaders to do PPL = per pixel lighting

shawn619
03-23-2012, 03:35 AM
Ah yes, im going to that now, thanks everyone!

@V-man, nice to see a Canadian opengl programmer =)