Opengl - Lighting problem

Started by
2 comments, last by Shawn619 12 years, 1 month ago
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

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);

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?
Advertisement
Because a default OpenGL state renderer computes a lighting per vertex (not per pixel). There are two solutions:
1: Make the floor more "high-poly".
2: Render with shaders (which computes lighting per pixel). (<< I recommend to use this).

Best wishes, FXACE.

Because a default OpenGL state renderer computes a lighting per vertex (not per pixel). There are two solutions:
1: Make the floor more "high-poly".
2: Render with shaders (which computes lighting per pixel). (<< I recommend to use this).

Best wishes, FXACE.


You can do per pixel lighting without shaders aswell, (google opengl dot3 lighting) which is useful for OpenGL ES 1.1 hardware (mainly older smartphones)
[size="1"]I don't suffer from insanity, I'm enjoying every minute of it.
The voices in my head may not be real, but they have some good ideas!
Thanks for the answers guys!

I knew it was something like that, but i just couldn't explain technically like you did.

I'm going to work with getting lighting-per-pixel shaders now, thanks!

This topic is closed to new replies.

Advertisement