#148586 - iainprice - Mon Jan 07, 2008 6:44 pm
If I have a square face, and a square texture, I know I can fit the texture to the face.....
Is there a way of repeating the texture? So that I have 4 or 16 copies of the texture on the face?
Cheers.
#148587 - Lick - Mon Jan 07, 2008 6:49 pm
Set the U and V values higher than 1.0.
_________________
http://licklick.wordpress.com
#148591 - nipil - Mon Jan 07, 2008 7:31 pm
Just to precise, UV greater (or lower) than one will put multiple (or partial )times the texture along the given axe.
Let's say your texture looks like this :
Code: |
0,0 U 1,0
+------------+
|111111222222|
|111111222222|
V|111111222222|
|333333444444|
|333333444444|
|333333444444|
+------------+
0,1 1,1 |
Let's say you have a square quad with top left (u=v=0) bottom right (u=2.5, v = 5). The quad would look like this :
Code: |
0,0 U 2.5,0
+----------+
|1122112211|
|1122112211|
V|1122112211|
|1122112211|
|1122112211|
|1122112211|
+----------+
0,0.5 2.5,0.5 |
So basically, you have 2+1/2 texture horizontally and 1/2 texture vertically :
=> UV > 1 equals repeating
=> UV < 1 equals partial texture.
This is very useful, for example on long polygons (walls anyone ?). For example if your wall is let's say 10 meters long and 2 m high, and you have a texture of a single brick of "size" 0.2m x 0.1m, you draw a single polygon :
Code: |
(0 , 0) U (0 , 10/0.2)
. .
0,2 X 10,2
+-------------------------------+
| |
| |
V Y| |
| |
| |
+-------------------------------+
0,0 10,0
. .
(0 , 2/0.1) (2/0.1 , 10/0.2) |
Which will, in only 1 instruction, draw the wall and "fill" it with 50 bricks horizontally and 20 bricks vertically.
This is far better than drawing 50x20 quads and map the texture each time, for the same quality (or better) and far less computing.
Me think you can even have negative UV (on a PC at least) to "mirror/flip" the texture. It's been a while i haven't used OpenGL so i'm not all that sure about the negative UV. Just try ;)
#148596 - simonjhall - Mon Jan 07, 2008 7:51 pm
Don't forget to turn texture wrapping on though.
http://nocash.emubase.de/gbatek.htm#ds3dtextureattributes
Teh bits 16 and 17, y'all. Or GL_TEXTURE_WRAP_S and GL_TEXTURE_WRAP_T for those who use libnds...
_________________
Big thanks to everyone who donated for Quake2
#148620 - iainprice - Mon Jan 07, 2008 11:17 pm
I follow the idea but am having trouble in code:
GFX_TEX_COORD = TEXTURE_PACK(inttot16(32),inttot16(32));
glVertex3v16(LEFTZ BOT, 0);
GFX_TEX_COORD = TEXTURE_PACK(inttot16(32),inttot16(64));
glVertex3v16(RIGHT, BOT, 0);
GFX_TEX_COORD = TEXTURE_PACK(0,inttot16(64));
glVertex3v16(RIGHT, TOP, 0);
GFX_TEX_COORD = TEXTURE_PACK(0,inttot16(32));
glVertex3v16(LEFT, TOP, 0);
This draws a quad. It uses:
0 0 0 0
0 0 0 0
1 1 0 0
1 1 0 0
part of a 64x64 texture... I want this texture 4 times on the quad.....
#148628 - M3d10n - Tue Jan 08, 2008 12:58 am
Texture coordinates on the DS uses texels, not ratios. So, if you have a 64x64 texture and want to display it entirely (without repeating), use the following values (using inttot16):
Code: |
(0,0)---------(0,64)
| |
| |
| |
| |
| |
| |
(0,64)--------(64,64) |
If you want it to repeat 2x on each axis, just double the value. You can also use a texture matrix to scale your coordinates (actually, this allows you to get more tiles without overflowing the 16-bit texture coordinates):
Code: |
glMatrixMode(GL_TEXTURE);
glLoadIdentity();
glScalef32(inttof32(2));
//DRAW YOUR QUAD HERE! |
#148671 - iainprice - Tue Jan 08, 2008 6:52 pm
Hmmm nearly works.....
I have a 64x64 texture but only want to use a 32x32 bit of it..... if I use the following code:
[code]
glMatrixMode(GL_TEXTURE);
glLoadIdentity();
glScalef32(inttof32(4));
GFX_TEX_COORD = TEXTURE_PACK(inttot16(32),inttot16(32));
glVertex3v16(LEFTZ, BOTX, 0);
GFX_TEX_COORD = TEXTURE_PACK(inttot16(32),inttot16(64));
glVertex3v16(RIGHTZ, BOTX, 0);
GFX_TEX_COORD = TEXTURE_PACK(0,inttot16(64));
glVertex3v16(RIGHTZ, TOPX, 0);
GFX_TEX_COORD = TEXTURE_PACK(0,inttot16(32));
glVertex3v16(LEFTZ, TOPX, 0);
[/code]
it displays all 64x64.... :(
yes it does shrink and repeat the texture but all of it.
#148686 - M3d10n - Tue Jan 08, 2008 10:35 pm
Ah, I understand now. What you want to do isn't supported by the hardware: you can't tile only part of a texture. You'll have to either cut your texture or use several quads for each tile.
Even on PC GPUs, you have to jump a few hoops to do this (using shaders).
#148690 - iainprice - Tue Jan 08, 2008 11:06 pm
poo
Thanks for the help......
#148708 - Rajveer - Wed Jan 09, 2008 3:43 am
What I do is store textures I want to repeat separately, which is what you kinda have to do.
#148720 - melw - Wed Jan 09, 2008 10:17 am
Just create a new 32x32 texture for tiling that one corner of a 64x64 texture. It's not like the DS doesn't have any VRAM at all. :) Other solution is to draw the amount of "tiles" you want in quads*quads and set texture coordinates accordingly for each quad. This might just make sense if you're out of texture memory but loose on the polygon budget...