glViewport是OpenGL中的一个
函数,计算机图形学中,在屏幕上打开窗口的任务是由窗口系统,而不是OpenGL负责的。
glViewport在默认情况下,
视口被设置为占据打开窗口的整个像素矩形,窗口大小和设置视口大小相同,所以为了选择一个更小的绘图区域,就可以用glViewport函数来实现这一变换,在窗口中定义一个像素矩形,最终将
图像映射到这个矩形中。例如可以对窗口区域进行划分,在同一个窗口中显示分割屏幕的效果,以显示多个视图。
X,Y————以像素为单位,指定了
视口的左下角(在第一象限内,以(0,0)为原点的)位置。
glViewport specifies the affine transformation of x and y from normalized device coordinates to window coordinates. Let (xnd, ynd) be normalized device coordinates. Then the window coordinates (xw, yw) are computed as follows:
Viewport width and height are silently clamped to a range that depends on the implementation. This range is queried by calling glGet with argument GL_MAX_VIEWPORT_DIMS.
GL_INVALID_VALUE is generated if either width or height is negative. GL_INVALID_OPERATION is generated if glViewport is executed between the execution of glBegin and the corresponding execution of glEnd.