Advertisement

openGL LIGHTING ???????????

Started by March 02, 2000 04:36 PM
3 comments, last by ECKILLER 24 years, 6 months ago
hi, Ok i am trying to add lighting to my application but when i did everything turned real dark. Obviously i''ve enabled lighting but no light is there I don''t see the problem in my code. Heres the fragments of code that relate to my problem: void Setup_Lighting(void) { // declare light position to the left and 3 units into the // screen GLfloat light_position[4] = { -7.0f, 0.0f, -3.0f, 0.0f}; // declare high intensity white light GLfloat white_light[4] = {1.0f, 1.0f, 1.0f, 1.0f}; // enable lighting glEnable(GL_LIGHTING); // enable color tracking glEnable(GL_COLOR_MATERIAL); // enable one light source-source zero glEnable(GL_LIGHT0); // enable the ability to modify diffuse material // with glColor() glColorMaterial(GL_FRONT, GL_DIFFUSE); glLightfv(GL_LIGHT0, GL_POSITION, light_position); glLightfv(GL_LIGHT0, GL_DIFFUSE, white_light); } Then in my render scene i call that function. Heres how i made the face of my prramid: void render(){ ... ... Setup_Lighting(); /* BEGIN DEFINING 3D COORDINATES OF PYRAMID **************************************************/ glBegin(GL_TRIANGLES); // draw face glColor3f(1.0f, 1.0f, 1.0f); glVertex3f( 0.0f*diff, 1.0f*diff, 0.0f*diff); glColor3f(0.0f, 0.0f, 0.0f); glVertex3f(-1.0f*diff,-1.0f*diff, 1.0f*diff); glColor3f(0.0f, 1.0f, 0.0f); glVertex3f( 1.0f*diff,-1.0f*diff, 1.0f*diff); ... ...} My pyramids all there but no light and i thought i set it to the brightest. Whats up?? ECKILLER
ECKILLER
first off, you are not specifying any normals for your vertices (unless i''m an idiot and i simply overlooked that part of the code). while that might not be the specific problem you''re having now, it will be a problem later on.
Advertisement
Ohh yeah, also to make sure that the object is at least getting drawn, you can use glClearColor to change the background color. change it to red or blue.. just something not black or white. if you can see the black shape of the object against the new background color you will at least know that it is a problem with your lighting and not that the object isn''t getting drawn.
My object is getting drawn. Its dark gray but i can see it. I''ll look into the normals, i forgot about those Any other possabilities/suggestions are appreciated.
ECKILLER
I got it, it was the normals.

ECKILLER
ECKILLER

This topic is closed to new replies.

Advertisement