Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

glViewport

The glViewport function sets the viewport.

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

Parameters

x, y
The lower-left corner of the viewport rectangle, in pixels. The default is (0,0).
width, height
The width and height, respectively, of the viewport. When an OpenGL context is first attached to a window, width and height are set to the dimensions of that window.

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:

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

Error Codes

The following are the error codes generated and their conditions.

Error code Condition
GL_INVALID_VALUE Either width or height was negative.
GL_INVALID_OPERATION glViewport was called between a call to glBegin and the corresponding call to glEnd.

Requirements

  Windows NT/2000: Requires Windows NT 3.5 or later.
  Windows 95/98: Requires Windows 95 or later. Available as a redistributable for Windows 95.
  Header: Declared in Gl.h.
  Library: Use Opengl32.lib.

See Also

glBegin, glDepthRange


  

Community Additions

Show:
© 2015 Microsoft