TexCoords: Where do they EXACTLY point to?

Hi

I want to blur a texture, by putting it in all 4 texture-units, offsetting the texcoords a bit and then averaging the values.
Now, of course i want to blur as efficiently as possible, meaning to reduce the passes needed.
For this i want to use bilinear filtering. However, to be able to really take advantage of bilinear filtering, i have to calculate my texcoords very carefully.

Some ASCII art:


|T|T|T|
–X-X–
|T|T|T|
–X-X–
|T|T|T|

A “T” stands for a texel. An “X” is the intended position of the texture-coordinate.
If my texcoords point to those positions, than every texcoord samples from exactly 4 texels.

Now the question is: What location does a texcoord like (0|0) point to? Is it the center of a texel, or is it a border/corner where 4 texels meet? And does (0|0) point to the same position as (1|1), or is there a difference?

Let´s just take the case of a 3x3 texture. Which coordinates does “X” have in this case:


|T|T|T|

|T|T|T|
–X----
|T|T|T|

Is it (1/3 | 1/3) or is it (1/6 | 1/6) ? Or might this position even be (0 | 0) ?

Thanks in advance,
Jan.

i think, if you have GL_REPEAT, at least (and ordinary GL_CLAMP, too…?), your coords you want are

pixel.x = (int)x + .5*(1/width)
pixel.y = (int)y + .5*(1/height)

but i’m so tierd, i’m not sure about anything anymore

Could you just use the next level mipmap of the texture.

(0;0) will point to the bottom left corner of the texture, just at the edge to the texture border.
Note that this isn’t the sample position. Tex coords are interpolated over primitives, of course, and the texcoord that’s interpolated for the pixel center is the sample position.

Ie, if you render a single-pixel quad and want to cover it with a single texel from a 32x32 texture, this is what you should do:

glBegin(GL_QUADS);
glTexCoord2f(0.0f,0.0f);
glVertex2f(0.0f,0.0f);
glTexCoord2f(1.0f/32,0.0f);
glVertex2f(0.0f+one_pixel_in_x,0.0f);
glTexCoord2f(1.0f/32,1.0f/32);
glVertex2f(0.0f+one_pixel_in_x,0.0f+one_pixel_in_y);
glTexCoord2f(0.0f,1.0f/32);
glVertex2f(0.0f,0.0f+one_pixel_in_y);
glEnd();

PS: dave is wrong

[This message has been edited by zeckensack (edited 09-10-2003).]

1 Like

@heath: No, tried that, but the results are crappy.

@zeckensack: Thanks, that clears i up for me.

Jan.