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

  • Home
  • SEARCH
  • 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 9128445
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T07:30:55+00:00 2026-06-17T07:30:55+00:00

I have created a room, actually rectangular with two windows and one door. I

  • 0

I have created a room, actually rectangular with two windows and one door. I have been trying to light the matarials with their material properties. I have used the below code but it does not work; why?

NOTE: light is in the room, as expected

in myinit ()

    glEnable(GL_DEPTH_TEST);
    glEnable(GL_COLOR_MATERIAL);
    glEnable(GL_LIGHTING);


    glLightfv(GL_LIGHT1, GL_AMBIENT, light[0]);  
    glLightfv(GL_LIGHT1, GL_DIFFUSE, light[1]);  
    glLightfv(GL_LIGHT1, GL_SPECULAR,light[2]);
    glLightfv(GL_LIGHT1, GL_POSITION,light[3]);  // position of the light
    glEnable(GL_LIGHT1);                     

in draw room ()

   glMaterialfv ( GL_FRONT, GL_AMBIENT ,material[0] ) ;
   glMaterialfv ( GL_FRONT, GL_DIFFUSE ,material[1] ) ;
   glMaterialfv ( GL_FRONT, GL_SPECULAR ,material[2] ) ; 
   glBegin (GL_TRIANGLES); 
            glColor3f ( /*...*/ )             
            // ...
   glEnd ( ) ;

in main ()

   glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);  
  • 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-17T07:30:57+00:00Added an answer on June 17, 2026 at 7:30 am

    Have you enabled the lighting itself? Enabling just a light isn’t enough, you should enable the whole light system as well (it’s off by default)

    It should happen in the initialization function:

    glEnable(GL_LIGHTING);
    

    Also, don’t forget:

    glEnable(GL_COLOR_MATERIAL);
    

    If you want material colors. (You have it now, but it’s another little flag that can cause problems)

    Another vital element one must understand in order to understand how lighting works in GL is normals. For every vertex you have in your geometry, you must also tell OpenGL which way it’s facing, so that it can calculate its direction relative to the light position, in order to determine how bright it should be. This looks like a decent introduction to the concept in OpenGL.

    When I first started with OpenGL, I thought that these normals would be computed automatically from the given triangles. I was wrong. OpenGL doesn’t automatically compute the normals of a model, even though, in theory, it could (albeit with blocky results – maybe smooth with more advanced techniques).

    And another recommendation – it would be a good idea to avoid using fixed pipeline functionality such as glBegin(...) ... glEnd() blocks (also known as immediate mode). It’s outdated and slow. Check out this great tutorial series for a good introduction to modern techniques also used in modern games.

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

Sidebar

Related Questions

i have created two classes Standard and Family which extend abstract class Room ,
I have created an EDMX in visual studio 2010 SP1. It has been built
I have created two imageViews promatically as shown below: public void createImageViews(Integer count){ ImageView[]
I have created block with function getRooms(). This function make joinLeft query for two
I have created a Hostel class and a Room class, the Hostel class contains
I have two 3rd party libraries. One just has a build for armv6 and
I have a program that I am trying to write that one row of
I have created new room for group chat by using this- XMPPRoomCoreDataStorage *rosterstorage =
I'm trying to simulate a working product and have created a PHP array of
I have been trying to get more in to TDD. Currently keeping it simple

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.