glTexCoord2i values?

I know how glTexCoord2f works - (0.0, 0.0) is at center of texture image and coords must fall between -1.0 and 1.0. However, what is the frame of reference of glTexCoord2i values? Obviously glTexCoord2i is fundamentally different from glTexCoord2f in its frame of reference. If I specify glTexCoord2i(0,0) what am I referring to - the bottom-left, top-left, or center of texure image?? If my texture image is 64x64, can I specify texture coord values greater than 63 or less than 0?

Correction to my post above. The sentence “glTexCoord2f - (0.0, 0.0) is at center of texture image and coords must fall between -1.0 and 1.0” should read:
I know how glTexCoord2f works - (0.0, 0.0) is at bottom-left of texture image and coords must fall between 0.0 and 1.0.

I think that the integer version behaves exactly like the float. Larger values then 1 is used to make the texture repeat.

you can use texture matrix to scale integer coordinates.

Originally posted by nvidia_linux:
I think that the integer version behaves exactly like the float. Larger values then 1 is used to make the texture repeat.

Sorry, I still dont understand. Max values for GlTextCoord2f values are 1.0. But how can you have a integer value less than 1 if you’re using GlTexCoord2i? If texture image is 64x64 then to reference element (32,32)in GlTexCoord2f i would use GlTexCoord2f(0.5f,0.5f). How would I reference that same texture pixel in glTextCoord2i?? glTexCoord(5,5)? That doesn’t make sense!

nvidia_linux is right, The integer version behaves just like the float version with the range between 0 and 1. Didn’t make sense to me at first either until you consider repeating textures. If you want to use actual texture coordinates, you can use the texture matrix like so…

glMatrixMode(GL_TEXTURE);
glScalef(1.0/64.0, 1.0/64.0, 1.0);

Now if you want to use glTexCoord2i(32.0, 32.0) it will equate to glTexCoord2f(0.5, 0.5);

Originally posted by Deiussum:
[b] If you want to use actual texture coordinates, you can use the texture matrix like so…

glMatrixMode(GL_TEXTURE);
glScalef(1.0/64.0, 1.0/64.0, 1.0);

Now if you want to use glTexCoord2i(32.0, 32.0) it will equate to glTexCoord2f(0.5, 0.5);[/b]

Ahhh, now I understand. Many thanks!

[b]>>Max values for GlTextCoord2f values are 1.0

>>… and coords must fall between 0.0 and 1.0.
[/b]

No, that’s wrong. You can pass any number you want to glTexCoord2f. If you pass 4.0, the texture will repeat four times, pass -5.0 and the texture will repeat five times “in the other direction”.

Originally posted by Deiussum:
[b]If you want to use actual texture coordinates, you can use the texture matrix like so…

glMatrixMode(GL_TEXTURE);
glScalef(1.0/64.0, 1.0/64.0, 1.0);

Now if you want to use glTexCoord2i(32.0, 32.0) it will equate to glTexCoord2f(0.5, 0.5);[/b]

Fyi, I tried this and it DOES NOT (!!) work. Example:
glMatrixMode(GL_TEXTURE);
glScalef(1.0/64.0, 1.0/64.0, 1.0);
glBegin
glTextCoord2i(11, 30)
glVertex3i(x,y,z)

glEnd
produced NOTHING! However, when I did the math myself as in glTextCoord2f(0.171f, 0.468f) that worked ok. Nice try though!

When you say it produced nothing do you mean that there was no texture, or the poly itself disappeared? I should have mentioned that before you do a glTranslate/glRotate/glScale calls to manipulate your scene, you should switch back to the model-view matrix.

glMatrixMode(GL_MODELVIEW);

If you don’t do that and you, for instance, tried to move things further away a bit with a glTranslate, it would have been applied to the texture matrix instead.

I just tried using that method myself in a little test app I had done, and it worked fine for me.

Originally posted by Deiussum:
[b]When you say it produced nothing do you mean that there was no texture, or the poly itself disappeared? I should have mentioned that before you do a glTranslate/glRotate/glScale calls to manipulate your scene, you should switch back to the model-view matrix.
[b]

