Three movement differences of light sources in OpenGL

Source: Internet
Author: User

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 ();


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.