Advertisement

Lesson 7

Started by June 17, 2003 08:02 AM
2 comments, last by iTec 21 years, 8 months ago
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
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
How do I set my laser printer on stun?
Advertisement
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);
glShadeModel(GL_SMOOTH);
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;
Sorry, but it''s a bit difficult to see what part of your code you''re posting exactly.

quote:

glEnable(GL_TEXTURE_2D);
glShadeModel(GL_SMOOTH);
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.
How do I set my laser printer on stun?

This topic is closed to new replies.

Advertisement