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)
About viewport transform
Started by tigerlc, Mar 10 2006 06:51 PM
2 replies to this topic
#1
Posted 10 March 2006 - 06:51 PM
#2
Posted 10 March 2006 - 10: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.
reedbeta.com - developer blog, OpenGL demos, and other projects
#3
Posted 13 March 2006 - 08:09 PM
Thanks. Now I understand better.
Reedbeta said:
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.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users











