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)
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)