glTextCoordPointer with anything but GL_FLOAT

I notice you can use GL_UNSIGNED_SHORT instead of GL_FLOAT in glTexCoordPointer.
Does this mean that if I know my texture width and height ahead of time, rather than putting in 0.5, 0.5, for UV coordinates, I can instead put the actual pixel offset like 256, 256 for a 512*512 texture?

This would save a lot of room considering a float is 4 bytes, and I could get away with 2 bytes each (or even 1 byte each if the texture width and height was 256 pixels.)

I tried it and it didn’t seem to work. I was just wondering if it was something I did, or if it is not possible.

Ultimately, I would love to have a single array of texture vertices, and be able to index them with an array like you can with regular vertices.

Actually, from what I understand, the way unsigned short works is that 0-65535 is equivalent to the range 0 to 1 in floats. So, if your texture coordinate in floats was 0.5, then your new one should be 32767. Basically, multiply your texture coordinates by 65535 and round to the nearest ushort. This makes texture wrapping rather difficult.

Great! Thank you. I’ll try that.

So, an unsigned byte would be 0-255. Pretty damn nice if your textures is exactly 256*256. Works out to be straight coordinates. =)

Um, I guess. It’s not good if you wanted the texture coordinate to hit the center of a pixel. This comes up on occasion, mostly with sprites.

I’d suggest, from a performance vs. quality standpoint, to stick with floats unless you start hitting vertex transfer bandwidth bottlenecks. Then, switch to VAR, display lists, or whatever else can enhance vertex transfer before dropping to unsigned shorts or lower.

Actually, you would expect it to work the way Korval describes, but from my own experience it doesn’t appear it works that way.

From my testing it appears that using integers 0-1 still maps into the equivalent float range 0-1. I’m not quite sure why it works this way. You wouldn’t think that it would. I just tested again and came up with the same results. I’m using the latest official Detonator drivers from nVidia.

So my question then is, how are you supposed to get fractional values using an int or short? It still works to do repeating textures if you don’t need fractional texcoords anywhere, but I’d stick with floats for most cases.

Yeah, I tried it again as well. Didn’t work for me either.

Someone must have tried this before, or knows how to make it work.

Maybe it takes shorter versions of floats?? Is there such thing as a 2 byte or 1 byte float?

Whenever you’re unsure of the correct behavior, consult the spec.
http://trant.sgi.com/opengl/docs/Specs/glspec1.1/node20.html#SECTION00570000000000000000

This section talks about how some quantities are range mapped to float, but others aren’t. Texture coordinates don’t appear to be. My suggestion would be to use the texture matrix if you need to remap the range.

Thanks -
Cass

Thanks cass.

I had actually checked the specs after noting that behavior but I guess I was explicitly looking for something that said if it was or wasn’t clamped to a specific range, not the absence of it saying that it was.

When you think about it from one perspective, it doesn’t make much sense for it to get clamped, actually. If you were using a short for example and it got clamped between 0 and the max value of a short, there would be no real way to specify repeating coordinates other than to use the texture matrix. As it is there is no good way to do fractional coordinates without using the texture matrix, so I guess either way there is a tradeoff.

Oh well… I still prefer to use floats for all my texcoords. It was just an interesting behavior that I noted at one time.

Sorry guys. I checked the specs but couldn’t make heads or tails from them. Heh heh. I am still kinda new to all this, and all I am looking for is an example or explanation on what the array data needs to look like when using GL_SHORT or GL_BYTE.

So is the short a smaller version of a float?

I just want to be able to use something smaller than a float to specify my texture coordinates. My object files are huge, and I really need to shrink them down some.

I am using non-repeating textures, so it wouldn’t have even concerned me if they were clamped. =)

Anyone have any code to show how to do this?

Using the texture matrix as cass suggestion you should be able to do this…

glMatrixMode(GL_TEXTURE);
glScalef(width, height, 1.0);

glMatrixMode(GL_MODELVIEW);

Where width and height are the size of your image. That should, let you specify texture coordinates based on the actual image coordinates, though I haven’t tested it myself.

Originally posted by Deiussum:
[b]Using the texture matrix as cass suggestion you should be able to do this…

glMatrixMode(GL_TEXTURE);
glScalef(width, height, 1.0);

glMatrixMode(GL_MODELVIEW);

Where width and height are the size of your image. That should, let you specify texture coordinates based on the actual image coordinates, though I haven’t tested it myself. [/b]

You might consider using
glScalef(1./width,1/height,1.0), should actually work a little better

Chris

Originally posted by DaViper:
[b] You might consider using
glScalef(1./width,1/height,1.0), should actually work a little better

Chris[/b]

Oops. Yeah, that would probably give a bit better result.

Hmmm. I am trying the suggested way, but it doesn’t seem to be working.

When the object first comes up, I see the texture as being color noise, then the texture is gone, and I am left with just a white texture.

Has anyone actually tried this and gotten it to work? I would love to see some code that works. =)

  1. The texture matrix is your friend.

  2. 0.0 to 1.0 does not map to the leftmost pixel and the rightmost pixel. They both map to the edge between the leftmost pixel and the rightmost pixel (assuming repeat here). For pixel-to-pixel correctness, you want the leftmost pixel at (0.0+(1.0/texWidth)/2) and the rightmost pixel at (1.0-(1.0/texWidth)/2). That is, at the nearest mipmap level; once you start mip mapping out you will need to move progressively further in from the texture edge. It’s a royal pain (especially for whomever makes the art).

GL_CLAMP
GL_REPEAT
GL_CLAMP_TO_EDGE_EXT

at least one of them would do what you want, automatically…