I am trying to create street lights in my environment box in opengl using c++. I need to create spot lights for this, I have written the code below but it does not work as a spot light. What am I doing wrong, or do you have any other solution for my problem?
GLfloat ambientLight[] = {0.7f, 0.2f, 0.2f, 1.0f};
glLightModelfv(GL_LIGHT_MODEL_AMBIENT, ambientLight);
GLfloat directedLight[] = {0.7f, 0.7f, 0.7f, 1.0f};
GLfloat directedLightPos[] = {-10.0f, 15.0f, 20.0f, 0.0f};
glLightfv(GL_LIGHT0, GL_DIFFUSE, directedLight);
glLightfv(GL_LIGHT0, GL_POSITION, directedLightPos);
Thanks.
If this is all of your light code you are missing some important lines. You only define ambient/diffuse light colors and a light position.
glEnable(GL_LIGHTING)glEnable(GL_LIGHT0)glLightfv(GL_LIGHT0, GL_SPOT_DIRECTION, direction);Two other notes: