glViewport function

The glViewport function sets the viewport.

Syntax

void WINAPI glViewport(
   GLint   x,
   GLint   y,
   GLsizei width,
   GLsizei height
);

Parameters

x

The lower-left corner of the viewport rectangle, in pixels. The default is (0,0).

y

The lower-left corner of the viewport rectangle, in pixels. The default is (0,0).

width

The width of the viewport. When an OpenGL context is first attached to a window, width and height are set to the dimensions of that window.

height

The height of the viewport. When an OpenGL context is first attached to a window, width and height are set to the dimensions of that window.

Return value

This function does not return a value.

Error codes

The following error codes can be retrieved by the glGetError function.

Name Meaning
GL_INVALID_VALUE
Either width or height was negative.
GL_INVALID_OPERATION
The function was called between a call to glBegin and the corresponding call to glEnd.

Remarks

The glViewport function specifies the affine transformation of x and y from normalized device coordinates to window coordinates. Let (xnd , ynd ) be normalized device coordinates. The window coordinates (xw , yw ) are then computed as follows:

Equation showing computation of the window coordinates.

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.

The following functions retrieve information related to glViewport:

glGet with argument GL_VIEWPORT

glGet with argument GL_MAX_VIEWPORT_DIMS

Requirements

Requirement Value
Minimum supported client
Windows 2000 Professional [desktop apps only]
Minimum supported server
Windows 2000 Server [desktop apps only]
Header
Gl.h
Library
Opengl32.lib
DLL
Opengl32.dll

See also

glBegin

glDepthRange