1. ## lights and 3D

Hi,
This may seem pretty elementary...but here is my problem...
I have just a simple room with 3 walls + roof + floor.
Just so that i can see the walls , rather than a rectangle, i give each wall a different color. Now I need to add an ambient light...as soon as I add a light in there...everything becomes grey...and so i loose that 3d effect.
Can someone please tell me how could i add ambient light into the room, and still see those walls and roof etc.
THANKS

2. ## Re: lights and 3D

that is a common problem. You have to enable materials to tell opengl how the light reflects off of the object. also you have to declare normals on what you draw to once again tell opengl how light bounces off of your object. Same thing happened to me a couple of weeks ago.

[This message has been edited by John Jenkins (edited 11-08-2002).]

3. ## Re: lights and 3D

Well I guess then my next question is ,
have i to do that for each wall..
as i explained all my object is a bunch of rectangles basically.(which act as walls)
so do i have to set the light reflection for each of those walls..
i am kind of lost, in there.
Could you explain more...

4. ## Re: lights and 3D

If you have a vertex of a wall that faces left then your normal is glnormal -1,0,0
if it faces right then glnormal 1,0,0
if it faces straight ahead towards the -z then glnormal glnormal 0,0,-1
if it faces away glnormal 0,0,1
up .. 0,1,0
down.. 0,-1,0
you have to give a normal for every vertex.
enabling a material is just like enabling a light. you give it diffuse specular and ambient settings. also you tell it how shiny it is.

5. ## Re: lights and 3D

Hi,
Well I did set up the normals for the vertices..but surprisingly they did not help in the 3d efect. so i guessi am not doing it right.
Moreover after reading about the normals...how do you know whether it is left or right facing vertex..(or up or down one)

consider the following:
glVertex3f(-1,1,-1);
glVertex3f(1,1,-1);
glVertex3f(1,1,1);
glVertex3f(-1,1,1);

As these vertices together indicate a rectangle, need i set the normal for each vertex, or would simply one normal command do good.
Thanks

[This message has been edited by lara (edited 11-08-2002).]

6. ## Re: lights and 3D

im quite sure that one call to glNormal will be enough for one wall just try it and see how it goes

7. ## Re: lights and 3D

glEnable(GL_COLOR_MATERIAL);
did u use this??

8. ## Re: lights and 3D

How have you set up you view, ortho or perspective?

The perspective view will give you more of a 3D depth.

Also I don't see any changes to the material settings, this will also aid in making the scene look more 3D.

example settings:

glColorMaterial(GL_FRONT_AND_BACK, GL_EMISSION);
glColor4f(0.0, 0.0, 0.0, 1.0);
glColorMaterial(GL_FRONT_AND_BACK, GL_SPECULAR);
glColor4f(0.5, 0.5, 0.5, 1.0);
glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE);
glColor4f(0.8, 0.8, 0.8, 0.;
glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT);
glColor4f(0.75, 0.75, 0.75, 1.0);

Also post your view settings, I don't see you using glMatrixMode GL_PROJECTION for view or GL_MODELVIEW for objects.

Originally posted by lara:
here are the display and the init functions..that i am using....
even after enabling material light and another white light source..i can see the chang ein color of the walls as i enalbe the light sources..but i still do not get the depth effect that i should be getting when using normals...(also note i am using enable GL(NORMALIZE)...
so if someone can point out to me where I am doing something crazy, it would really help.
becasue as it is right now...everything is visible and fine..but it seems to be a 2D rather than in 3D

[This message has been edited by nexusone (edited 11-09-2002).]

9. ## Re: lights and 3D

Hi,
Here are the view settings.
I was using glFrustrum...and I think the problem is with the the way the light reflects..right now even after setting material color and all..from the front to the back the wall is one shade, thus i cannot see any depth in there. As far I know it has something to do the normals...
Strangely enought even for the ceiling , instead of making the normal (0,-1,0)..i have to make it (0,1,0)..becasue otherwsie the wall (celing) just disappers and becomes all black....

void reshape (int w, int h)
{
glViewport (0, 0, (GLsizei) w, (GLsizei) h);
glMatrixMode (GL_PROJECTION);
glFrustum (-1.0, 1.0, -1.0, 1.0, 1.5, 20.0);
glMatrixMode (GL_MODELVIEW);
}

I am wondering if someone can help me check those normals in the code...also should i change and use glPerspective?
lara

10. ## Re: lights and 3D

I'm not sure if this is the problem, but I've heard there's a difference between specifying normals for each vertex and for the entire polygon at once. If each vertex has it's own normal and smooth shading is enabled, the lighting will affect each vertex separately, and the color will be blended across the whole polygon. If there is only one normal per polygon, each polygon will appear flat and have the same color across its surface.

Page 1 of 2 12 Last

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•