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

Started by
6 comments, last by Grellin 19 years, 6 months ago
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?
---"What? What is it? Is it the monkey in the pants? It's the monkey in the pants, isn't it. Don't give me that look."
Advertisement
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!
HxRender | Cornerstone SDL TutorialsCurrently picking on: Hedos, Programmer One
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!
the rug - funpowered.com
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.
HxRender | Cornerstone SDL TutorialsCurrently picking on: Hedos, Programmer One
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)?
Steven Bradley .:Personal Journal:. .:WEBPLATES:. .:CGP Beginners Group:. "Time is our most precious resource yet it is the resource we most often waste." ~ Dr. R.M. Powell
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
HxRender | Cornerstone SDL TutorialsCurrently picking on: Hedos, Programmer One
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.
Ok, I got it. Thanks guys!
Steven Bradley .:Personal Journal:. .:WEBPLATES:. .:CGP Beginners Group:. "Time is our most precious resource yet it is the resource we most often waste." ~ Dr. R.M. Powell

This topic is closed to new replies.

Advertisement