2
votes

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?

1
ARB_texture_rectangle?genpfault
Seems like it could do the job. So there is no way without resorting to extensions?Andreas

1 Answers

0
votes

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.