Advertisement

directional lighting

Started by October 02, 2003 05:58 PM
-1 comments, last by Crispy 21 years, 5 months ago
I''d like to get spotlights working, but evidently there''s this hidden parameter I have to set up to tweak the spot itself. I know it should be GL_SPOT_CUTOFF, but rather annoyingly it doesn''t affect the cone size in any way. I''ll just post the entire code listing to save some hassle explaining the stuff: Setting up the light:

float ambcol[4] = { 0.0, 0.0, 0.2, 1.0};
float difcol[4] = { 0.0, 0.0, 0.8, 1.0};
float specol[4] = { 0.0, 0.0, 0.4, 1.0};

float matAmb[4] = {0.2, 0.2, 0.2, 1.0};
float matDiff[4] = {0.8, 0.8, 0.8, 1.0};
float matSpec[4] = {0.4, 0.4, 0.4, 1.0};
float matEmission[4] = {0.0, 0.0, 0.0, 1.0};
float modelAmb[4] = {0.2, 0.2, 0.2, 1.0};

  glLightModelfv(GL_LIGHT_MODEL_AMBIENT, modelAmb);
  glLightModelf(GL_LIGHT_MODEL_LOCAL_VIEWER, GL_TRUE);
  glLightModelf(GL_LIGHT_MODEL_TWO_SIDE, GL_FALSE);

  glMaterialfv(GL_FRONT, GL_AMBIENT, matAmb);
  glMaterialfv(GL_FRONT, GL_DIFFUSE, matDiff);
  glMaterialfv(GL_FRONT, GL_SPECULAR, matSpec);
  glMaterialfv(GL_FRONT, GL_EMISSION, matEmission);
  glMaterialf(GL_FRONT, GL_SHININESS, 10.0);

  glEnable(GL_NORMALIZE);
    glEnable(GL_LIGHT0);

    glLightf(GL_LIGHT0, GL_SPOT_EXPONENT, 20);
    glLightf(GL_LIGHT0, GL_SPOT_CUTOFF, 60);
    glLightf(GL_LIGHT0, GL_CONSTANT_ATTENUATION, 1.0);
    glLightf(GL_LIGHT0, GL_LINEAR_ATTENUATION, 0.0);
    glLightf(GL_LIGHT0, GL_QUADRATIC_ATTENUATION, 0.0);

    glLightfv(GL_LIGHT0, GL_AMBIENT, ambcol);
    glLightfv(GL_LIGHT0, GL_DIFFUSE, difcol);
    glLightfv(GL_LIGHT0, GL_SPECULAR, specol);
And using it:

float lpos[3] = { 0, 30, -20 };
float ldir[3] = { 0, -1, 1 };
glTranslatef(lpos[0], lpos[1], lpos[2]);
glRotatef(lightrot, 0, 0, 1); //for the heck of it

glLightfv(GL_LIGHT0, GL_POSITION, lpos);
glLightfv(GL_LIGHT0, GL_SPOT_DIRECTION, ldir);
The light is direcional alright and rotating it causes it to behave the way one would expect (when it faces away, stuff isn''t lit), but there''s no way I''ve been able to form the target sufrace that is lit into a proper cone - instead it lights a huge area and when GL_SPOT_CUTOFF is decreased to marginally low levels (< 10 or so), the light simply fades out, but the cone size doesn''t change. Any suggestions?
"Literally, it means that Bob is everything you can think of, but not dead; i.e., Bob is a purple-spotted, yellow-striped bumblebee/dragon/pterodactyl hybrid with a voracious addiction to Twix candy bars, but not dead."- kSquared

This topic is closed to new replies.

Advertisement