Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 503445
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T06:23:41+00:00 2026-05-13T06:23:41+00:00

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

  • 0

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 nicely.

But when i start flying in the world, the lighting reacts to that as if the world was an object that is being rotated. So the lights changes when my camera angle changes.

How do i revert that rotation? so the lighting would think that i am not actually rotating the world, and then i could make my buildings have static shading which would change depending on where the sun is on 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
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T06:23:42+00:00Added an answer on May 13, 2026 at 6:23 am

    http://www.opengl.org/resources/faq/technical/lights.htm

    See #18.050

    In short, you need to make sure you’re defining your light position in the right reference frame and applying the appropriate transforms each frame to keep it where you want it.

    Edit:

    With the removal of the fixed function pipeline in OpenGL 3.1 the code and answer here are deprecated. The correct answer now is to pass your light position(s) into your vertex/fragment shaders and perform your shading using that position in world space. This calculation varies based on the type of lighting you’re doing (PBR, phong, deferred etc).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got an update function in my game that contains the following code: void
I draw the ellipse with the code as shown below. How can I make
I draw picture in canvas in place where I click. This is code: public
What is the best way to separate rendering code from the actually game engine/logic
I have vector data for buildings on my map and want them to appear
I'm building a simple sliding blocks game. I use the repaint() method to draw
//Draw Icon for (var i = 0; i < diagram.Children.length; i++) { if (diagram.Children[i].Icon
I draw a line in a zedgraph pane, but sometimes it will be like
I draw my background every frames : void Window::paintGL() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity();
To draw a circle on map I have a center GLatLng (A) and a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.