PDA

View Full Version : glTexCoord2i values?

RJH
06-25-2001, 08:45 PM
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?

RJH
06-25-2001, 09:32 PM
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.

06-25-2001, 10:52 PM
I think that the integer version behaves exactly like the float. Larger values then 1 is used to make the texture repeat.

Serge K
06-26-2001, 01:00 AM
you can use texture matrix to scale integer coordinates.

RJH
06-26-2001, 05:12 AM
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!

Deiussum
06-26-2001, 05:35 AM
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);

RJH
06-26-2001, 07:19 AM
Originally posted by Deiussum:
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);

Ahhh, now I understand. Many thanks!

Bob
06-26-2001, 07:34 AM
>>Max values for GlTextCoord2f values are 1.0

>>... and coords must fall between 0.0 and 1.0.

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".

RJH
06-26-2001, 01:13 PM
Originally posted by Deiussum:
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);

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!

Deiussum
06-27-2001, 05:09 AM
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.

RJH
06-27-2001, 08:49 AM
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!

DFrey
06-27-2001, 09:26 AM
RJH you are being quite rude. Deiussum is right on the mark. It is your implementation of glTexCoord2i that is flawed, not glTexCoord2i itself.

Deiussum
06-27-2001, 10:00 AM
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.

RJH
06-27-2001, 01:10 PM
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.

Deiussum
06-28-2001, 04:51 AM
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.

OpenGLRox
06-28-2001, 08:47 AM
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.

=)

Rob The Bloke
06-28-2001, 02:50 PM
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.

OpenGLRox
06-28-2001, 07:56 PM
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? =))

Deiussum
06-29-2001, 06:45 AM
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).]

OpenGLRox
06-29-2001, 10:55 AM
Nice. Thank you for the demo. =)

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

Deiussum
06-29-2001, 11:31 AM
You should be able to. glTexCoordPointer accepts both GL_SHORT and GL_INT for the data type. You just have to make sure you follow all the normal rules of using texcoords with vertex arrays. (The index of the texcoord array is used for the vertex with the same in index in the vertex array, etc.)

RJH
06-30-2001, 06:54 AM
Originally posted by Deiussum:
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.

Deiussum:

am happy to report that I'm now able to use glTexCoordi in conjuction with glScalef and it's working perfectly. Problems I encountered were due to my copying (incorrectly) the texture image into my texture buffer from a larger bitmap. I'll spare you the gruesome details... Anyway, thanks for your kind help and patience. Lesson learned: Anyone wishing to master OpenGL must be prepared to face and conquer the Yawning Chasm of Despair before scaling the Heights of OpenGL Bliss and Enlightenment. <g>