libsdl-org / sdl12-compat

An SDL-1.2 compatibility layer that uses SDL 2.0 behind the scenes.
Other
193 stars 40 forks source link

tuxfootball: selected option in main menu disappears #265

Closed smcv closed 1 year ago

smcv commented 1 year ago

Prerequisites:

To reproduce:

and press Up/Down arrow keys.

Expected result: selected option is white, remaining options are gold

Actual result: Real SDL 1.2 works. With sdl12-compat, the selected option vanishes.

Gameplay seems OK as far as I can tell.

icculus commented 1 year ago

It's something with the font atlas image...if I swap font_white.png and font_yellow.png, I get just the current option and none of the others.

icculus commented 1 year ago

There's a color key of 0xFFFFFF (pure white) set for some reason. If I force color keying off for that surface, it renders correctly. Not sure why there's a colorkey at all yet.

icculus commented 1 year ago

Finally got back to this. So here's what's happening.

Eventually, this lands in SDL_Blit_Slow in SDL2. Probably because this is a 32-bit surface with an alpha channel and a colorkey, blitting to a 32-bit surface without an alpha channel, but I don't know.

The difference, of course, is this code in classic SDL-1.2's SDL_CalculateAlphaBlit ...

    if(sf->Amask == 0) {
    if((surface->flags & SDL_SRCCOLORKEY) == SDL_SRCCOLORKEY) {

...where it will only consider the colorkey of a surface at all if it doesn't have an alpha channel. SDL_Blit_Slow in SDL2, though, will discard pixels that match the colorkey and then alpha-blend what's left.

It's not clear to me if this is a bug in SDL-1.2 or a bug in SDL2. :)

We'll probably have to look for this case and just not set the colorkey on the SDL2 surface, though.