12-09-2005, 10:21 PM
I'm trying to get multiple spotlights to shine on the z and x axes, in both the positive and negative direction.
GLfloat LightPosition[]= { 0.0f, 0.0f, 0.0f, 1.0f };
GLfloat spot_direction[] = { 0.0f, 0.0f, -1.0f };
In my init() function I have:
glLightf(GL_LIGHT0, GL_SPOT_CUTOFF, 15.0f); // Set up spotlight
glLightf(GL_LIGHT0, GL_SPOT_EXPONENT, 20.0f);
glLightfv(GL_LIGHT0, GL_SPOT_DIRECTION, spot_direction);
glLightfv(GL_LIGHT0, GL_POSITION, LightPosition);
glEnable(GL_LIGHT0);
I tried creating the others in a similar fashion, with the spot_direction values changing accordingly. But it didn't work, hehe obviously. So to experiment why, I played around with the first spotlight, which worked. Surprisingly, I'm not messing with the MatrixMode stuff and it's following my viewer as it looks anywhere where the heading is towards the negative z-axis. But if I change the spot_direction to anything where the z parameter is not a negative value, I get complete darkness.
Another confusing thing is that the spotlight is following the viewer throughout my 3D world - even through textured walls - and I'm not including any lighting code in my draw(). I'm a complete openGL newbie, but from searching for the past 5 hrs for clues, it seems that my spotlight is doing things it shouldn't and also not corresponding correctly to changes =/. I don't know if I made any sense, but I need some help as this is for a final project of mine due in a few days. This one problem has bogged me down for the past 19 hrs I've spent on it.
GLfloat LightPosition[]= { 0.0f, 0.0f, 0.0f, 1.0f };
GLfloat spot_direction[] = { 0.0f, 0.0f, -1.0f };
In my init() function I have:
glLightf(GL_LIGHT0, GL_SPOT_CUTOFF, 15.0f); // Set up spotlight
glLightf(GL_LIGHT0, GL_SPOT_EXPONENT, 20.0f);
glLightfv(GL_LIGHT0, GL_SPOT_DIRECTION, spot_direction);
glLightfv(GL_LIGHT0, GL_POSITION, LightPosition);
glEnable(GL_LIGHT0);
I tried creating the others in a similar fashion, with the spot_direction values changing accordingly. But it didn't work, hehe obviously. So to experiment why, I played around with the first spotlight, which worked. Surprisingly, I'm not messing with the MatrixMode stuff and it's following my viewer as it looks anywhere where the heading is towards the negative z-axis. But if I change the spot_direction to anything where the z parameter is not a negative value, I get complete darkness.
Another confusing thing is that the spotlight is following the viewer throughout my 3D world - even through textured walls - and I'm not including any lighting code in my draw(). I'm a complete openGL newbie, but from searching for the past 5 hrs for clues, it seems that my spotlight is doing things it shouldn't and also not corresponding correctly to changes =/. I don't know if I made any sense, but I need some help as this is for a final project of mine due in a few days. This one problem has bogged me down for the past 19 hrs I've spent on it.