Jump to content
  • Advertisement


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.

If you intended to correct an error in the post then please contact us.

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 this post

Link to post
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.

vertexnormal AT linuxmail DOT org

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

Share this post

Link to post
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)*floatTileWidth
t1 = (TileWanted/TileWidth)*floatTileWidth

s2 = (TileWanted%TileWidth)*floatTileWidth
t2 = ((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]

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

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!