Hi
I just recently got into opengl programming.
Basically what I am trying to do is to create a scene where everything is dark except the flashlight on my camera. So I made a textured skybox to move around in.
I got a form of lighting but it seems to be stationary. I messed around with quite a few settings like exponent , cutoff and annuattion but I never seem to be able to move my light in the direction where my camera is going it always stays in the same spot.
this is what i wrote thus far:
InitGL
void Scene::initializeGL()
{
camera = new Camera();
world = new World();
object = new Object();
world->initSkybox();
QGLWidget::initializeGL();
glShadeModel(GL_SMOOTH);
glClearColor(0.0f,0.0f,0.0f,0.0f);
glClearDepth(1.0f);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
//Light
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
camera->Position_Camera(10, 3, -20, 0, 2.5f, 0, 0, 1, 0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
timer->start(10);
my paintGL
void Scene::paintGL()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode( GL_MODELVIEW );
glLoadIdentity();
GLfloat ambientColor[] = {0.0f, 0.0f, 0.0f, 1.0f};
glLightModelfv(GL_LIGHT_MODEL_AMBIENT, ambientColor);
GLfloat lightPos [] = {camera->mPos.x,camera->mPos.y,camera->mPos.z,1.0};
glLightfv(GL_LIGHT0,GL_POSITION,lightPos);
GLfloat spotDir[] = {camera->mView.x - camera->mPos.x,camera->mView.y- camera->mPos.y,camera->mView.z - camera->mPos.z};
glLightfv(GL_LIGHT0,GL_SPOT_DIRECTION,spotDir);
gluLookAt(camera->mPos.x, camera->mPos.y, camera->mPos.z,
camera->mView.x, camera->mView.y, camera->mView.z,
camera->mUp.x, camera->mUp.y, camera->mUp.z);
world->drawSkyBox(0,0,0,1000,1000,1000);
}