PDA

View Full Version : lights and 3D



lara
11-08-2002, 09:58 AM
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

John Jenkins
11-08-2002, 10:16 AM
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).]

lara
11-08-2002, 10:19 AM
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...

John Jenkins
11-08-2002, 10:35 AM
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.

lara
11-08-2002, 06:51 PM
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).]

jono_123
11-08-2002, 10:16 PM
im quite sure that one call to glNormal will be enough for one wall just try it and see how it goes

Black Knight
11-09-2002, 03:42 AM
glEnable(GL_COLOR_MATERIAL);
did u use this??

nexusone
11-09-2002, 05:43 AM
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.8);
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).]

lara
11-09-2002, 11:57 AM
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);
glLoadIdentity ();
glFrustum (-1.0, 1.0, -1.0, 1.0, 1.5, 20.0);
glMatrixMode (GL_MODELVIEW);
glLoadIdentity();
}

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

saxman
11-09-2002, 12:57 PM
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.

bodros
11-09-2002, 01:07 PM
Didn't you need to define normal vecs for all vertices in shade model too?

I thought with shade model it would just pick out 1 of the normals of the vertices of the quad. If a normal is taken from a vertex that has no normal, no lighting?

11-11-2002, 07:11 AM
Hi,
If you still have problems with your code check out lesson 10 from NeHe's OpenGL tutorial: http://nehe.gamedev.net/tutorials/lesson.asp?l=10
You said you wanted to see a room - thus I'm assuming you want to look at walls, roof, etc. from the inside, not from the outside - this lesson does exactly that.

Martin


Originally posted by lara:
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);
glLoadIdentity ();
glFrustum (-1.0, 1.0, -1.0, 1.0, 1.5, 20.0);
glMatrixMode (GL_MODELVIEW);
glLoadIdentity();
}

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