Difference between glOrtho and glViewPort in openGL

I'm struggling to figure something out, let them say im to an image having a height of 100 and a width of 100.

In scenario A

I accept glOrtho(0,100,0,100,-100,100) and glViewPort(0,0,50,50) when glOrthois is defined as (left, right, lower, upper, zNear, zFar) and glViewPort (lower left corner x, lower left angle y, width, height).

In scenario B

I take a glOrtho(0,50,0,50,-100,100) and glViewPort(0,0,100,100) when glOrthois is defined as (left, right, bottom, top, zNear, zFar) and glViewPort is defined (bottom left corner x, bottom left corner y, width, height)

This basically means that in scenario A, the image will be displayed at a lower width and height than required (that is, st will be displayed every two pixels). In the original image, one will be displayed on the target "surface", but the whole image will be visible.

In Scenario B, however, the image will be cropped and only the upper left quarter will be visible. I'm right? - just to be clear, this is a question from the CG im tommorow test, and I want to make sure that I got OpenGL correctly ... (already read the API ... =\ )

+6
source share
2 answers

glViewPort is in pixel units of the screen: that it has nothing to do with the 3D world “inside” your video card. It simply reports that part of the window will be used for rendering (or just visible).

glOrtho instead changes the “inner” world and is OpenGL modules: More OpenGL blocks fit in the visible part of the screen, so “large” objects will easily fit in the visible area if you increase the spelling size.

Changing the viewport does not change the truncation; in fact, the same image is simply stretched to fit the new viewport.

Explicative Images:

Image 1: - this is a window with half a window

enter image description here

Figure 2: If I just doubled the viewing area, the image will be stretched (the same truncated corner that fills another surface).

enter image description here

Thus, the only solution for maintaining proportions is to double the spelling size (in this case, I double the left and right values)

Figure 3: final result (note that most of the 3D world is now visible):

enter image description here

More information is available on a fairly familiar OpenGL NeHe product site .

+20
source

These two things affect the different stages of the transformation of the GL coordinate transformation. OpenGL uses weaving, which in the normalized space of the device is a cube in the range [-1,1] for all 3 dimensions. The call to glOrtho() usually used to set up a projection matrix that transforms the coordinates of the eye space into the clip space. GL will be internally converted from the clip location to NDC. In the orthogonal case, you can even assume that the clip space and the NDC are the same. The view window describes the conversion from NDC to the window where the rasterization takes place.

Am I right? - just to be clear, this is a question from the CG im test I need to make sure that I opened OpenGL correctly ...

You are probably right for case A. In case B, the left quarter is probably primed. But in fact, the question is impossible if no additional information is provided. You say that the image has a width and height of 100. Typically, these dimensions are interpreted as the number of pixels in each direction. But in this case, the question arises that the square that is equipped with the image is visualized in such a way that it will fall into the eye space from (0,0) to (100,100) (either using this directly as the coordinates of the object, or using another mdoel and / or view conversions). It is also not indicated how the image is displayed, that is, it can be rotated (which does not allow us to determine which part of the image is visible in scenario B with any reasonable certainty).

Another observation is that glOrtho() will multiply the current matrix by the orthogonal projection matrix. Therefore, if the initial state of this matrix is ​​unknown, it is impossible to say what the resulting transformation will be.

I hope that this test will not contain such ill-conceived questions.

0
source

Source: https://habr.com/ru/post/971666/


All Articles