Jump to content

  • Log In with Google      Sign In   
  • Create Account


#ActualHodgman

Posted 22 October 2012 - 07:16 AM

The way texcoords work is that 0 is the left/top edge of your image, and 1 is the bottom/right edge, which is very abstract and disconnected from the notion of pixels.
If you're thinking in integer coordinates for an array of 1024 pixels, then 0 is the index of the leftmost pixel and 1023 is the index of the rightmost pixel.

To reconcile the two, we can imagine a grid of 1024 squares scaled down to be 1 unit wide total. Each cell would then be 1/1024 units wide. The offset from the edge of a squares to it's centre would be 0.5/1024 units. We can pretend that these squares are pixels, even though that's not technically true (pixels are just points in 2d space with no pre-defined shape or size -- the filtering mode used gives them shape, e.g. nearest/point filtering makes them appear as squares).
So to convert from an integer pixel index to a texture coordinate at the very centre of that pixel, you can use (pixel index + 0.5) / pixel count.

So, yes, 1023.5/1024 is the exact centre of the rightmost pixel.
If clamp mode is used, then 1.0 is the right hand edge of the rightmost pixel. If wrap mode is used, then 1.0/0.0 are the same -- on the edge between the first and last pixels.

#1Hodgman

Posted 22 October 2012 - 07:13 AM

The way texcoords work is that 0 is the left/top of your image, and 1 is the bottom/right.
If you're thinking in integer pixel coordinates (for a 1024 wide image), then 0 is the index of the leftmost pixel and 1023 is the index of the rightmost pixel.

To reconcile the two, we can imagine a grid of 1024 squares scaled down to be 1 unit wide total. Each cell would then be 1/1024 units wide. The offset from the edge of a cell to it's centre would be 0.5/1024 units.
So to convert from an integer pixel index to a texture coordinate at the very centre of that pixel, you can use (pixel index + 0.5) / pixel count.

So, yes, 1023.5/1024 is the exact centre of the rightmost pixel.
If clamp mode is used, then 1.0 is the right hand edge of the rightmost pixel. If wrap mode is used, then 1.0/0.0 are the same -- on the edge between the first and last pixels.

PARTNERS