Introduction to OpenGL-viewport and object movement functions

Source: Internet
Author: User

University when there is an elective, to use OpenGL, very elementary content, the same introduction of the study of younger brother to apply

Recommended a learning Material Nehe OpenGL tutorial, very complete and have examples, speak very clearly. Better than some broken books.

can cooperate with the so-called "Red Book" to see, the Chinese wrote the book do not read, I have borrowed several of the contents are some mistakes.

Getting Started is enough.

English: http://nehe.gamedev.net/

English: http://www.yakergong.net/nehe/

Start to the chase:

Gltranslatef (x, y, z); Translate objects

Glrotatef (angle, x, Y, z), around developing vector rotation

Glscalef (x, Y, z), scaled Object 1.0 to original size

Glpushmatrix ();//Store the current view matrix

Glpopmatrix ();//Popup Last saved location

*glulookat (EYEX,EYEY,EYEZ,CENTERX,CENTERY,CENTERZ,UPX,UPY,UPZ); The position of the first three specified eyes, the middle three designated center point position, that is, the position of sight direction is usually 0, 0,0, the last three specifies which direction is above (use this to control the camera position.) If I'm wrong, I'm a beginner, so I think it's a good theory. But is the camera really in control? (recently learned that this function is encapsulated GLTRANSLATEF and GLROTATEF two functions are not recommended for use in the GL Standard library)

Example:  glulookat ( -2.0f,5.0f,10.0f,0.0f,0.0f,0.0f,0.0f,1.0f,0.0f);
 glpushmatrix ();
 gltranslatef (0.0f,0.0f,3.0f);
 glbegin (gl_quads);       //  draw a square
 glvertex3f ( -1.0f, 1.0f, 0.0f);      //left Upper
 glvertex3f (1.0f, 1.0f, 0.0f);      //Upper right
 glvertex3f (1.0f,-1.0f, 0.0f);      //left
 glvertex3f ( -1.0f,- 1.0f, 0.0f);      //right down
 glend ();
 glcolor3f (1.0f,0.0f,0.0f);
 glpopmatrix ();
 gltranslatef (0.0f,0.0f,-3.0f);
 glbegin (gl_quads);
 glvertex3f ( -1.0f, 1.0f, 0.0f),      //upper left
 glvertex3f (1.0f, 1.0f, 0.0f);      //Upper right
 glvertex3f (1.0f,-1.0f, 0.0f);      //Bottom left
 glvertex3f ( -1.0f,-1.0f, 0.0f);      //right down
 glend ();  

Equivalent

Glulookat ( -2.0f,5.0f,10.0f,0.0f,0.0f,0.0f,0.0f,1.0f,0.0f);
Gltranslatef (0.0f,0.0f,3.0f);
Glbegin (gl_quads); Draw a square
glvertex3f ( -1.0f, 1.0f, 0.0f); Upper left
glvertex3f (1.0f, 1.0f, 0.0f); Top Right
glvertex3f (1.0f,-1.0f, 0.0f); Lower left
glvertex3f ( -1.0f,-1.0f, 0.0f); Lower right
Glend ();
glcolor3f (1.0f,0.0f,0.0f);

Glloadidentity ();
Glulookat ( -2.0f,5.0f,10.0f,0.0f,0.0f,0.0f,0.0f,1.0f,0.0f);
Gltranslatef (0.0f,0.0f,-3.0f);
Glbegin (gl_quads);
glvertex3f ( -1.0f, 1.0f, 0.0f); Upper left
glvertex3f (1.0f, 1.0f, 0.0f); Top Right
glvertex3f (1.0f,-1.0f, 0.0f); Lower left
glvertex3f ( -1.0f,-1.0f, 0.0f); Lower right
Glend ();

Reference a section of the tutorial:

When you call Glloadidentity (), you actually move the current point to the center of the screen, the x-axis from left to right, the y-axis from bottom to top, and the z-axis from inside to outside. The coordinate values for the center of the OpenGL screen are the 0.0f points on the x and Y axes. The center left coordinate value is negative and the right side is positive. Moving to the top of the screen is positive, and moving to the bottom of the screen is negative. Moving to the bottom of the screen is negative, and moving out of the screen is positive.

Gltranslatef (x, y, z) move along the X, y, and Z axes. According to the preceding order, the following code moves left 1.5 units along the x-axis, the y-axis does not move (0.0f), and finally moves into the screen 6.0f units.

Here is a free hand-drawn version of the OpenGL coordinate system, note that the z-axis is a vertical monitor outward.

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.