# Thread: Tex Coord for Middle of a Texture Rectangle

1. ## Tex Coord for Middle of a Texture Rectangle

If I have a 256x256 GL_Texture_Rectangle_NV

Is the middle at 127.5, 127.5 or 128, 128

I think the coords run from 0 - 256.0 which would make the exact center 128,128

The center of the first pixel would be 0.5, 0.5 and the center of the last 255.5, 255.5

Is this correct ?

2. ## Re: Tex Coord for Middle of a Texture Rectangle

The first half of your texture coordinates is 0,1,2,...,127 and the second half of your texture coordinates is 128,129,130,...,255 (there is no pixel 256, 0-255 is 256 pixels)

So the exact middle of your texture would be 127.5 If I'm not mistaken, texture rectanges want integers for texture coordinates, so whether you round up or down is up to you, if you pass 127.5 in, I'm going to assume the driver will round down. My question is, is there something wrong with GL_TEXTURE_2D?

Dan

3. ## Re: Tex Coord for Middle of a Texture Rectangle

If there is an even number of pixels how can the middle of the texture be in the middle of a pixel?

Even if the 255th pixel is the 255th, it is still one pixel wide, making 256 pixels.

The middle is obviously exactly between the 128th and 129th pixels. If we restrict ourselves to integers then is no middle pixel.

If we are using floating point then it is just .5, which would map to the left edge of the 129th pixel or the right edge of the 128th pixel.

I am not up enough on the opengl spec to know off the top of my head what .5 maps to if you are using NEAREST filtering.

[This message has been edited by Nakoruru (edited 09-27-2002).]

4. ## Re: Tex Coord for Middle of a Texture Rectangle

Dan,

I think you're wrong.

If we assume wrapping for a moment (as a thought experiment) then 0.0 is the "same" position as 256.0; both locations lie between the first and the last pixel. Thus, 128.0 would like exactly between two halves of the texture, where each half contains 128 pixels.

This is easier to think about if you think of pixels as squares separated by a grid. The grid lines are numbered with whole integers, and the center of each square (pixel) is between two integers, and thus should correspond to a .5 coordinate.

5. ## Re: Tex Coord for Middle of a Texture Rectangle

Right. The exact center of a 1x1 texture rectangle is (0.5, 0.5). The exact center of a 2x2 texture rectangle is (1,1). The exact center of a 256x256 texture rectangle is (128,128).

In general it's (w/2.0, h/2.0).

Thanks -
Cass

6. ## Re: Tex Coord for Middle of a Texture Rectangle

Ok, I think I know where my train of thought got derailed. I thought that the texture coordinate was for the actual pixel (I guess meaning the center of the pixel), but it's actually the boundary edges of the pixels, right? not the inside of the pixel.

Dan

7. ## Re: Tex Coord for Middle of a Texture Rectangle

Texels values *are* at the center of the texel.

8. ## Re: Tex Coord for Middle of a Texture Rectangle

There is no middle to a 256x256 sized image, or any even numbered size image for that matter. You're either on one side or the other.

So, does OpenGL round up or down? If you feed in 0.5f, does it map to 127 or 128 of a 256x256 size texture, assuming the range is 0 to 255?

[This message has been edited by WhatEver (edited 09-29-2002).]

9. ## Re: Tex Coord for Middle of a Texture Rectangle

Never mind, I just saw your post cass. It rounds up accoording to you.

10. ## Re: Tex Coord for Middle of a Texture Rectangle

x = u * width - 1
y = v * width - 1

So with a 256x256 image you get this:

x = 127 = 0.5f * 256 - 1
y = 127 = 0.5f * 256 - 1

That means it naturally rounds to 127, and not 128. Interesting. So 0.5f maps to the lesser side.

Don't mind me, I'm just bored .

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•