Sign in to follow this  
Pogo708

Blitting to a surface, then blitting that surface to screen....

Recommended Posts

Pogo708    138
Ok, so right now, I use a for loop to draw each 16x16 tile on the screen. What I want to do, is when I load the map in, blit the tiles to a surface, then just blit the portion of that surface thats visible to the player to screen, so that it's only one blit command instead of a few hundred. Can someone help me with this?

Share this post


Link to post
Share on other sites
PnP Bios    494
Its prety easy, but it can take some work to do. What you can do is create a staging surface to blit everything to, then blit that onto the screen.

I have a tutorial on surface creation you might want to look at.

cheers. good luck!

Share this post


Link to post
Share on other sites
The Rug    628
You might want to look over this thread, to make sure you avoid those pitfalls.

Source Surface/s to Intermediate Surface to Screen is a pretty trivial thing to do. If you need to know about setting up a surface, to use as the intermidiate surface, check out PnPs tutorial. Then, its as easy as this:


// set up intermediate surface
SDL_Surface * intermediate = SDL_CreateRGBSurface(SDL_SWSURFACE, 800, 600, 32, 0xff0000, 0xff00, 0xff, 0xff000000);

// loop through your tiles and draw to intermediate surface...
SDL_BlitSurface(someTile, NULL, intermediate, tilePosition);
// ...end loop

// ...later on
// Draw your intermediate surface to the screen
SDL_BlitSurface(intermediate, NULL, screen, NULL);






One of the things I got stumped by when I first tried this (which was pretty stupid of me really, and I just happened to overlook it) was the bit depth and the corresponding masks in surface creation. I was doing:


SDL_Surface * intermediate = SDL_CreateRGBSurface(SDL_SWSURFACE, 800, 600, 16, 0xff0000, 0xff00, 0xff, 0xff000000);


instead of

SDL_Surface * intermediate = SDL_CreateRGBSurface(SDL_SWSURFACE, 800, 600, 16, 0xf00, 0xf0, 0xf, 0xf000);


And nothing was showing up... oops :oP

Hope that provided some insight!

Share this post


Link to post
Share on other sites
PnP Bios    494
Hey, The Rug.
Its just better to use the define method for the masking, otherwise you can't cross compile.
Big Endian vs Little Endian. Stupid stupid stupid. This should be handled internaly.

Share this post


Link to post
Share on other sites
Grellin    186
Just for a little clarification on this (for me). What is the benefit of blitting to an intermediate surface? Isn't it the same number of blits +1 (the intermediate surface)?

Share this post


Link to post
Share on other sites
PnP Bios    494
The benifit, is that you can do bluring in combination with alpha blending, or have an offset to do a screen shake effect.

Mostly for screen transitions and stuff

Share this post


Link to post
Share on other sites
C-Junkie    1099
The OP wants to blit all the tiles to an intermediate surface, then never blit the tile again.

just blit parts of the intermediate to the screen, whenever the screen needs drawing.

Share this post


Link to post
Share on other sites

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