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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T00:26:39+00:00 2026-05-31T00:26:39+00:00

im trying to do a little 3d scene with openGL and include a bit

  • 0

im trying to do a little 3d scene with openGL and include a bit of lighting, im fine with my scene (although it isnt anything special) and im trying to add some lighting to give it some effect. however I can add material to my podium (which isnt textured) and that gives me light and anything that IS textured does not apply any material to it so it defies the point of having lights. Heres some of the code.

// Setup GL_LIGHT0
glLightfv(GL_LIGHT0, GL_AMBIENT, lightAmbient);     // Setup ambient light
glLightfv(GL_LIGHT0, GL_DIFFUSE, lightDiffuse);     // Setup diffuse light
glLightfv(GL_LIGHT0, GL_SPECULAR, lightSpecular);   // Setup specular light

glLightf(GL_LIGHT0, GL_CONSTANT_ATTENUATION, ca);
glLightf(GL_LIGHT0, GL_LINEAR_ATTENUATION, la);
glLightf(GL_LIGHT0, GL_QUADRATIC_ATTENUATION, qa);

glLightf(GL_LIGHT0, GL_SPOT_CUTOFF, 180.0f);
glLightf(GL_LIGHT0, GL_SPOT_EXPONENT, 0.0);

// Setup GL_LIGHT1
glLightfv(GL_LIGHT1, GL_AMBIENT, lightAmbient);     // Setup ambient light
glLightfv(GL_LIGHT1, GL_DIFFUSE, lightDiffuse);     // Setup diffuse light
glLightfv(GL_LIGHT1, GL_SPECULAR, lightSpecular);   // Setup specular light

glLightf(GL_LIGHT1, GL_CONSTANT_ATTENUATION, ca);
glLightf(GL_LIGHT1, GL_LINEAR_ATTENUATION, la);
glLightf(GL_LIGHT1, GL_QUADRATIC_ATTENUATION, qa);

glLightf(GL_LIGHT1, GL_SPOT_CUTOFF, 180.0f);
glLightf(GL_LIGHT1, GL_SPOT_EXPONENT, 0.0);
// Setup GL_LIGHT2
glLightfv(GL_LIGHT2, GL_AMBIENT, lightAmbient);     // Setup ambient light
glLightfv(GL_LIGHT2, GL_DIFFUSE, lightDiffuse);     // Setup diffuse light
glLightfv(GL_LIGHT2, GL_SPECULAR, lightSpecular);   // Setup specular light

glLightf(GL_LIGHT2, GL_CONSTANT_ATTENUATION, ca);
glLightf(GL_LIGHT2, GL_LINEAR_ATTENUATION, la);
glLightf(GL_LIGHT2, GL_QUADRATIC_ATTENUATION, qa);

glLightf(GL_LIGHT2, GL_SPOT_CUTOFF, 180.0f);
glLightf(GL_LIGHT2, GL_SPOT_EXPONENT, 0.0);
// Setup GL_LIGHT3
glLightfv(GL_LIGHT3, GL_AMBIENT, lightAmbient);     // Setup ambient light
glLightfv(GL_LIGHT3, GL_DIFFUSE, lightDiffuse);     // Setup diffuse light
glLightfv(GL_LIGHT3, GL_SPECULAR, lightSpecular);   // Setup specular light

glLightf(GL_LIGHT3, GL_CONSTANT_ATTENUATION, ca);
glLightf(GL_LIGHT3, GL_LINEAR_ATTENUATION, la);
glLightf(GL_LIGHT3, GL_QUADRATIC_ATTENUATION, qa);

glLightf(GL_LIGHT3, GL_SPOT_CUTOFF, 180.0f);
glLightf(GL_LIGHT3, GL_SPOT_EXPONENT, 0.0);

// OpenGL provides a global ambient light component - we don't want this so set to zero
GLfloat global_ambient[] = { 0.0f, 0.0f, 0.0f, 1.0f };
glLightModelfv(GL_LIGHT_MODEL_AMBIENT, global_ambient);

And to render my room + 3d object.

