PDA

View Full Version : Texture Map Coordinate (0.0 - 1.0) or (0 - short int)?



bmcclint
08-15-2001, 08:59 AM
Well this will seem like another really generic question but I can't seem to find the answer either way...

I have texture mapping working all and well. This is great but I had to convert all the models texture coordinates to a 0.0 - 1.0 float to get the texture applied.

glTexCoord2fv((GLfloat*)&gl_polygon[ipoly].mipvert[ivert]);
glVertex3fv((GLfloat*)&gl_vertex[gl_polygon[ipoly].vert[ivert]]);

I would like to use intereger texture coordinates, is it possible. glTexCoord2sv takes integers but only 0 and 1. OR...I'm doing something really wrong...

EXMAPLE...
Poly 1 has three verts and texture coords on a 256x256 texture.

tv1 = 128,0
tv2 = 0,255
tv3 = 255,255

I had to convert to

tv1 = 0.5,0.0
tv2 = 0.00,1,0
tv3 = 1.0,1.0

A work arond I have is...

glTexCoord2f((float)TexVert[Poly[Polygon].v[Vertex]].s/(float)Texture->x,(float)TexVert[Poly[Polygon].v[Vertex]].t/(float)Texture->y);

Any suggestions...

Thanks...

richardve
08-15-2001, 09:54 AM
Of course it's possible to use integer coordinates http://www.opengl.org/discussion_boards/ubb/smile.gif

You just have to use glTexCoord2i() instead of glTexCoord2f() http://www.opengl.org/discussion_boards/ubb/wink.gif

bmcclint
08-15-2001, 10:39 AM
This does work but only numbers 0 & 1 produce the texture. Top left 0,0 to bot right 1,1. I'm thinking maybe I am declaring the texture wrong...

0,0 to 2,2 produce the texture in one quater of the square with GL_LAMP, when GL_CLAMP is replaced with GL_REPEAT it then tiles.

Thoughts?



Originally posted by richardve:
Of course it's possible to use integer coordinates http://www.opengl.org/discussion_boards/ubb/smile.gif

You just have to use glTexCoord2i() instead of glTexCoord2f() http://www.opengl.org/discussion_boards/ubb/wink.gif

DFrey
08-15-2001, 10:59 AM
You need to use the texture matrix to scale the texture. Do a search on the board (beginners or advanced) it has been mentioned several times.

bmcclint
08-15-2001, 11:42 AM
This did the trick...

glMatrixMode(GL_TEXTURE);
glScalef(1.0/GL_Texture->x, 1.0/GL_Texture->y, 1.0);

Now...next question...I have this code where I initialize the texture. In a more compelex program I will be moving from texture to texture. Will this property need to be reset each time I move to a new texture or is the scaling set for each texture?

Not sure if that made sense, I hope you know where I'm going with this.

Thanks...



Originally posted by DFrey:
You need to use the texture matrix to scale the texture. Do a search on the board (beginners or advanced) it has been mentioned several times.

DFrey
08-15-2001, 11:45 AM
You would need to reset the texture matrix for any texture that used different scaling factors. The matrix is not part of the texture state, it is part of the rasterizer state.