• ### Popular Now

• 14
• 12
• 9
• 10
• 13

#### Archived

This topic is now archived and is closed to further replies.

# Lesson 7

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

## Recommended Posts

i''ve added a diffuselight source to my project with the help of lesson 7 but it seems that the lightsource rotates along with my cube. Yet i can find out why. May anyone has an idea? Grtz iTec

##### Share on other sites
You have to be carefull about the order you do your conversions. If I recall correctly first insert geometry, then do all the translations/rotations of geometry, then insert the light via glLightfv(light.name,GL_POSITION,light.position);.

If that doesn''t help, try doing the following:
    glPushMatrix();    {        // Do rotations + translations        // Insert geometry    }    glPopMatrix();    // Insert Lights

##### Share on other sites
Don''t know anything about glPushMatrix() and glPopMatrix() yet but I insert the light in the initGL just like in the tutorial (only a bit modified)

glEnable(GL_TEXTURE_2D);
glClearColor(0.0f, 0.0f, 0.0f, 0.5f);
glClearDepth(1.0f);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);

glLightfv(GL_LIGHT1, GL_AMBIENT, World.Light.Ambient.Color);

bool chk = false;
cDiffuseLight Current = (cDiffuseLight) *(World.Light.firstDiffuse());
do{
glLightfv(Current.Name, GL_DIFFUSE, Current.Color);
glLightfv(Current.Name, GL_POSITION,Current.Position);
glEnable(Current.Name);

if(Current.Volgende!=NULL){
cDiffuseLight *tc = Current.Volgende;
Current = (cDiffuseLight) *tc;
chk = true;
}else{
chk = false;
}
}while (chk);
glEnable(GL_LIGHTING);
return TRUE;

##### Share on other sites
Sorry, but it''s a bit difficult to see what part of your code you''re posting exactly.

quote:

glEnable(GL_TEXTURE_2D);
glClearColor(0.0f, 0.0f, 0.0f, 0.5f);
glClearDepth(1.0f);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);

All this is initialisation stuff, and should only be done once (=beginning of your programm).
quote:

glLightfv(Current.Name, GL_POSITION,Current.Position);

While this is a part of code you''ll need to put into the main loop. You''ll have to insert the light every time you changed the orientation of the geometry, otherwise the changes will affect the light as well (which you don''t want obviously).

As for glPush/PopMatrix: These function store/restore the transformation matrix. That is: if you do glPushMatrix, then do some transformations (glRotate, glTranslate), then do glPopMatrix the original Matrix is restored. Resulting in geometry outside the Push/Pop block not being affected by any of the translations inside.