PDA

View Full Version : Lighting Help



05-10-2002, 12:13 PM
Hey! I need help getting lighting into this scene. It's just a test but I need to learn lighting anyhow.
Here is the code:

//Lighting

//Enable Light0
glEnable(GL_LIGHT0);

//Set Ambient Color
GLfloat ambient[4] = {0.8,0.1,0.7,1.0};
glLightfv(GL_LIGHT0,GL_AMBIENT,ambient);

//Set Position
//General Positions of Polygons
/*
glVertex3i(25,25,0);
glVertex3i(125,95,0);
glVertex3i(84,95,2);
=====End=====
glVertex3i(25,25+15/2,0);
glVertex3i(125,95+15/2,0);
glVertex3i(84,95+15/2,1);
=====End=====
glVertex3i(25,25+15,0);
glVertex3i(125,95+15,0);
glVertex3i(84,95+15,0);
=====End=====
glVertex3i(25,25+30,0);
glVertex3i(125,95+30,0);
glVertex3i(84,95+30,-1);
=====End=====
*/

GLfloat lightPos[4] = {125,95+30,0,0.0};
glLightfv(GL_LIGHT0,GL_POSITION,lightPos);

glutDisplayFunc(renderScene);
glutKeyboardFunc(keyCB);
glutMainLoop();

Bob
05-11-2002, 12:30 AM
You enable light 0, but do you enable the lighting system? That is, glEnable(GL_LIGHTING). I don't see you pass any normals to your vertices, and I don't see any glBegin/glEnd around your vertices. As it is, the code looks VERY incomplete. Post the whole code as it is, and not just small pieces from different parts of the code. Of course, you can leave totally irrelevant stuff like texture loading, and similar stuff.

05-11-2002, 11:34 AM
Thankz, now it works. I just changed the position and enabled the lighting system which I forgot to do. Thanks Bob for pointing that out...