Link to home
Start Free TrialLog in
Avatar of srihari1986
srihari1986

asked on

AMBIENT AND SPOT LIGHT IN OPENGL

Hi,

Actually i have done a program will have a a room(Where all the walls are a 10 X 10 grid).And actually implemented a ambient light.but when i runt the program i can see that only the 1 wall changes color.

And anybody tell me how should i use spot light and what are the steps i need to use.And how to bring shining to  the surface.

Regards
Hari
Avatar of _corey_
_corey_

Are the walls textured at all?  Also, did you set the material values (ambient/diffuse/etc) for those objects?

corey
Avatar of srihari1986

ASKER

Yes my walls are textured.What are the values we need to set for ambient and spot light.Below is the code o have done for the ambient light.The ambient light actually works only on the wall that has no texture.


// method to setup the lighting
   void set_light ( void)
   {


        // controlling the ambient light
        GLfloat ambientVal;
        if(!nightMode)
              ambientVal = 2.0;
        else
                ambientVal = 0.2;

        GLfloat lmodel_ambient[] = {ambientVal,ambientVal,ambientVal, 1.0 };
        glClearColor(0.0,0.0,0.0,1.0);
        glShadeModel(GL_SMOOTH);

      // enable ambient light
        glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient);

            glLightModeli ( GL_LIGHT_MODEL_LOCAL_VIEWER, GL_TRUE );
      glLightModeli ( GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE );

       // enable all the lighting
        glEnable ( GL_LIGHTING ); // ambient
        glEnable (GL_DEPTH_TEST);
        glEnable(GL_COLOR_MATERIAL); // to enable proper transparency and color after the lighting
   }

Regards
Hari
I'd recommend keeping a browser window open to:
http://rush3d.com/reference/opengl-redbook-1.1/
Whenever you're doing OpenGL programming.  The chapter on lighting (#6) is probably going to be most helpful to you.  Can you post a bit more code, specifically, your draw function?
I've been away with work, I'll try to answer your question soon.

corey
ASKER CERTIFIED SOLUTION
Avatar of _corey_
_corey_

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial