Jump to content
  • Advertisement
Sign in to follow this  
Pogo708

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

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

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
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!

Share this post


Link to post
Share on other sites
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
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
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
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
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!