PDA

View Full Version : Lighting trouble



Montoya
02-17-2003, 09:10 AM
Hey there, this is probably a newbie question, but what the hell.
I am trying to simulate a solar system, and at the moment, am making a test binary solar system. However, only GL_LIGHT0 seems to cast any light on the planets, and GL_LIGHT1 does nothing, though if I rename LIGHT1 as 0 it works. Oddness. The following is some of the code, that deals with the lighting, the planets and the camera class, which uses lookAt.

int InitGL(GLvoid)
{
.
.
.
matAmbient[0] = 1.0f;
matAmbient[1] = 1.0f;
matAmbient[2] = 1.0f;
matAmbient[3] = 1.0f;

ambient[0] = -0.1f;
ambient[1] = -0.1f;
ambient[2] = -0.1f;
ambient[3] = 1.0f;

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

glEnable(GL_COLOR_MATERIAL);
glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE);

glLightfv(GL_LIGHT0, GL_AMBIENT, ambient);
// glLightfv(GL_LIGHT0, GL_DIFFUSE, ambient);

glLightfv(GL_LIGHT1, GL_AMBIENT, ambient);
// glLightfv(GL_LIGHT1, GL_DIFFUSE, ambient);

glMaterialfv(GL_FRONT, GL_SPECULAR, matSpecular);
glMaterialf(GL_FRONT, GL_SHININESS, 3.0f);

glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_LIGHT1);

.
.
.
}

bool DrawScene()
{
.
.
.
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glMatrixMode(GL_MODELVIEW);

// gluLookAt(cam_x, cam_y, cam_z, sun->position.x, sun->position.y, sun->position.z, 0.0, 1.0, 0.0);
gluLookAt(g_Camera.m_vPosition.x, g_Camera.m_vPosition.y, g_Camera.m_vPosition.z,
g_Camera.m_vView.x, g_Camera.m_vView.y, g_Camera.m_vView.z,
g_Camera.m_vUpVector.x, g_Camera.m_vUpVector.y, g_Camera.m_vUpVector.z);

//glRotatef(0.1f, 0.0, 1.0, 0.0);

glInitNames(); // This clears the name stack so we always start with 0 names.
glPushName(0); // This starts off the first object in the stack

float ro=45.0;

glLoadName(SUN);
glBegin(GL_LINES);
glEnd();
//sun->SetLight(0);
sun->Draw(test_rotate);
lightPosition[0] = sun->position.x;
lightPosition[1] = sun->position.y;
lightPosition[2] = sun->position.z;
lightPosition[3] = 1.0f;
glLightfv(GL_LIGHT0, GL_POSITION, lightPosition);

glLoadName(SUN2); // Push on our SUN label (IMPORTANT)
glBegin(GL_LINES);
glEnd();
//sun2->SetLight(1);
sun2->Draw(test_rotate);
lightPosition[0] = sun2->position.x;
lightPosition[1] = sun2->position.y;
lightPosition[2] = sun2->position.z;
lightPosition[3] = 1.0f;
glLightfv(GL_LIGHT1, GL_POSITION, lightPosition);

}

Bob
02-17-2003, 10:00 AM
All lights but the first defaults to black color. The first defaults to white. So unless you set any colors for GL_LIGHT1 and above, only GL_LIGHT0 will affect your scene.

Montoya
02-17-2003, 10:42 AM
It's official - I'm an idiot. A thousand thanks to you sir. http://www.opengl.org/discussion_boards/ubb/smile.gif