Reputation: 10067
Is it possible to get pixel-perfect precision with glTexCoord2f() somehow? For example, let's assume that I have bound a 512x512 texture to the OpenGL context and now I want to draw an arbitrary area from inside that texture as a quad. Let's also assume that the area I want to draw uses really odd offsets and dimensions that are not a multiple of the texture's size. For instance:
Texture size: 512x512
Area inside the texture that I want to draw: X=131 Y=159 Width=243 Height=33
The problem is that glTexCoord2f() expects values in the range from 0 to 1 so I'd have to do some floating point arithmetic to convert the pixel values into a float value that ranges from 0 to 1 and I'm afraid that pixel-perfect precision might get lost in the course of that integer to float conversion. I know that this conversion won't be a problem if you stick to texture size multiples, i.e. sprite sheets with items sized 16x16, 32x32, 64x64 or something like that but what about addressing really arbitrary offsets within the texture? Is pixel-perfection possible here at all?
Upvotes: 2
Views: 182
Reputation: 7397
This is not a solution, just a workaround that has been used for ages:
Usually sprites within atlases are padded with 1px transparent border, so that floating-point errors are unnoticeable.
We had used 1024x1024 atlas with 32x32 tiles and even then we had edge errors at some specific camera offsets.
Upvotes: 0