PDA

View Full Version : Calculating Window Coordinates -- glViewPort



desi_jatt
03-29-2017, 10:50 PM
I was reading OpenGL's documentation for glViewPort and there was given a formula for how Window Coordinates are calculated in OpenGL.

This is the equation : - xwindow = (xnormalized + 1) * (width / 2) + x

I'm a li'l bit confused, what if xnormalized = 1.0 ? Will the xwindow go out of Screen's Width?

Like:

xwindow = (1 + 1) * (width / 2) + x;
xwindow = 2 * (width/2) + x = width + x
(width being the width of the actual resolution of the Screen)

So, doesn't it go out of the Screen? Somebody please clear this confusion.

Silence
03-30-2017, 01:10 AM
No. Unless you set the viewport x position to a non zero value and/or a viewport width larger than the screen.

So, if you define this:



glViewport(0,0,800,600);


with a window with the same size (800x600), then xwindow max value can be width=800, which is perfect.
But if you do something like



glViewport(100,0,800,600);


Then for sure, you'll exceed the physical window size.

Read this (https://www.khronos.org/registry/OpenGL-Refpages/es2.0/xhtml/glViewport.xml)(maybe once again if the documentation you are referring to is the same).

desi_jatt
03-30-2017, 02:00 AM
Thank you for clearing the situation. : )