Jump to content
  • Advertisement
Sign in to follow this  
LatchGameDev

SDL Question

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

This is my work around but it makes my program so slow


// I take the small square tile i want out of the tile_sheet and blit it onto temp_tile
apply_surface( 0, 0, tile_sheet, temp_tile, &clip);

// I save the SDL_Surface as tile.bmp
SDL_SaveBMP(temp_tile, "Graphics\\tile.bmp");

// Lastly I load the bmp into a different SDL_Surface called tile
tile = load_image("Graphics\\tile.bmp");


Like I said the above works but is so darn slow. Ideally what I'd like to do is set the clipped part of tilesheet into a seperate SDL_Surface and have it save like...


// I take the small square tile i want out of the tile_sheet and blit it onto temp_tile
apply_surface( 0, 0, tile_sheet, temp_tile, &clip);

tile = temp_tile;


Also the apply_surface function is from http://lazyfoo.net/S...son06/index.php

Share this post


Link to post
Share on other sites
Advertisement
If you just want to copy the surface you can use SDL_DisplayFormat (or SDL_DisplayFormatAlpha)
tile = SDL_DisplayFormat(temp_tile);

If you don't want to use temp_tile at all you could just create a new surface with the same format as tile_sheet and blit the part you want.
tile = SDL_CreateRGBSurface(tile_sheet->flags, clip.w, clip.h, tile_sheet->format->BitsPerPixel, tile_sheet->format->Rmask, tile_sheet->format->Gmask, tile_sheet->format->Bmask, tile_sheet->format->Amask);
apply_surface( 0, 0, tile_sheet, tile, &clip);


Copying/creating surfaces are slow so try to avoid doing it each frame update. If you only do it at loading/setup time it shouldn't be a problem.

Share this post


Link to post
Share on other sites
Thank you, Thank you, Thank you :D
I'm only copying surfaces when i'm loaded/reloading the map and it was taking 44 seconds to load my map before. I used your first suggestion and it reduced the time to less then a second! :D

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • 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!