Advertisement

SpotLights OpenGL

Started by June 15, 2000 07:42 AM
2 comments, last by Gandalf 24 years, 5 months ago
glLightfv(GL_LIGHT0, GL_SPOT_DIRECTION, LightDirection); glLighti(GL_LIGHT0, GL_SPOT_CUTOFF, 90); glLightf(GL_LIGHT0, GL_CONSTANT_ATTENUATION, 1); glLightf(GL_LIGHT0, GL_LINEAR_ATTENUATION, 0); glLightf(GL_LIGHT0, GL_QUADRATIC_ATTENUATION, 0); Witch values to choose to get a "normal", spotlight? The distance between the light and the vertex is 15 units. All help is wellcommed! Show me your code! Gandalf the White Gandalf the White
Gandalf the Black
How to create a decent spotlight in OpenGL? All my objects turn dark. I´m sure about the direction but not so sure about GL_SPOT_EXPONENT and the attenuation params. I set the angle to 90 degree. Nothing happend. Darker then coffe.

Please help, OpenGL wizard out there!

Gandalf the White


Gandalf the White

Gandalf the Black
Advertisement
hi Gandalf

maybe you have forgotten the light position?

glLightfv(GL_LIGHT0, GL_POSITION,light0_position);

hope that help

lunasol

Hopefully this''ll help. I''m still rather new to the OpenGL stuff myself. It''s a section of code I got from a tutorial, and seems to work fairly well. (Adds a little ambience and specular light for effect)

GLfloat ambientlight[] = {0.5f, 0.5f, 0.5f, 1.0f};
GLfloat specular[] = {1.0f, 1.0f, 1.0f, 1.0f};

//enable lighting
glEnable(GL_LIGHTING);

//Set up light 0
glLightModelfv(GL_LIGHT_MODEL_AMBIENT, ambientlight);

//the light is composed of just diffuse and specular components
glLightfv(GL_LIGHT0, GL_DIFFUSE, ambientlight);
glLightfv(GL_LIGHT0, GL_SPECULAR, specular);
glLightfv(GL_LIGHT0, GL_POSITION, lightposition);
glLightfv(GL_LIGHT0, GL_SPOT_DIRECTION, spotdir);

//set up spot effects
glLightf(GL_LIGHT0, GL_SPOT_CUTOFF, 60.0f);

//make a shiny spot
glLightf(GL_LIGHT0, GL_SPOT_EXPONENT, 100.0f);

//enable the light
glEnable(GL_LIGHT0);

This topic is closed to new replies.

Advertisement