SDL_BlitSurface creates "holes" instead of alpha blending

Hello list,

I’ve this weird problem which is kind of annoying:

Given are two surfaces, both are RGBA, width and height are equal, the
alpha channel parameters of both of them have been set:

SDL_SetAlpha(Surface, SDL_SRCALPHA, SDL_ALPHA_OPAQUE);

Now, one is the background and the other is the top (which has opaque
parts, transparent parts and inbetween). These surfaces should be
blitted onto each other.

This works fine for the parts which are completely opaque and for those
which are completely transparent. For the “inbetween” areas I expect
alpha blending - instead in these areas only the background is visible.
No alpha blending is done whatsoever.

What am I doing wrong?

Thanks in advance,
Johannes

Johannes Bauer schrieb:

What am I doing wrong?

Some code to demonstrate the problem - I still don’t see any solution.
This is weird.

#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <stdlib.h>

#include “SDL.h”

SDL_Surface *init(int Width, int Height) {
Uint32 RMask, GMask, BMask, AMask;
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
RMask = 0xff000000;
GMask = 0x00ff0000;
BMask = 0x0000ff00;
AMask = 0x000000ff;
#else
RMask = 0x000000ff;
GMask = 0x0000ff00;
BMask = 0x00ff0000;
AMask = 0xff000000;
#endif

SDL_Surface *SubSurface = SDL_CreateRGBSurface(SDL_SWSURFACE |
SDL_SRCALPHA, Width, Height, 32, RMask, GMask, BMask, AMask);
// SDL_SetAlpha(SubSurface, SDL_SRCALPHA, SDL_ALPHA_OPAQUE);
return SubSurface;
}

void dump(SDL_Surface x) {
Uint8 r, g, b, a;
SDL_GetRGBA(((Uint32
)x->pixels)[0], x->format, &r, &g, &b, &a);
printf(“RGBA %2x %2x %2x %2x\n”, r, g, b, a);
}

int main(int argc, char **argv) {

SDL_Init(SDL_INIT_VIDEO);

{
SDL_Surface *src, *dst;
src = init(1, 1);
dst = init(1, 1);

  ((Uint32*)(src->pixels))[0] = 0x11223344;
  ((Uint32*)(dst->pixels))[0] = 0x0;
  SDL_BlitSurface(src, NULL, dst, NULL);

  dump(src);
  dump(dst);

  SDL_FreeSurface(src);
  SDL_FreeSurface(dst);

}

SDL_Quit();
return 0;
}

So it should blit “src” on “dst”. What it outputs is:

RGBA 44 33 22 11
RGBA 0 0 0 0

This is way weird. Shouldn’t it output something like
RGBA 3 2 1 0

I’m pretty desperate right now. This is like the most basic primitive
SDL offers and I get it to work most of the time (my game works,
actually) - but currently I’m incredibly stuck. Did it all just work by
accident so far?

Greetings,
Johannes

[…]

So it should blit “src” on “dst”. What it outputs is:

RGBA 44 33 22 11
RGBA 0 0 0 0

This is way weird. Shouldn’t it output something like
RGBA 3 2 1 0
[…]

RGBA->RGBA blending is not supported by the SDL blitters! You’ll need
to use custom code or some add-on library for this. IIRC, SDL will
just do opaque blits replacing destination A just like any other
channel.

//David Olofson - Programmer, Composer, Open Source Advocate

.------- http://olofson.net - Games, SDL examples -------.
| http://zeespace.net - 2.5D rendering engine |
| http://audiality.org - Music/audio engine |
| http://eel.olofson.net - Real time scripting |
’-- http://www.reologica.se - Rheology instrumentation --'On Sunday 25 November 2007, Johannes Bauer wrote:

David Olofson schrieb:> On Sunday 25 November 2007, Johannes Bauer wrote:

[…]

So it should blit “src” on “dst”. What it outputs is:

RGBA 44 33 22 11
RGBA 0 0 0 0

This is way weird. Shouldn’t it output something like
RGBA 3 2 1 0
[…]

RGBA->RGBA blending is not supported by the SDL blitters! You’ll need
to use custom code or some add-on library for this. IIRC, SDL will
just do opaque blits replacing destination A just like any other
channel.

Jeez, you’re right.

Thanks for hitting me with the brick on the head. Sometimes I need
that… Changed the destination surface to RGB and now everything works
like a charm!

Thanks a lot,
Greetings,
Johannes

PS: I tried the Video Game Character Evaluator you’ve liked on your
homepage and turned out to be an Asteroid. Neat :wink: