# What are the exact right texture coordinates?

Hi, I have a very basic question, but I am breaking my head over it.

an example: I have a 4x4 2D texture, it uses linear interpolation. MY question is, how do i get closest to the original values that i have stored in the texture?

What coordinates do I use, the texture ranges from 0.0 to 1.0? in 1D case which of these 4 possibilities is the right array to use?

• (0.0),(0.25),(0.50),(0.75) or
• (0.25),(0.50),(0.75),(1.0) or
• (0.125),(0.375),(0.625),(0.875) or
• (0.0),(0.333),(0.667),(1.0)

yes, i am aware of the fact that u can use NEAREST, but I need to use linear and i want to know where in the texture the exact value is located. Please enlighten me

``````|--x--|--x--|--x--|--x--|
0                       1
``````

| are texel boundaries, x texel centers where the texel color is defined, and the number below are the texture cooridnates; 0 to the left and 1 to the right.

To to sample exactly where the texel color is defined, you sample at (0.1250, 0.3750, 0.6250, 0.8750). In general, for a texture with N texels (along a specific dimension), the n:th texel (counting from zero) is located at (n+0.5)/N.

Also, keep in mind that these are not the texture coorinates you should use for, say, a screen aligned quad to get a 1 to 1 mapping of screen- and vertex coordinates and texels to perfectly render an image for example.

Originally posted by Bob:
[b]

Also, keep in mind that these are not the texture coorinates you should use for, say, a screen aligned quad to get a 1 to 1 mapping of screen- and vertex coordinates and texels to perfectly render an image for example. [/b]

I will also render a screen aligned quad with NEAREST, what coordinates should I use then?

(0.125),(0.375),(0.625),(0.875)

Why ?

``````0-------1
|.|.|.|.|
``````

. is a texel
| is the edge between two texels.

EDIT: ok, I am slower than everybody else

It’s depend of the Clamping mode. for Clamp to Edge it’s:

``````x--|--x--|--x--|--x
0                 1
``````

Originally posted by oc2k1:
[b] It’s depend of the Clamping mode. for Clamp to Edge it’s:

``````x--|--x--|--x--|--x
0                 1
``````

[/b]
No, the coordinates needed to hit the defined colors are still the same. Clamp to edge makes the coordinate clamp to the range [0.125, 0.875] instead of [0, 1]. Whatever clamping mode, 0.125 is the coordinate needed to hit the center of the first texel.