<p>The viewport as specified by <code>glViewport</code> is just the rectangle in pixels on the screen that you wish to render to. Usually it's from (0,0) to (width, height) in pixels, but you could set it to a smaller region (or larger, for that matter) and it will basically scale the image as it's being rendered.</p>
<p>The &quot;affine transformation from normalized device coordinates&quot; business is saying that the GPU is going to remap from the abstract coordinates in which you define your scene, to the physical pixel coordinates on the actual image you're rendering (which in OpenGL is called window coordinates).</p>
<p>The coordinates of triangle vertices, after going through the projection matrix and so forth, end up in a normalized range from −1 to 1 representing your field of view. For example, x = −1 on the left edge of the camera frustum and x = 1 on the right edge of the frustum (no matter how big the actual field of view of the frustum is). To find which pixels the triangles actually cover on screen, those coordinates get linearly remapped from [−1, 1] to the range of the viewport rectangle in pixels. Technically that kind of mapping is called an &quot;affine transformation&quot;.</p>

CC BY-SA 4.0
2021-09-04T17:14:41.887Z
2021-09-04T17:14:41.887Z
Nathan Reed
<p>Can someone please explain to me what the <strong>Viewport</strong> is. I've read the OpenGL wiki and doc.gl but they give me a definition that I don't understand at all. The definition they gave me is &quot;glViewport specifies the affine transformation of x and y from normalized device coordinates to window coordinates. Let (xnd,ynd) be normalized device coordinates.&quot;. I don't understand what that means.</p>

CC BY-SA 4.0
2021-09-03T19:46:24.373Z
"Unfortunately, no one can be told what the Viewport is. You have to see it for yourself." On a serious note: http://www.songho.ca/opengl/gl_transform.html
lightxbulb
<opengl><c++>
What is the Viewport?
Nathan
# What is the Viewport?

(Asked by: username_0 on 2021-09-03)

Can someone please explain to me what the **Viewport** is. I've read the OpenGL wiki and doc.gl but they give me a definition that I don't understand at all. The definition they gave me is "glViewport specifies the affine transformation of x and y from normalized device coordinates to window coordinates. Let (xnd,ynd) be normalized device coordinates.". I don't understand what that means.

**Tags:** opengl, c++

> **Comments:**
> **username_1**: "Unfortunately, no one can be told what the Viewport is. You have to see it for yourself." On a serious note: http://www.songho.ca/opengl/gl_transform.html  

---

## 1 answers

### Answer by username_2 on 2021-09-04. Score: 4

The viewport as specified by `glViewport` is just the rectangle in pixels on the screen that you wish to render to. Usually it's from (0,0) to (width, height) in pixels, but you could set it to a smaller region (or larger, for that matter) and it will basically scale the image as it's being rendered.

The "affine transformation from normalized device coordinates" business is saying that the GPU is going to remap from the abstract coordinates in which you define your scene, to the physical pixel coordinates on the actual image you're rendering (which in OpenGL is called window coordinates).

The coordinates of triangle vertices, after going through the projection matrix and so forth, end up in a normalized range from −1 to 1 representing your field of view. For example, x = −1 on the left edge of the camera frustum and x = 1 on the right edge of the frustum (no matter how big the actual field of view of the frustum is). To find which pixels the triangles actually cover on screen, those coordinates get linearly remapped from [−1, 1] to the range of the viewport rectangle in pixels. Technically that kind of mapping is called an "affine transformation".


---

