1. Light source does not move: you need to finish setting the view model transform. Then set the position of the light source and turn it on.
The pseudo code is as follows:
Glmatrixmode (gl_projection);
Glloadidentity ();
xxxxxxxxxx;
Glmatrixmode (Gl_modelview);
Glloadidentity ();
Glfloat Light_position []={1.0,1.0,1.0,1.0};//
GLIGHTFV (gl_light0,gl_position,light_position);//These two codes appear only after the most I
2. Independent Mobile Light Source:
(1), the movement of the light source is set at the end, as in Method 1. (2) The movement of the light source is considered during the change of the model matrix. The trick is to use Glpushmatrix () and Glpopmatrix () skillfully.
The pseudo code is as follows:
Glfloat light_position []={1.0,1.0,1.0,1.0};
Glupushmatrix ();
Glulookat ();
Glupshmatrix ();
Glrotated ();
GLLIGHTFV (gl_light0,gl_position,light_position);//note where the GLLIGHTFV () function appears
Glupopmatrix ();
Then perform the other model's operations.
Glflush ();
3. Move the light and observer points together:
The method is to set the light position before the view transformation
, and then the view transforms, the light source and the observer point are affected in the same way. Remember that the light source is stored in visual coordinates.
Pseudo code:
Glfloat light_position []={1.0,1.0,1.0,1.0};
GLIGHTFV (gl_light0,gl_position,light_position);//Note that these two lines of code appear before the view settings. The relative position of the camera and the viewpoint is fixed at this time.
Glviewport ();
Glmatrixmode (gl_projection);
Glloadidenty ();