Jump to content
  • Advertisement
Sign in to follow this  
toXic1337

Clipping Question

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

I'm sure this is a very simple thing to do, because it is. But I've researched and researched SDL commands for clipping, and I think I'm doing things right, but when I get down to run-time, I get a segmentation fault. So I'm obviously doing something wrong. Here's a simplified form of my situation: Let's say I have a 32x16 image with two 16x16 tiles in it, a tileset basically. Now, what I want to do is create a 16x16 sprite that uses 1/2 of the 32x16.
//So this is where I'm getting messed up.

SDL_Surface *tileset;
SDL_Surface *terrain;

tileset = IMG_Load(tileset_file);

// Ok so 16x32 tileset is loaded, now I want to blit the left side of that to the terrain surface.

srcRect.x = 0;
srcRect.y = 0;
srcRect.w = 16;
srcRect.h = 16;

SDL_BlitSurface(tileset, &srcRect, terrain, NULL);

// Now the left side of the 16x32 should be the new surface "terrain"
// And now I'm going to blit surface to screen.

SDL_BlitSurface(terrain, NULL, screen, positionRect);

Now, does anyone see any theory mishaps? I'm at a loss. The only thing left for me to try I guess is using SDL_CreateRGBSurface(..) on "terrain" before blitting the left side of "tileset" to "terrain". Maybe "terrain" has to be initialized first or somethin, who knows? Hopefully, you do. Thanks in Advance! toXic1337

Share this post


Link to post
Share on other sites
Advertisement
terrain is NULL (or even worse, it's uninitialized), so you're trying to blit to a NULL surface. You've got to create the terrain surface first.

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!