Hi,
I’m a very new beginner to OpenGL. I’m trying to add a light source that points to a specific location on my plane surface containing 2 axes (X and Y), which means it appears like a cone.
However, the code below doesn’t work the way I want it to, and I’m not really sure why, since the light just scatters all over the surface of the plane.
void init_light()
{
GLfloat mat_specular[] = { 1.0, 1.0, 1.0, 1.0 };
GLfloat mat_shininess[] = { 50.0 };
GLfloat light_position[] = { 1.0, 1.0, 1.0, 1.0 };
glClearColor (0.0, 0.0, 0.0, 0.0);
glShadeModel (GL_SMOOTH);
glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess);
glLightfv(GL_LIGHT0, GL_POSITION, light_position);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_DEPTH_TEST);
}
void display() {
computeCameraPosition();
glClearColor(0.1, 0.1, 0.1, 1.0);
/* Clear frame buffer and z buffer */
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(eye[0], eye[1], eye[2],
centroid[0], centroid[1], centroid[2],
yaxis[0], yaxis[1], yaxis[2]);
drawAxes();
glFlush();
glutSwapBuffers();
}
int main(int argc, char **argv) {
glutInit(&argc, argv);
glutInitWindowSize(800, 800);
glutInitWindowPosition (200, 100);
glutCreateWindow("Scene Editor");
init_light();
glutDisplayFunc(display);
// glutReshapeFunc(myReshape); - leave it for a while
glutMainLoop();
}