PDA

View Full Version : Lighting questions and problems



juanmanuelsanchez
02-04-2007, 10:36 AM
hi all ! Im new here and Im tryning to code a opengl app, so far I got my model into game and a moving camera with the mouse. But Im having issues to setup the lights.

1) My idea is to create a soccer stadium, so wich is the best approach? just code spot lights to cover the whole scene?

2) So far I have this (the idea is to load the lights from an ASE file),but this is for testing:



CGL_Light3D::CGL_Light3D () {

m_pSphere = NULL;
m_pSphere = gluNewQuadric();

ambient[0] = 5.0f;
ambient[1] = 1.0f;
ambient[2] = 1.0f;
ambient[3] = 1.0f;

diffuse[0] = 1.0f;
diffuse[1] = 1.0f;
diffuse[2] = 1.0f;
diffuse[3] = 1.0f;

specular[0] = 0.0f;
specular[1] = 0.0f;
specular[2] = 0.0f;
specular[3] = 1.0f;


position[0] = 0.0f;
position[1] = 1.0f;
position[2] = 0.0f;
position[3] = 0.0f;

spot_direction[0] = 0.0f;
spot_direction[1] = 0.0f;
spot_direction[2] = -1.0f;

spot_exponent = 0.0f;
spot_cutoff = 90.0f;

constant_attenuation = 1.0f;
linear_attenuation = 0.0f;
quadratic_attenuation = 0.0f;


}

void CGL_Light3D::TurnOn ( int light ) {


LIGHT=light;


glEnable(LIGHT);

//glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);

//glLoadIdentity();

glLightfv(LIGHT, GL_POSITION, position);
glLightfv(LIGHT, GL_AMBIENT, ambient);
glLightfv(LIGHT, GL_DIFFUSE, diffuse);
glLightfv(LIGHT, GL_SPECULAR, specular);
glLightf(LIGHT, GL_SPOT_EXPONENT,spot_exponent);
glLightfv(LIGHT, GL_SPOT_DIRECTION, spot_direction);
glLightf(LIGHT, GL_SPOT_CUTOFF,spot_cutoff);
glLightf(LIGHT, GL_CONSTANT_ATTENUATION, constant_attenuation);
glLightf(LIGHT, GL_LINEAR_ATTENUATION, linear_attenuation);
glLightf(LIGHT, GL_QUADRATIC_ATTENUATION, quadratic_attenuation);

//glLightModeli(GL_LIGHT_MODEL_TWO_SIDE,1);

}

void CGL_Light3D::Render(glCamera *Cam)
{


//glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);


// glLoadIdentity();
gluLookAt(Cam->m_Position.x, Cam->m_Position.y, Cam->m_Position.z,0.0,0.0,0.0, 0.0, 1.0, 0.0);

glPushMatrix();
glDisable(GL_LIGHTING);
// glRotatef(m_lightAngle, 1.0, 0.0, 0.0);
// glRotatef(m_lightAngle, 0.0, 1.0, 0.0);
glTranslatef(position[0], position[1], position[2]);
glColor3fv(ambient);
gluSphere(m_pSphere, 100.0f, 10, 10);
glEnable(GL_LIGHTING);
glPopMatrix();


}


Lights.SetPosition(-2022.3320f, -1185.0239f, 1263.6978f,1.0);
Lights.SetSpotDirection(82.0830f, -17.6392f, 0.0000f);
Lights.SetAmbientColor(0.8980f, 0.1373f, 0.1373f, 0.0f);
// Lights.SetSpotCutoff(43.0000f);
Lights.TurnOn(GL_LIGHT0);
My problem is that I have the light in the scene, at least I can see some red... but the light behaves as flash light that moves with the camera (split the camera in half and the right side is lighted while the left one is not).

Also the sphere, wich I use as reference, behaves in a weird way moving with the camera...

The help is appreciated.
THanks!

dorbie
02-11-2007, 08:11 PM
It's probably best to use a textured light map where you can paint spotlights onto the lightmap image and apply that to the field and color the players by sampling the right place on the image either in software or using texgen.