Jump to content
  • Advertisement
Sign in to follow this  

Spotlight doesn't light up my scene

This topic is 2608 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

Hello everyone!

I'm having some trouble with getting a spotlight to correctly light up my scene.

The center of my scene is at 0, 0, 0.

I translate and rotate my scene so that it seems like a player has moved,
I then reposition the light at 0, 0, 0 and draw the world around 0, 0, 0 as center point.

I am not seeing my spotlight however... Who knows what might be wrong?
// INIT:

glShadeModel(GL_SMOOTH); // Enable smooth shading
qglClearColor(Qt::black); // Set the clear color to a black background
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // Really nice perspective calculations

// Set up lighting
GLfloat fv[] = {1.0f, 1.0f, 1.0f, 1.0f};

// Spot in center of room shining down
GLfloat ambient = {0.5f, 0.2f, 0.2f, 1.0f};
glLightfv(GL_LIGHT1, GL_AMBIENT, ambient);
GLfloat diffuse = {0.5f, 0.2f, 0.2f, 1.0f};
glLightfv(GL_LIGHT1, GL_DIFFUSE, diffuse);
GLfloat specular = {0.5f, 0.2f, 0.2f, 1.0f};
glLightfv(GL_LIGHT1, GL_SPECULAR, specular);
glLightf(GL_LIGHT1, GL_SPOT_CUTOFF, 90.0f);
GLfloat direction = {0.0f, 0.0f, -1.0f};
glLightfv(GL_LIGHT1, GL_SPOT_DIRECTION, direction);

// Set up textures

// Set up blending
glBlendFunc(GL_SRC_ALPHA, GL_ONE);

// Set up depth testing


// Prevent divide by zero (in the gluPerspective call)
if (height == 0)
height = 1;

glViewport(0, 0, width, height); // Reset current viewport

glMatrixMode(GL_PROJECTION); // Select projection matrix
glLoadIdentity(); // Reset projection matrix

gluPerspective(45.0f, static_cast<GLfloat>(width)/height, 0.1f, 100.0f); // Calculate aspect ratio

glMatrixMode(GL_MODELVIEW); // Select modelview matrix
glLoadIdentity(); // Reset modelview matrix


glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear screen and depth buffer

glMatrixMode(GL_MODELVIEW); // Select modelview matrix
glLoadIdentity(); // Reset modelview matrix

// Move scene to make it seem like player moves around
glRotatef(lookupdown, 1.0f, 0.0f, 0.0f);
glRotatef(sceneroty, 0.0f, 1.0f, 0.0f); // Rotate to direction player is watching
glTranslatef(xtrans, ytrans, ztrans); // Translate scene based on player position

// The center of the world is at (0.0f, 0.0f, 0.0f)

// Reset light position
GLfloat fv[] = {0.0f, 0.0f, 0.0f, 1.0f};
glLightfv(GL_LIGHT1, GL_POSITION, fv);

// Draw the world
for (int i = 0; i < displayLists.size(); ++i) {
glCallList(displayLists.at(i)); }

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!