1
votes

I have a question about computer graphics pipeline.

In OpenGL, we usually use glViewport function in reshape callback. I heard glViewport is related to viewport transformation.

In our vertex shader, we usually calculate our vertices and make these vertices to be defined in clipping coordinate(Normalized clipping cube).

When does viewport transformation work?

I guess if the vertex shader output the vertices information to rasterizer, then the pipeline translate these vertices information.

X(v) = (x + 1)/2 * width + left y(v) = (y + 1)/2 * height + bottom. (viewport transformation)

Consequently, I thought glViewport just set how to work viewport transformation after finishing vertex shader work.

Is it right?

1

1 Answers

1
votes

In OpenGL, we usually use glViewport function in reshape callback

No, "we" don't. glViewport belongs into the display function.

Consequently, I thought glViewport just set how to work viewport transformation after finishing vertex shader work.

Yes, that's how it works. Essentially the viewport is just another variable, not very different from a uniform, that contains parameters for the vertex transformation step. However since the last steps of the transformation, the homogenous divide and clipping are hardwired and the viewport transform happens after that, it has to be set individually.