• FEATURED

View more

View more

View more

### Image of the Day Submit

IOTD | Top Screenshots

### The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

# Opengl - Lighting problem

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

3 replies to this topic

### #1Shawn619  Members

Posted 22 March 2012 - 04:30 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

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++){
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?

### #2FXACE  Members

Posted 22 March 2012 - 08:18 AM

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.

### #3SimonForsman  Members

Posted 22 March 2012 - 09:25 AM

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

### #4Shawn619  Members

Posted 22 March 2012 - 10:17 AM