Sign in to follow this  

Saving images to file in SDL help needed

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

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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

This topic is 3724 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this