To main page | 3dengine.org

Viewport matrix


Viewport matrix is 1 by 4 matrix, used in OpenGL like so:
[x, y, width, height]
x,y specify coordinates of lower-left point on user's screen, usually x=0, y=0.

width and height specify inner width and height of OpenGL window.

Is it a matrix ?

Well, it isn't a matrix per se, more like 4 integers, because most of the code I've seen actually uses usual math, rather than matrix math, when dealing with the viewport data.

Setting

It is usually set by
glViewport(x,y,width,height) 

Reading

It can be get back by
glGetIntegerv(GL_VIEWPORT, ar)
ar is reference to array of 4 elements (x,y,width,height).

In PyOpengl the call would be
x,y,width,height=glGetInteger(GL_VIEWPORT).

Warning

Note that this matrix is set and read in integers.

See also

Center of viewport