glEnable(GL_LIGHTING);
    glEnable(GL_LIGHT0);
    glEnable(GL_LIGHT1);
    glEnable(GL_LIGHT2);
    glEnable(GL_LIGHT3);

    // Define position and direction
    // NOTE: Placing these commands AFTER the above viewing (camera) transformations means the light position and direction appear to have a set point / direction in the 3D environment.  If these commands are placed BEFORE the above viewing transformations, then the light appears to move with the camera (as if it is attached to the camera!)
    glLightfv(GL_LIGHT0, GL_SPOT_DIRECTION, lightDirection);
    glLightfv(GL_LIGHT0, GL_POSITION, lightPosition);

    glLightfv(GL_LIGHT1, GL_SPOT_DIRECTION, lightDirection1);
    glLightfv(GL_LIGHT1, GL_POSITION, lightPosition1);

    glLightfv(GL_LIGHT2, GL_SPOT_DIRECTION, lightDirection2);
    glLightfv(GL_LIGHT2, GL_POSITION, lightPosition2);

    glLightfv(GL_LIGHT3, GL_SPOT_DIRECTION, lightDirection3);
    glLightfv(GL_LIGHT3, GL_POSITION, lightPosition3);


    // setup materials for objects to draw
    glMaterialfv(GL_FRONT, GL_AMBIENT, ambientMaterial);
    glMaterialfv(GL_FRONT, GL_DIFFUSE, diffuseMaterial);
    glMaterialfv(GL_FRONT, GL_SPECULAR, specularMaterial);


    // 2. Draw scene
    glPushMatrix();
        drawRoom();
        glTranslatef(0.0,-0.75,0.0);
        glRotatef(90.0, 1.0,0.0, 0.0);
        glRotatef(-spin, 0.0,0.0, 1.0);
        glColor3f(1.0, 1.0, 1.0);
        drawPodium();
    glPopMatrix();

    // Save transformations prior to rendering scene
    glPushMatrix();

        glColor3f(0.0, 0.0, 1.0);   

        // Setup texture state
        glEnable(GL_TEXTURE_2D);
        glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);

        glRotatef(spin, 0.0,1.0, 0.0);
        // Render model

        glMaterialfv(GL_FRONT, GL_DIFFUSE, diffuseMaterial2);

        glTranslatef(0.0,0.8,0.0);
        glRotatef(1.0,1.0,0.0,0.0);
        myModel->renderTexturedModel();

        // Reset texture state
        glDisable(GL_TEXTURE_2D);

    // restore transformations after rendering scene
    glPopMatrix();

And the current outcome with my 4 lights, in a square shape above the helicopter all looking down towards 0.0 is:

My scene

If you can make out the white dotted lines they are the direction the lights are looking. the surface of the podium is lit and the sides of the podium are lit as it spins. However the rest of the room and helicopter does not respond to light and act like lighting isnt even enabled hence why i think its because everything except the podium is textured.

  • 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-31T00:26:40+00:00Added an answer on May 31, 2026 at 12:26 am

    You need to setup glTexEnv to specify how lighting should work for the textured objects

    See:

    21.030 Why doesn’t lighting work when I turn on texture mapping?
    http://www.opengl.org/resources/faq/technical/texture.htm

    Or to address your problem more directly, the line

    glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
    

    is what causes the behaviour. As the faq explains, when you specify GL_REPLACE, you replace the primitive lighting colour with the texture colour, which overwrites any lighting calculations. You can remove this line completely as GL_MODULATE is the default behaviour.

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

Sidebar

Related Questions

After trying my hand at Perl and a little bit of C, I am
I'm trying to enter a little bit of HTML into an ASP.NET Dynamic Data
iam trying to setup an little search-engine for my website. I want to add
I'm trying to make a little scene for viewing 3D models. I modified the
I'm trying a little concept test to change one of the features of the
I am trying out a little reflection and have a question on how the
I'm going a little nuts trying to understand the doc on impersonation and delegation
I'm going a little nuts trying to figure out how to use template inheritance
I'm trying to write a quick little java application to read the contents of
I'm trying to develop a little C# application (with MS Visual Express and SQL

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.