Jump to content

  • Log In with Google      Sign In   
  • Create Account


ruben7

Member Since 08 Dec 2012
Offline Last Active Apr 18 2013 07:21 PM

Topics I've Started

Lighting and Shading 101

08 December 2012 - 01:19 PM

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[i]->Render();
  glPopMatrix();
}

I've attached 2 screenshots, one with the glutSolidsphere() commented out and another drawing them.

PARTNERS