I put the

glMatrixMode(GL_TEXTURE);
glScalef(1.0/64.0, 1.0, 1.0/64.0);

right before the glBegin. Note that I want 2D texture scaled only in X-Z plane not Y. Doesn’t really matter though because it didn’t work either way. I’m getting the polys drawn in default color just fine but no texture when using glTexCoord2i with code above. However, when I do the arithmetic (i.e., divide by 64) and use those values in glTextCoord2f, texture displays ok. Btw, I put glMatrixMode(GL_MODELVIEW) right after glEnd, then tried also after glFlush. Still no textures. At this point I’m convinced that using glMatrixMode(GL_TEXTURE) with glTexCoord2i does NOT work!

RJH you are being quite rude. Deiussum is right on the mark. It is your implementation of glTexCoord2i that is flawed, not glTexCoord2i itself.

Try putting it in your initialization function instead. If you are putting it right before glBegin, it is going to get called every frame, therefore after the first frame it will be 1/64, next frame it will be 1/4096, third frame it would be 1/262144, etc… As you can see, it is going to diminish to nothing rather quickly. If you don’t understand why that is, I suggest reading up on how the matrices work in OpenGL a bit further.

Originally posted by DFrey:
RJH you are being quite rude. Deiussum is right on the mark.

My sincere apologies. I did not mean to be rude. I really do appreciate Deissum’s efforts in explaining this topic.

It’s ok. No offense taken. I understand how frustrating it can be when something doesn’t work like you expect. Usually it’s the simplest little thing that causes the problems, too.

I am following this thread very closely as I posted the same question a while back, and could not get it working using the texture matrix either.

If someone has written a small demo, and has it working, please please please put the source code on a web server, and give us a link to it. I am using HUGE HUGE polygon count models (Poser models), and I can make my object file format 75% smaller if I can get this to work. Specifying floats for each texture coordinate rather than true pixel coordinates is making a 10 frame walk animation a 6 meg file. Not good.

Since my textures on the models do not repeat, it only makes sense to specify true pixel coordinates and lose the extra bulk from floats.

=)

Originally posted by OpenGLRox:
I am using HUGE HUGE polygon count models (Poser models), and I can make my object file format 75% smaller if I can get this to work. Specifying floats for each texture coordinate rather than true pixel coordinates is making a 10 frame walk animation a 6 meg file. Not good.
=)

  1. Why would changing the texture co-ordinates make that much of a difference? You only need to have one copy of the uv coords. (unless of course you are purposfully animating the texture coords - but I doubt it).

  2. On The presumtion that you are using 10 models and inbetweening them, replace the ‘tweening’ with a skeletal animation system. Only one copy of the model is then needed. The only storage you then need is the rotations of say 10-30 joints. Much more pleasing.

  3. Dont worry about the size of the file so much, worry about whats going on in the code. If you believe that you need to change every thing to chars or shorts (I dont think you do - causes more headaches than it solves) to save on memory, then cast them when inputting to your code.

Rob, true true, but all knowledge is good knowledge. Any savings is good savings. I sure as heck don’t want to add to the bloatware out there, and thinking about savings in space and speed at an early point in a project is always good.

Yes, I have only 1 copy of the UV’s but that doesn’t mean I shouldn’t be looking for ways to improve on file space.

I play to have a LOT of animations in my game so obviously thinking about the impact on the game is an intelligent thing to do as well as looking at game speed.

Do you honestly think OpenGL is faster at parsing floats than it would be at whole numbers? =)

So, anyone got a sample running yet we can peruse? =))

Ok. Here you go. I just threw this together now. It creates a simple textured quad (actually broken into 4 quads so that you can see the “halfway” texcoords). Enjoy.
http://www.lycanth.com/OpenGL/Demos/IntTexCoords.zip

[This message has been edited by Deiussum (edited 06-29-2001).]

Nice. Thank you for the demo. =)

Do you know offhand if you can use true pixel coordinates in an index table with glDrawArrays etc?