# OpenGL Lighting

Page 1 of 1

## 1 Replies - 1029 Views - Last Post: 13 January 2012 - 07:40 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'https://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=262862&amp;s=03657198b867d47373e125023f98c359&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 programmerblack

Reputation: 0
• 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);

glPopMatrix();

Is This A Good Question/Topic? 0

## Replies To: OpenGL Lighting

### #2 anonymous26

• D.I.C Lover

Reputation: 2
• Posts: 3,638
• Joined: 26-November 10

## Re: OpenGL Lighting

Posted 13 January 2012 - 07:40 PM