Jump to content
  • Advertisement

Archived

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

Amnesiac

Rendering from a tile map quickly

This topic is 5572 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

So say I have a tile map, you know the drill: { 0,0,0,1,1,1,1,0,0,0,0,0,0,0,0, 0,0,0,1,0,0,1,0,0,0,0,0,0,0,0, 0,0,0,1,0,0,1,0,0,0,0,0,0,0,0, 0,0,0,1,1,1,1,0,0,0,0,0,0,0,0 }; or something like that and I wanna render it onto a square grid with 0''s being one texture and 1''s being another. Whats the best way to do this? Right now I just have a nested loop to go though each coordinate and I draw the appropriate texture at the appropriate space on the screen, but i''m told this isn''t the way to go speedwise.

Share this post


Link to post
Share on other sites
Advertisement
Fastest way would be to put both textures into one larger texture.

Set texture coordinate transform for tile 0, draw all tile 0s.
Set texture coordinate transform for tile 1, draw all tile 1s.

you could keep both textures seperate and
Load texture 0, draw all tile 0.
Load texture 1, draw all tile 1.

Also, drawing each tile individually will hurt. You could create a (or a series of) static vertex buffer(s) for a group of tiles. OR create a dynamic vertex buffer, build a list of vertices needed this frame in system mem, do a memcpy of it all at once (AGP is optmized for large transfers) to the buffer.

Actually, thinking of it, I''d put the textures in a single texture, and while building a dynamic buffer set the UVs to the appropriate values for that tile, and forget the texture transforms altogether.

Share this post


Link to post
Share on other sites
The way I do it is with separate textures. I build up my vertex buffer with a screenful of tiles. Then each render, I go through the current tiles (IE, position read from the texture identifying map) and build an index list. Then I set texture 1, render indices for texture 1, set texture 2, render, etc.

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!