lighting makes scene black n white

Started by
10 comments, last by themule 20 years, 11 months ago
i make a green grid, and a purple nurbs surface, but when i introduce light (diffuse light), i can see the lighting effect but the whole scene turns black n white and shades of gray.... can''t figure out how. before drawing my grid and surface i am choosing the color explicitly and yet... could anyone point out where am i going wrong? thanks a bunch.
Advertisement
You might want to check your normals - it also screws up sphere mapping btw - learn''t that the hard way
could u be more specific? i didn''t get wht the normals have to do with the colors disappearing.. and moreso.. wht should i do with the normals anyways?
please help, i have no clue abt how the normals intervene with this matter.

thanks again.
When you enable lighting in opengl, it ignores the colors you set with glColor. glEnable(GL_COLOR_MATERIAL) should do it


// Website // Google // GameDev // NeHe // MSDN // OpenGL Extensions //
~neoztar "Any lock can be picked with a big enough hammer"my website | opengl extensions | try here firstguru of the week | msdn library | c++ faq lite
Or you can play with material colorings:

glMaterialXX() for each of:
GL_AMBIENT
GL_DIFFUSE
GL_SPECULAR
GL_EMISSION
GL_SHININESS

For Example:
float rAmbient[4];
float rDiffuse[4];
float rSpecular[4];
float rEmissive[4];
float rShininess;

// Set your values for the above.

glMaterialfv(GL_FRONT, GL_AMBIENT, rAmbient);
glMaterialfv(GL_FRONT, GL_DIFFUSE, rDiffuse);
glMaterialfv(GL_FRONT, GL_SPECULAR, rSpecular);
glMaterialfv(GL_FRONT, GL_EMISSION, rEmissive);
glMaterialf (GL_FRONT, GL_SHININESS, rShininess);

This will probably take a bit more reading and experimenting, but you can make some pretty neat looking stuff with it.

- sighuh?
- sighuh?
To use glColor with OpenGL lighting you have to glEnable(GL_COLOR_MATERIAL);

Hope this helps...
Do as RedDragon said...but don''t forget about the normals...

Why it is important to lighting? It is used by lighting to calculate it''s reflecction, shininess, etc... It should be pointing out from your polygon face. For example, in a ccube the normals should be pointing out from each of the cube''s face.

For more complex models you should consider doing vertex normals, it will look more smooth...but it''s another story...
"Steel and Fire,Spreading the Holy Word,Dirty Liars,The truth has never been told" - Primal Fear
About normals: they mathematically determine which way the light reflects off a model. You will have to do run time generated normals - basically cross the two vectors that make up the triangle and apply that normal to each vertex - you can use GL_NORMALIZE to make them unit vectors. If you want to smothe out your nurb surface you are going to have to run a smothing algorithm. Basically for each vertex, you average the normals for each triangle that the vertex belongs to; hopes this makes sence

On a side note; normals are also important for sphere mapping - if you dont include vertex normals you wont get the desired effect.
ok thanks everyone, the colors came by enabling GL_COLOR_MATERIAL
ya i think my normals are ok. and abt the few things related to glMaterial that redragon has suggested to experiment with and read about, i have been trying to figure them out myself, but msdn doesn''t seem to help much, i don''t know y these msdn ppl have made msdn so counter intuitive... it just fails to tell in a straightforward manner what a particular function or capability is supposed to do and what is it used for. The Java API documentation is soooo much better than msdn.
now i am looking for some other resources to read up on my opengl queries, i am hoping to find something on the net, as i dont even have the red or blue book of opengl, can''t afford to buy any and the only copy in my library is issued for a good long time by some faculty
all the opengl that i know is from tutorials/articles etc from the net.

anyways, thanks everyone.
Look for the red and blue book on the net. Search in google. Eventually you'll find them!!! Download and ... psss...don't tell anyone

[edited by - brucesinner on April 30, 2003 11:42:00 AM]
"Steel and Fire,Spreading the Holy Word,Dirty Liars,The truth has never been told" - Primal Fear

This topic is closed to new replies.

Advertisement