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 5973365
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T20:47:24+00:00 2026-05-22T20:47:24+00:00

I want to put a light in the scene that is fixed at a

  • 0

I want to put a light in the scene that is fixed at a certain spot. Here’s what the OpenGL site has to say about this:

How can I make my light stay fixed relative to my scene? How can I put a light in the corner and make it stay there while I change my view?

As your view changes, your ModelView matrix also changes. This means you’ll need to respecify the light position, usually at the start of every frame. A typical application will display a frame with the following pseudocode:

  • Set the view transform.
  • *Set the light position //glLightfv(GL_LIGHT_POSITION,…)*
  • Send down the scene or model geometry.
  • Swap buffers.

If your light source is part of a light fixture, you also may need to specify a modeling transform, so the light position is in the same location as the surrounding fixture geometry.

So I added this to the paintGL() function.

glMatrixMode(GL_MODELVIEW);
glPushMatrix();
gluLookAt(0.0, 5.0, 0.0,
    0.0, 0.0, 0.0,
    0.0, 1.0, 0.0);
GLfloat l0pos[] = {0.0, 0.0, 0.0, 1.0};
glLightfv(GL_LIGHT0, GL_POSITION, l0pos);
glPopMatrix();

It seems okay when I’m standing still, but when I move the camera’s eye position or the camera’s center position, the light flickers. What am I doing wrong?


Update2: I ended up using this code, but I’m still having issues. The light no longer moves, but its position isn’t accurate. The matrix on top of the stack is the matrix generated by a gluLookAt command that represents the camera position.

glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glTranslatef(xCoordinate, yCoordinate, zCoordinate);
GLfloat lpos[] = {0.0, 0.0, 0.0, w};
glLightfv(GL_LIGHT0, GL_POSITION, lpos);
glPopMatrix();
  • 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-22T20:47:25+00:00Added an answer on May 22, 2026 at 8:47 pm

    I’m not entirely sure if this is what is causing your symptoms, however:

    glMatrixMode(GL_MODELVIEW);
    glPushMatrix();
    gluLookAt(0.0, 5.0, 0.0,
        0.0, 0.0, 0.0,
        0.0, 1.0, 0.0);
    

    There are a few things you would want to look at here.

    First, according to the documentation online, gluLookAt multiplies the matrix at the top of the stack by a camera transformation matrix, rather than setting it (furthermore, glPushMatrix preserves the current matrix). For this reason, it’s a good idea to make sure the current matrix is the identity matrix before doing your camera transformation. A push/pop is generally enough but if you call gluLookAt after or “within” any other transformation, bad things can happen.

    Second, you’ll want to use your actual camera coordinates, so that GL can transform the light position properly. Otherwise the light won’t appear to move with the scene geometry. I’d suggest doing gluLookAt once, then transforming lights and drawing your geometry all in one go before popping the camera transformation matrix again. That way you can be certain that your lights and geometry stay together as expected.

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

Sidebar

Related Questions

I want to put an info light button in a section header - (CGFloat)tableView:(UITableView
My backend is PHP I have a service that I want to put out
I want to implement an ajax Client that does polling to the server. This
i want to put some description text in light grey in a text field.
I want put a button on android edittextpreference. I create a custom editextpreference: public
I've projected an Intranet Ajax application and I want put it in a full
hey, hi i want put limit on object creation means a class can have
I want to put two side by side on another (I have three )
I want to put some images in an area at the application start. As
I want to put the name of the loggedin user as the title of

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.