Uh-oh

Posted by (twitter: @quaIiaa)
December 18th, 2011 11:29 am

Hit a massive snag with sprite-loading. We’re using transparent PNG spritesheets. For, say, the font, the SDL_Surface* _font is loaded, and displays as transparent with no problems.

When blitting parts of _font onto an empty SDL surface, there is no transparency:
SDL_Surface *surface = SDL_CreateRGBSurface(SDL_SWSURFACE | SDL_SRCALPHA, width, height, 32,0xff000000,0x00ff0000,0x0000ff00,0);

SDL_BlitSurface(_font, &srcRect, surface, &destRect);
results in:

I’ve tried every combination of masks imaginable, including _font->format->Rmask, etc., to no effect.

If anyone has any idea what I’m doing wrong, I’d love to know, even though we’re very unlikely to make the jam deadline at this point.


3 Responses to “Uh-oh”

  1. JohnBedlam says:

    I had the exact same problem. It has to do with alpha channels being applied instead of blitted or something.

    Here’s how I fixed it:
    SDL_SetAlpha(font_surface, 0, font_surface->format->alpha);
    SDL_SetAlpha(target, 0, target->format->alpha);
    // Put your blits here
    SDL_SetAlpha(font_surface, SDL_SRCALPHA, font_surface->format->alpha);
    SDL_SetAlpha(target, SDL_SRCALPHA, target->format->alpha);

    • Gazok says:

      Woohoo! That fixed it. Thanks a lot, you may potentially have saved us. On the other hand, I think I wasted about four hours on this, so we’re probably still screwed 😛

Leave a Reply

You must be logged in to post a comment.

[cache: storing page]