Jump to content
  • Advertisement
Sign in to follow this  
ruben7

OpenGL Lighting and Shading 101

This topic is 2172 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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. Edited by ruben7

Share this post


Link to post
Share on other sites
Advertisement
Seems that glut is messing with some internal state, no? You really shouldn't be using glut or fixed-functionality.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!