SDL_SetAlpha-bug?

If I set SDL_SRCALPHA | SDL_RLEACCEL with SDL_SetAlpha, I see nothing on
the screen. If I set SDL_SetColorKey after that alpha, it works just
fine(and also the colorkey has an effect). Then I moved the
SDL_SetColorKey before the SDL_SetAlpha, and it didn’t work then. So here
are the combination I tried:

working:

SDL_SetAlpha
SDL_SetColorKey

not-working:

SDL_SetColorKey
SDL_SetAlpha

or

SDL_SetAlpha

What could be my problem here? Some flag I missed?

Juhana Lehtiniemi wrote:

If I set SDL_SRCALPHA | SDL_RLEACCEL with SDL_SetAlpha, I see nothing on
the screen. If I set SDL_SetColorKey after that alpha, it works just
fine(and also the colorkey has an effect). Then I moved the
SDL_SetColorKey before the SDL_SetAlpha, and it didn’t work then.

please post a minimal testcase

Ok, I tried to trace the problem a little bit more, and came to the
conclusion, that this occurs if the image is on hw_surface. My library
loaded every image onto an SDL_HWSURFACE after loading the image-file
itself.

So if the image is on a hardware surface, the alpha blending doesn’t seem
to work properly, but draws nothing or the picture actual with some grab.
But if you set the colorkey-transparency before the alpha-key
(SDL_SetAlpha), alpha blending works fine. I have no idea what happens.
Either the HWSURFACE is converted to SWSURFACE on the fly or the the hw
blending works… ehh…? This didn’t work on images that had alphachannel
by theirselves. I can’t get the images containing an alpha channel appear
transparent. Is there some trick? Just load them to a surface and draw
them, that should be it, right? SDL_SRCALPHA is set automatically?

Ehm, this is getting weird. The following is not about the same problem
that the last mail. I have a PNG-image that has an alpha-channel. I
can’t make it show half-transparent even if I set all the surfaces to SW.
It just shows a little bit darker. Then I have this background-image that
is also on SW-surface. The the image and the background-image both show
ok(thought the alpha channel doesn’t work), but if I set the
background-image(that doesn’t have alpha-channel) on a HW_surface, the
image that is on the sw_surface, starts to show all kind of grab in it.
Actually it doesn’t matter on which surface the other image is, but if the
background-image without the alpha channel is set to be on HW_SURFACE, the
other image(no matter which one surface it is on) starts to show
strangely. The screen-surface doesn’t seem to affect, wether it is on sw
or hw. I’m sorry that I can’t provide any testcase-code about this, but
here’s the theory.

Once more:

image 1 on sw			-> shows ok
image 2 with alpha on sw	-> shows ok

image 1 on sw			-> shows ok
image 2 with alpha on hw	-> shows ok

image 1 on hw			-> shows ok
image 2 with alpha on sw/hw	-> shows with grab

and in no case the alpha channel of the image 2 works. Could it be with
png-image?

Juhana Lehtiniemi wrote:

So if the image is on a hardware surface, the alpha blending doesn’t seem
to work properly, but draws nothing or the picture actual with some grab.
But if you set the colorkey-transparency before the alpha-key
(SDL_SetAlpha), alpha blending works fine. I have no idea what happens.

Neither have we, since you didn’t show us any testcase

Juhana Lehtiniemi wrote:

I’m sorry that I can’t provide any testcase-code about this,

Experience has taught me to insist on testcases. The sad reality is
that when someone says “I’m doing this, and it doesn’t work!” he isn’t
doing what he says at all.

Sam, please add something like this to the FAQ:

Q: My code doesn’t work! Is it a bug in SDL, or in my code? Help!

documentation and the FAQ, try asking on the SDL mailing list.
Before doing so, write a testcase.

This is a program that exhibits your problem, and:

  1. is short - about 20 lines, no more than 50 lines.
    This is absolutely essential; it should be as small and simple
    as possible.
  2. is written in plain C. No Pascal, Python, C++, etc.
  3. is complete and compileable, not just a code fragment.
  4. uses no extra libraries except for SDL (and possibly SDL_image,
    SDL_mixer, SDL_ttf)
  5. does not require any large image files

Often you will find your problem while making such a test program.
If the problem can be reduced to a testcase, you will have good
chances of getting a quick answer.A: If you don’t find your answer after carefully reading the

I agree, but sometimes a post to the mailing list with what you think is
going wrong is enough for a reader to spot a similar experience, and respond
with something that saves you the effort of trying to make a test case. So
when I post for help in this way, it’s usually with this in mind. Or else
what you’re asking is the set of circumstances to consider when a test case
appears to work, but the same code ‘in context’ doesn’t. So a test case is
sometimes appropriate, but other times you can get the same result with a
considered posting, and a reasoned run-down of why you think such-and-such
ought to work-- after all it’s in the poster’s interest if they want their
problem solved.On Tuesday 05 February 2002 10:34 am, you wrote:

Juhana Lehtiniemi wrote:

I’m sorry that I can’t provide any testcase-code about this,

Experience has taught me to insist on testcases. The sad reality is
that when someone says “I’m doing this, and it doesn’t work!” he isn’t
doing what he says at all.


Matthew > http://www.soup-kitchen.net/
> ICQ 19482073

Hi!

Are you really sure you have an alpha-channel?
A few weeks ago i hab a problem with a png saved in Corel PhotoPaint…
And it turned out that Corel’s alpha-channels are not the same as GIMP’s.
When i created the alpha channel in gimp and saved it, it worked…

greets
Stiefel