Home c++ What is the Glortho function in OpenGL?

What is the Glortho function in OpenGL?

Author

Date

Category

Do I understand what GLORTHO can recalculate the coordinates?
I want to disassemble this part of the code:

glviewport (0,0, screenwidth, screenHeight);
GlMatrixMode (GL_Projection);
glloadidentity ();
Glortho (0, ScreenWidth, 0, ScreenHeight, 0, 1);
glmatrixmode (GL_Modelview);

After this code has become pixel values ​​(x from 0 to WindowWidth and Y from 0 Before Windowheight ). But this is not convenient for working with 3D so? Probably more suitable for working with 2D?


Answer 1, Authority 100%

When the vertices are in the space of the species, they will have three spatial coordinates. But your screen is flat, two-dimensional, and you can not take and draw a three-dimensional top on this screen – you need to do this three-dimensional vertex on the plane.

We can make it very different ways. The most commonly used promising and orthographic projection.

Imagine rails. They lie parallel to each other. But when they are far away, then it seems to us that they intersect. That is, objects that are far seem to us less. This is a promising projection.

orthographic projection works otherwise – it displays each point of three-dimensional space perpendicular to the plane. In a particular case, the third coordinate is not taken into account and simply take the coordinates of x and Y vertices.

Perspective projection is more suitable for three-dimensional graphics, computer games, and so on, because we see in real life. Orthographic projection is most often used in various CAD systems, when drawing, in engineering graphics …

So the function glortho just asks the matrix of the orthographic projection. That is, you demand from OpenGL so that your vertices from the view space are projected to the plane using an orthographic projection.


by the way, you use the old OpenGL version. In new versions in the Core Profile, the projection matrix must be set independently.


Answer 2

is a legacy. https://www.khronos.org/opengl/wiki/legacy_opengl
Need this feature so that the old programs continue to work.

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions