PDA

View Full Version : About viewport transform


tigerlc
03-10-2006, 10:51 AM
Hi all,

I have a maybe ignorant question about viewport transform in openGL.

I saw in one paper talking about viewport transform,

for viewport setting

glViewPort(x0, y0, w, h);

He define the transform like

| w/2, 0, 0, w/2+x0 |
| 0, h/2, 0, h/2+y0 |
| 0, 0, 1, 0 |
| 0, 0, 0, 1 |


But to my understanding

it should be like

| (w-1)/2, 0, 0, (w-1)/2+x0 |
| 0, (h-1)/2, 0, (h-1)/2+y0 |
| 0, 0, 1, 0 |
| 0, 0, 0, 1 |


since we are mapping points

(-1.0, -1.0, z, 1) to (0, 0, z, 1)
( 1.0, -1.0, z, 1) to (w-1, 0, z, 1)
(-1.0, 1.0, z, 1) to (0, h-1, z, 1)
( 1.0, 1.0, z, 1) to (w-1, h-1, z, 1)

in pixel position on the screen (zero-indexed)

Am I right? Thanks for your any comments. (this is quite important to my current work and I want to confirm it)

Reedbeta
03-10-2006, 02:22 PM
Not quite. In OpenGL the pixel centers are considered to be at 0.5, 0.5, so the screen extends from (0, 0) at the bottom-left edge to (w, h) at the top-right edge. The pixel centers are then at (0.5, 0.5) ... (w - 0.5, h - 0.5), so there are exactly w*h pixels. The mapping given in the paper you read is correct. You can also consult the OpenGL specification if you want an authoritative reference.

tigerlc
03-13-2006, 12:09 PM
Thanks. Now I understand better.

Not quite. In OpenGL the pixel centers are considered to be at 0.5, 0.5, so the screen extends from (0, 0) at the bottom-left edge to (w, h) at the top-right edge. The pixel centers are then at (0.5, 0.5) ... (w - 0.5, h - 0.5), so there are exactly w*h pixels. The mapping given in the paper you read is correct. You can also consult the OpenGL specification if you want an authoritative reference.