Viewport usage & distortion

I’ve made a user-interface where I use a set_viewport() function for each ‘panel’ … sets the viewport to the dimensions of the ‘panel’. There are no other transformations involved and I send draw-commands in pixel-units and uses lower-left as (0,0) … and it works. Trying to understand what the viewport-transform does I’m becomming pussled WHY my setup works and why it does not distort whatever I draw.
If the viewport can be used to distort a drawing on the screen … what will you have to do to do that? If I perform a scale-matrix on it, it would make some sense. But, that’s not the viewport doing the distortion.

What kind of distortion are you talking about? Just a different aspect ratio (width1/height1 != width2/height2)?

ey Photon
Yes. The viewport gets the data of the rectangle it uses, in screen-coordinates (pixels). Horizontal and vertical panels are very different in their aspect_ratio.

Typically you use a projection matrix which corrects for the aspect ratio of the viewport.

hi Clements,
It makes sense that the projection does the trick.
I’ve got the ‘idea’ from the Bible 5. (page 27).
That’s a book with meny errors.

I misunderstood you … using a projection for a distortion sounds reasonable.
It’s the other way around: that a projection is needed to make the viewport do what you would expect. It looks as if an ortho(…), covering the same rect as the viewport is mandatory in d2-space.

If the viewport isn’t square, then the projection matrix (or some other part of the coordinate transformation process) needs a corresponding non-uniform scaling so that the combination of the projection and viewport transformations results in a uniform scaling.

To get the correct aspect ratio overall, the eye-space view frustum must have the same aspect ratio as the viewport. The clip-space view frustum has a 1:1 aspect ratio, so the transformation from eye space to clip space needs to be such that a viewport-shaped rectangle in eye space maps to a square in clip space. For glOrtho, gluOrtho2D, or glFrustum, (right-left)/(top-bottom) should match the viewport’s aspect ratio; for gluPerspective the aspect parameter should match.

For the viewport’s aspect ratio, you can either use the dimensions in pixels (i.e. the width and height parameters from the glViewport call) or you can convert these to physical dimensions (inches/mm) for more accurate results on monitors with non-square pixels.

Thank you Clemens,
I’ll keep this for future references. It takes time for all elements to settle properly …