Jump to content

  • Log In with Google      Sign In   
  • Create Account


SDL Question


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 LatchGameDev   Members   -  Reputation: 167

Like
0Likes
Like

Posted 12 April 2012 - 11:22 PM

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

Sponsor:

#2 Wooh   Members   -  Reputation: 611

Like
0Likes
Like

Posted 13 April 2012 - 06:12 AM

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.

#3 LatchGameDev   Members   -  Reputation: 167

Like
0Likes
Like

Posted 13 April 2012 - 10:27 AM

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




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS