View Full Version : Texture question..

30-01-2005, 11:36 PM
Hi all,

I have a strange question,
Is there a way to tile a section of texture?

To better explain, its for my GUI, all the controls are contained in a single texture as you do.
How ever i want to be able to tile the forms background image, which for example could be at position X:20,Y:80 in the texture and X:50,Y:50 in size, but if i had a window with a background canvas of say X:30,Y:80 i want to tile the background image and not stretch it in any way..

Is this possible?

I had a try using scale but of course this scaled the texture coords too...

31-01-2005, 02:06 AM
The answer is in the UV coordinates.

Using your example, if the background texture fit perfectly in a 50x50 window, but then you wanted that same background tiled/cropped to fit a 30x80 window, use this equation to work out the required UV coordinates.


So, in your case, you would need UV coordinates of (0,0) for the top left corner and (30/50,80/50) or (0.6,1.6) for the bottom right corner.

Note that this only works if the texture contains only the background, but re-reading your message I see that the window background is contained within a texture that has other elements on it. Ok, we use a similar principle, but draw multiple quads.

Break the destination window size into quads of the texture size or less. This means that you will one quad of 30x50 and another quad of 30x30 that fits below it. Draw the first quad using UV coordinates of (0.0,0.0)-(0.6,1.0) and then draw the second quad immediately below the first with UV coordinates of (0.0,0.0)-(0.6,0.6).

This will give you a tiled background using a section of a texture.

I hope I've explained that good enough.