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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:31:00+00:00 2026-06-16T00:31:00+00:00

I have a model that needs to be under a spotlight/directional light, Meaning, I

  • 0

I have a model that needs to be under a spotlight/directional light,

Meaning, I need to switch between the modes (Spotlight and directional).

Here is the code with some explanation:

I can rotate the model / light source with mouse movements so I am using

glRotate and glTranslate for that.

Once the user pressed the ‘L’ key I’m supposed to switch between the modes.

here is the code for the lightning:

void LightBall::projectLight(void)
{
if(LIGHT == _lightMode){
    printf("Entering LIGHT mode\n"); <--- Supposed to be a directional light
    glDisable(GL_LIGHT1);
    glEnable(GL_LIGHT0);
    glLightfv(GL_LIGHT0, GL_POSITION, _light_position);
}

if(SPOT_LIGHT == _lightMode){
    printf("Entering SPOTLIGHT mode\n"); <--- Supposed to be a spotlight
    glDisable(GL_LIGHT0);
    glEnable(GL_LIGHT1);
    glLightfv(GL_LIGHT1, GL_POSITION, _light_position);
    glLightf(GL_LIGHT1, GL_SPOT_CUTOFF, 10.0);
    glLightf(GL_LIGHT1, GL_SPOT_EXPONENT, 2.0);
    glLightfv(GL_LIGHT1,GL_SPOT_DIRECTION,_spotlight_position);
}
}

The problem is I always get the same light mode when switching between them,

Which is the following:

directional

And another example after switching between 2 light modes and still getting same light

source with light source rotation (the small ball):

rotation

How can I get the wanted result?

Here are the LIGHT0 & LIGHT1 definitions:

    GLfloat light_ambient[] = { 1.0, 0.0, 0.0, 1.0 };
GLfloat light_diffuse[] = { 1.0, 0.0, 0.0, 1.0 };
GLfloat light_specular[] = { 1.0, 1.0, 1.0, 1.0 };
_light_position[0] =  0.0;
_light_position[1] = 1.0;
_light_position[2] = 0.0;
_light_position[3] = 0.0;

_spotlight_position[0] = 0.0;
_spotlight_position[1] = -1.0;
_spotlight_position[2] = 0.0;

glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);
glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular);

glLightfv(GL_LIGHT1, GL_AMBIENT, light_ambient);
glLightfv(GL_LIGHT1, GL_DIFFUSE, light_diffuse);
glLightfv(GL_LIGHT1, GL_SPECULAR, light_specular);

Thanks!

  • 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-06-16T00:31:01+00:00Added an answer on June 16, 2026 at 12:31 am

    Whether a GL light is a directional light or a spotlight depends on the w (4th) component of its position. If the coordinate is 0, it’s directional. If nonzero (usually 1), it’s a spotlight. You’ll have to modify _lightPosition accordingly before calling glLightfv(..., GL_POSITION, ...).

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

Sidebar

Related Questions

I have the following data model: I am writing a WCF service that needs
I have a namespaced model quiz under Student, and I need to access a
I need to model routes that act a little strange to me. Here is
I have a JInternalFrame window that needs to popup a modal dialog box when
I have several models that need to call a method that takes a particular
i have a enum like that : public enum Mode { [*I need a
I have a model that looks like this: Performance - Location - Event -
I have a model Articles that has_many Assets which is a polymorphic model that
I have a model that contains an Address property and Latitude / Longitude properties.
I have a model that requires quite a few BooleanFields, they could be considered

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.