1 Replies - 726 Views - Last Post: 13 January 2012 - 07:40 PM Rate Topic: -----

#1 programmerblack  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 28-January 11

OpenGL Lighting

Posted 13 January 2012 - 06:30 PM

Hello DIC,

I'm trying to add a light that shines in the direction of my object. I can't get it to be in the correct place, and shine in the correct direction. There's a rotating sphere that's moving around an inner object, similar to a moon orbiting a planet. Here's the section of code I'm having trouble with. This is for homework, I've been working on this for 5+ hours, and am slowing beginning to hate OpenGL because it's counter intuitive to what I know. I'm coming from XNA programming. There's 1 matrix created per object model, cameras, and etc. This matrix stack throws me way off. Here's the code posted below:

// set up a temporary transform for the orbiting sphere
glPushMatrix();

// make light rotate about an odd axis
glRotatef(m_angle, 1.0f, 1.0f, 0.0f);

// move the light into upper left corner of the scene
glTranslatef(-2.0, 2.0, 3.0f);

// draw a small sphere for light position
GLfloat lightColor[] = { 1.0f, 1.0f, 1.0f };
GLfloat specularColor[] = { 1.0f, 0.0f, 0.0f };
GLfloat lightPos[] = { 0.0f, 0.0f, 0.0f, 1.0f };
glLightfv(GL_LIGHT0, GL_POSITION, lightPos);
glLightfv(GL_LIGHT0, GL_AMBIENT_AND_DIFFUSE, lightColor);
glLightfv(GL_LIGHT0, GL_SPECULAR, specularColor);

glEnable(GL_LIGHT0);

gluSphere(m_Quadric, 0.2, 10, 10);

glPopMatrix();

By the way, I already enabled lighting before this executes. Thanks in advance for any answers.

Is This A Good Question/Topic? 0
  • +

Replies To: OpenGL Lighting

#2 anonymous26  Icon User is offline

  • D.I.C Lover

Reputation: 0
  • View blog
  • Posts: 3,638
  • Joined: 26-November 10

Re: OpenGL Lighting

Posted 13 January 2012 - 07:40 PM

What's your last glMatrixMode()?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1