lighting the inside of a cube

Im trying to make a lit room.
The camera is inside ans there should be coming a light from the ceiling.

im doing the following:

enable lighting
enable light0
position the light
set diffuse light to 1, 1, 1
set light model to local point light
draw the cube with normals pointing to the inside and draw the verteces clockwise so that the front faces will be inside

Ok, the cube is lit from the inside now, but the onlything i see is a white screen now, all 6 polygons have the same color!
I want the floor to look darker than the ceiling, becuz the light comes from the ceiling.

im very sure the light position is correct…

i hope you can help me

(btw with a sphere this works fine!)

thx

-xill

Did you enable color under lighting?

glEnable(GL_COLOR_MATERIAL);// Without everything will be white.

Originally posted by xillie:
[b]Im trying to make a lit room.
The camera is inside ans there should be coming a light from the ceiling.

im doing the following:

enable lighting
enable light0
position the light
set diffuse light to 1, 1, 1
set light model to local point light
draw the cube with normals pointing to the inside and draw the verteces clockwise so that the front faces will be inside

Ok, the cube is lit from the inside now, but the onlything i see is a white screen now, all 6 polygons have the same color!
I want the floor to look darker than the ceiling, becuz the light comes from the ceiling.

im very sure the light position is correct…

i hope you can help me

(btw with a sphere this works fine!)

thx

-xill [/b]

yes i did, but i dont think it has anything to do with it…

what i want is see a nice circle of light on teh ceiling which grows darker… :stuck_out_tongue:

i can find no tuts on that

For your ceiling you could make a sphere your light source by using the material option of GL_EMISSION.
As for the other lighting issue’s, there is a trick to doing what you ask. Opengl lights everything the same even if the light is block by another object. You have to create you own shadows using the stencil buffer. go to nehe.gamedev.net and look at the shadow tutor.

Originally posted by xill:
[b]yes i did, but i dont think it has anything to do with it…

what i want is see a nice circle of light on teh ceiling which grows darker… :stuck_out_tongue:

i can find no tuts on that[/b]

there are no objects in the way )
all i want is that the further a pixel is the darker it is, you can see that nicely in a sphere but i cant do it on a cube, even if i devide it into 6*16 polygons theyre all lit the same :stuck_out_tongue:

sounds like you need to set up attenuation, look up
GL_QUADRATIC_ATTENUATION
GL_LINEAR_ATTENUATION
GL_CONSTANT_ATTENUATION

set those up with glLightf and you should be in luck, just make sure your polygons are sufficiently tessalated

Even with attenuation set correctly you probably won’t get the effect you’re looking for. OpenGL only calculates lighting at each vertex and then interpolates per pixel. With a cube, any higlights that don’t fall on a vertex will be lost since OpenGL only samples at vertices. To solve this, tesselate the cube into more triangles or use a different lighting technique, e.g. lightmaps or per pixel lighting. Check out pifall #2 here . Lightmapping is explained in the FAQ.

Its not per pixel lighting that i want, all i ask is that each vertex is calculated…
but now, the color from one vertex of the floor is not the same as the same point of the wall… :stuck_out_tongue: all pixels in the polygons are the same color, and i DID enable GL_POLYGON_SMOOTH

maybe someone wants to look at my code??

Hi, maybe I can help.

  1. Make sure your walls are sufficiently tesselated.
  2. The walls are flat, so just specify surface normals.
  3. Make sure your normals point the right way!
  4. Enable smooth shading.
  5. Set the ambient, diffuse, and specular components of your light source.
  6. Set up color materials for your walls.
  7. Set the specular reflectance component.
  8. Specify a decent shininess for your material.
  9. If your walls are textured, specular highlighting wont work, you have use the GL_EXT_separate_specular_color extension, or use a two pass technique.
  10. If you are using a pointlight, make sure you set the cutoff to 180.0f.
  11. Make sure your normals point the right way!
  12. Remember to update the lights position each frame.
  13. Ask if you have more questions!

Old GLman

[This message has been edited by Old GLman (edited 05-01-2002).]

Originally posted by xillie: Ok, the cube is lit from the inside now, but the onlything i see is a white screen now, all 6 polygons have the same color!
I want the floor to look darker than the ceiling, becuz the light comes from the ceiling.

Remember to make your normals unit length (i.e. Normalised). Otherwise your light might be oversaturated. Or your light might be too bright for your scene. Try cutting your light intensity and see if it makes a difference.

Also, though unlikely, check if you had entered any state that treats lighting differently, like texture mapping.

[This message has been edited by Furrage (edited 05-02-2002).]

i know now, i was wrong on the vertex normals! i thought all vertices of the quad had the same normals so i used the same normals for each of them, but i have to calculate the normals out of 3 other normals :stuck_out_tongue:

thx you guys!