Problem with OpenGL lighting when turning the camera

I draw buildings in my game world, I shade them with the following code:

GLfloat light_ambient[] = {0.0f, 0.0f, 0.0f, 1.0f};
GLfloat light_position[] = {135.66f, 129.83f, 4.7f, 1.0f};

glShadeModel(GL_SMOOTH);

glEnable(GL_LIGHT0);
glEnable(GL_COLOR_MATERIAL);

glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);
glLightfv(GL_LIGHT0, GL_POSITION, light_position);

glColorMaterial(GL_FRONT, GL_AMBIENT);

It works well.

But when I start flying in the world, the lighting reacts to it, as if the world was an object that rotates. Therefore, when you change the angle of the camera, the lights change.

How to return this rotation? so the lighting will think that I don’t really rotate the world, and then I could make my buildings a static shade that would change depending on where the sun is in the sky.

Edit: here is the rendering code:

int DrawGLScene()
{

    // stuff

    glLoadIdentity();

    glRotatef(XROT, 1.0f, 0.0f, 0.0f);
    glRotatef(YROT, 0.0f, 1.0f, 0.0f);
    glRotatef(ZROT, 0.0f, 0.0f, 1.0f);

    glTranslatef(-XPOS, -YPOS, -ZPOS);

    // draw world
}
+3
source share
2 answers

, - , OpenGL Lights World Coordinates, . , , , , , .

, .

+1

Source: https://habr.com/ru/post/1725896/


All Articles