Jump to content

  • Log In with Google      Sign In   
  • Create Account

Lighting and Shading 101


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
1 reply to this topic

#1 ruben7   Members   -  Reputation: 103

Like
0Likes
Like

Posted 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.

Attached Thumbnails

  • 1.png
  • 2.png

Edited by ruben7, 08 December 2012 - 01:25 PM.


Sponsor:

#2 SHOKWAV   Members   -  Reputation: 120

Like
0Likes
Like

Posted 09 December 2012 - 03:27 PM

Seems that glut is messing with some internal state, no? You really shouldn't be using glut or fixed-functionality.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS