Saving images to file in SDL help needed

Started by
0 comments, last by Kylotan 16 years, 6 months ago
Hey In brief : Made a random map generator : with a mini map in the corner of the screen. As the map generator is randomally generated , the minimap needs to be made each time the game is run : but then'll never change. Seemed better - to me - if , rather then cycling through the map structure , loading up all the bits for it - and then drawing them all to the screen each cycle , just to do it once when the program is first run , taking a screenshot of the minimap , and then just loading the minimap screenshot bitmap to the screen. I've got the code to save the image buffer to an external file ( basically - take a screenshot ) , but the screenshot : while it only has the minimap on it - comes out at the size of the full screen ( 1600 x 1200 ). SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 0, 128, 255)); ( LOAD AND DRAW MAP CODE ) minimap=screen; SDL_SaveBMP (minimap,"minimap.bmp"); Is there anyway I can set the minimap.bmp to be the size I want , rather then the size of the whole screen? I am rather new with SDL , and don't really know what I'm doing yet Many Thanks in Advance
Advertisement
There's no need to save it out and load it back in again. Just create it in memory in the first place.

'screen' is the screen. If you copy it, then you get the whole screen, that's that.

However, you rarely deal with SDL_Surfaces, you deal with pointers to them. So "minimap=screen" doesn't even copy the screen - it just makes 'minimap' point to the same place as the screen. Be sure to bear that in mind.

What you really need to do is this:
- create a new surface of the correct size, probably with SDL_CreateRGBSurface
- create the map by drawing to that surface, not to the screen
- then draw that surface to the screen each time you need it

This topic is closed to new replies.

Advertisement