Lighting and Shading 101

Started by
0 comments, last by SHOKWAV 11 years, 4 months ago
Hi guys, beginner here, I'm getting a very weird problem in opengl.

Whenever I draw a glutWire or solid sphere, the lighting on the rest of my objects are disabled.

Here's my Render method:

void RenderLights() {
// x,y,z,w
// w = 0 is directional; 1 is point light
// create light components
GLfloat ambientLight[] = { 0.2f, 0.2f, 0.2f, 1.0f };
GLfloat diffuseLight[] = { 0.8f, 0.8f, 0.8, 1.0f };
GLfloat specularLight[] = { 0.5f, 0.5f, 0.5f, 1.0f };
GLfloat position[] = { -10.0f, 1.0f, 10.0f, 1.0f };
// assign created components to GL_LIGHT0
glLightfv(GL_LIGHT0, GL_AMBIENT, ambientLight);
glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuseLight);
glLightfv(GL_LIGHT0, GL_SPECULAR, specularLight);
glLightfv(GL_LIGHT0, GL_POSITION, position);
}

// offset everything by the position of the player/camera
glTranslatef(-camera->GetPosition().x, -camera->GetPosition().y, -camera->GetPosition().z);
glPushMatrix();
RenderLights(); // this just sets materials and position
glPopMatrix();
// this here draws all the Balls, their render method simply translates and glutSolidSphere()
for(int i = 0; i < NUM_BALLS; i++) {
glPushMatrix();
gameobj_list->Render();
glPopMatrix();
}


I've attached 2 screenshots, one with the glutSolidsphere() commented out and another drawing them.
Advertisement
Seems that glut is messing with some internal state, no? You really shouldn't be using glut or fixed-functionality.

This topic is closed to new replies.

Advertisement