Using allegro I can create a Bitmap to draw just doing:

bmp = create_bitmap(width,height); // I don't remember exactly the parameters

I'm using SDL now, and i want create an SDL_Surface to draw the game level (that is static). I create an SDL_Surface, draw the tiles on it, then just blit this surface to the screen instead of drawing the tiles directly on screen (I believe this will require more processing);

Is there a way to create a blank SDL_Surface as I did with Allegro to draw before I blit it?

  • 1
    \$\begingroup\$ If you care about searching on the sdl documentation, yes, there are. \$\endgroup\$ – Gustavo Maciel Mar 18 '12 at 17:25
  • \$\begingroup\$ Also, I'd check Lazy Foo', as he does a lot of really good stuff regarding SDL, including Surface stuff. \$\endgroup\$ – thePalindrome Mar 19 '12 at 4:51

You are looking for this function:

SDL_Surface* SDL_CreateRGBSurface(Uint32 flags, int width, int height, int bitsPerPixel,
             Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask);

Check the docs to see what to pass as each argument.


Normally you set up an

SDL_Surface * screen;

which is a pointer to a spot of memory that stores pixel information for a given resolution and color depth. You create one as a screen initially and manage it with a SetVideoMode function. You can then blit all of your images onto screen and flip the buffers at the end of your main loop.

You may also want to look into SDL_Image to make loading and working with various image files easier. Also as someone else mentioned, I highly recommend Lazy Foo's Tutorials. There is information on his site about setting up and using SDL_Image.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.