Public Group

#### Archived

This topic is now archived and is closed to further replies.

# splitting up a texture

This topic is 5534 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi! I''m making a tile-based game, and I want to know how I easiest split up a texture (the tileset) into small chunks (tiles, 32x32). I''ve come up with one idea, but it''s kinda weird; mapping the whole tileset to each tile when drawing, but with S and T values deppending on where the tile''s position in the tileset is. PS: I''m using OpenGL.

##### Share on other sites
That''s actually not as wierd an idea as you might think. I''ve used that method for all sorts of things, from bitmapped fonts to sprites and tiles.

Josh
vertexnormal AT linuxmail DOT org

Check out Golem: Lands of Shadow, an isometrically rendered hack-and-slash inspired equally by Nethack and Diablo.

##### Share on other sites
Thats how I do it, say you have a texture that is a power of two (64x64,128x128,256x256,etc) and it is made up of 32x32 tile images, taking into consideration that s and t can only have values between 0.0f and 1.0f, you need to do quite some work.

First you need to find out how many tiles are inside your texture, for this you need to find how many tiles wide the texture is, and then raise it to the power of 2 so:
TileWidth = ImageWidth/32;TolalTileCount = TileWidth^2;

Now you need to scale the value of TileWidth to a 0.0f to 1.0f range and find out the Texel lenght:
floatTileWidth = float(1.0f/TileWidth);floatTexelLenght = float(1.0/ImageWidth);

Now that you have that, how do you find the 4 values that make the tile?
s1 = (TileWanted%TileWidth)*floatTileWidtht1 = (TileWanted/TileWidth)*floatTileWidths2 = (TileWanted%TileWidth)*floatTileWidtht2 = ((TileWanted/TileWidth)*floatTileWidth)+(floatTileWidth-floatTexelLenght)s3 = ((TileWanted%TileWidth)*floatTileWidth)+(floatTileWidth-floatTexelLenght)t3 = ((TileWanted/TileWidth)*floatTileWidth)+(floatTileWidth-floatTexelLenght)s4 = ((TileWanted%TileWidth)*floatTileWidth)+(floatTileWidth-floatTexelLenght)t4 = (TileWanted/TileWidth)*floatTileWidth

You MUST check that TileWanted is NOT greater than TotalTiles and you have to substract TexelWidth so the tile doesnt take the next tile's first line.

I dont have my code here, so ALL that is from memory, should get you started tho.
Oh yeah! and TileWanted first posible value is of course 0, not 1.

Proud aedGUI developer.

[edited by - Kwizatz on October 22, 2003 1:50:20 PM]

1. 1
2. 2
Rutin
20
3. 3
4. 4
A4L
15
5. 5
khawk
14

• 13
• 26
• 10
• 11
• 9
• ### Forum Statistics

• Total Topics
633737
• Total Posts
3013614
×

## Important Information

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!