Jump to content
  • Advertisement
Sign in to follow this  
Shawn619

OpenGL Opengl - Lighting problem

This topic is 2456 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

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)

Share this post


Link to post
Share on other sites
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!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!