PDA

View Full Version : Texture Wrapping

G4Soon
09-14-2001, 06:39 PM
I have made a simple 2d sidescrolling game, but the way I am rendering the tri strips on the terrain requires the texture to be repeated several hundred times horizontally and vertically. I don't know how to get textures to do that... I know the answer should be simple with OpenGL, so any help at all will be beneficial.

V--man
09-15-2001, 02:55 AM
You just need to give the correct tex cordinates, for example:

glTexCoord2f(0.0, 0.0); glvertex();
glTexCoord2f(0.01, 0.0); glvertex();
glTexCoord2f(0.01, 0.01); glvertex();
glTexCoord2f(0.0, 0.01); glvertex();
glEnd();

that will repeat it 100 times on that quad and all I did was use 1/100=0.01

V-man

V--man
09-15-2001, 02:58 AM
Woops! that's the inverse. use replace all the 0.01 by 100.0

There are other ways too, like using the texture matrix, but I would just give the tex coord straight for a static texture.

V-man

G4Soon
09-15-2001, 07:26 AM
Well, I'm not THAT stupid. The thing is that any texture coordinate above 1 gets clipped back to 1 automatically, so in the example you gave, this is what it would look like:

texture:

1 0 1 0
0 1 0 1
1 0 1 0
0 1 0 1

repeat it 2 times on a quad:

1 0 1 0 0 0 0 0
1 0 1 0 0 0 0 0
1 0 1 0 0 0 0 0
1 0 1 0 0 0 0 0
1 0 1 0 0 0 0 0
0 1 0 1 1 1 1 1
1 0 1 0 0 0 0 0
0 1 0 1 1 1 1 1

this example has it set up as it is in my program, with (0,0) on the bottom left and (2,2) on the top right.

Any ideas?

Michael Steinberg
09-15-2001, 08:00 AM
Set the texture to GL_REPEAT mode in s and t!
Then, giving a 1.5 will be matched to a 0.5, same 2.5 and 3.5 and and and...

G4Soon
09-15-2001, 09:32 AM
actually, I figured it out just before I got that message.

for other beginners wondering how to do this, the specific function calls are:

glBindTexture GL_TEXTURE_2D,TextureID
glTexParameteri GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_REPEAT
glTexParameteri GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_REPEAT

thanks!