PDA

View Full Version : antoher boring question about lighting...



miko
07-29-2002, 08:30 AM
ok... i started with gl some time ago and now, i've got a crazy idea to put some lighting to my code.....

so i tried and it won't work! (what a surprise http://www.opengl.org/discussion_boards/ubb/wink.gif)... just everything seems to be black and white http://www.opengl.org/discussion_boards/ubb/frown.gif

i tried to set up ligting using this code (stolen from nehe)

GLfloat LightAmbient[]= { 0.5f, 0.5f, 0.5f, 0.1f };
GLfloat LightDiffuse[]= { 1.0f, 1.0f, 1.0f, 0.1f };
GLfloat LightPosition[]= { -10.0f, 0.0f, -3.0f, 1.0f };
GLfloat SceneAmbient[]= { 0.7f, 0.7f, 0.7f, 0.5f };

glLightfv(GL_LIGHT1, GL_AMBIENT, LightAmbient);
glLightfv(GL_LIGHT1, GL_DIFFUSE, LightDiffuse);
glLightfv(GL_LIGHT1, GL_POSITION, LightPosition);

glLightModelfv(GL_LIGHT_MODEL_AMBIENT, SceneAmbient);

glEnable(GL_LIGHTING);
glEnable(GL_LIGHT1);

what's wrong or what's missing?.... i'm sure normal vectors are good... i'm lost, i need your help...

Deiussum
07-29-2002, 08:51 AM
Have you set material properties? When using lighting, color is based on material properties rather than what you give to glColor. You can use glColorMaterial in order to make glColor change a particular material property, though.

pleopard
07-29-2002, 09:08 AM
Yup, u r missing some code ...




GLfloat mat_ambient[] = { 0.0, 0.0, 0.0, 1.0 };
GLfloat mat_diffuse[] = { 1.0, 1.0, 1.0, 1.0 };
GLfloat mat_specular[] = { 1.0, 1.0, 1.0, 1.0 };
GLfloat mat_shininess = 10.0f;

glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);
glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess);

miko
07-29-2002, 10:43 AM
tnx a lot, people.... now it's working well http://www.opengl.org/discussion_boards/ubb/cool.gif