Blitting to a surface, then blitting that surface to screen....
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?
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!
I have a tutorial on surface creation you might want to look at.
cheers. good luck!
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:
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:
instead of
And nothing was showing up... oops :oP
Hope that provided some insight!
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!
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.
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.
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)?
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
Mostly for screen transitions and stuff
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.
just blit parts of the intermediate to the screen, whenever the screen needs drawing.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement