We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 850

Summary: Colour distortion when playing a game in windowed mode
Product: SDL Reporter: Kieran P <kieran776>
Component: *don't know*Assignee: Sam Lantinga <slouken>
Status: RESOLVED INVALID QA Contact: Sam Lantinga <slouken>
Severity: major    
Priority: P2    
Version: 1.2.14   
Hardware: x86_64   
OS: Mac OS X 10.6   
Attachments: Fix for Globulation 2

Description Kieran P 2009-10-16 12:35:09 UTC
For starters, I compile / make packages, I don't know c++ so I'm sorry if I can't provide a smaller example.

When playing Globulation 2 (http://globulation2.org) on the Mac, the colours are really distorted.

I'm using the latest SVN pre release, along with the latest sdl_image, sdl_ttf, and sdl_mixer pre releases, and various combinations of them.

Note: When I play the game in full screen, the issues go away. I only get this issue in windowed mode.

Here is the rundown on what works and doesn't work:

Leopard + SDL 1.2.13 + SDL_image 1.2.7  =  works
Snow Leopard + SDL 1.2.13 (with patch*) + SDL_image 1.2.7  =  doesn't work
Snow Leopard + SDL 1.2.13 (with patch*) + SDL_image 1.2.8  =  doesn't work
Snow Leopard + SDL 1.2.14 pre-release + SDL_image 1.2.7  = doesn't work
Snow Leopard + SDL 1.2.14 pre-release + SDL_image 1.2.8  = doesn't work

* http://methylblue.com/junk/libsdl-1.2.13-10.6.patch

So whats wrong exactly?

Good: http://globulation2.org/wiki/Image:Beta2_AttackingEnemy.jpg
Good: http://globulation2.org/wiki/Image:Beta2_BuildingCamp.jpg
Bad: http://screencast.com/t/WD8SLtkF1x

In the bad version. the menu on the right and the top stats bar which
are normal transparent black shade are blue background. The black
undiscovered areas, which are normally solid black, are now solid
blue. The blackish fog out when an area is out of view of
buildings/units is now a transparent blue instead of black. Also
notice that all units and buildings, where normally pink, are orange.
The bar above the main building (Swarm) should have white dots, the
bar to its left should have yellow dots, the bar below it should have
green dots. All three bars are blue. The small pink areas over the
resources called wheat are actually meant to be red.

There are quite a few other issues throughout the game menus and other screens.


Smaller example?

I emailed one of the devs of the game, who said that, given the custom graphics lib we use (called libgag -
http://hg.globulation2.org/glob2-new/file/default/libgag ) it won't be
trivial to find the exact code causing the issue for you to test. And as mentioned earlier, I'm not a c++ dev so please don't ask. Just compile/run the game, and if it gives the same error, something somewhere is doing something it shouldn't.
Comment 1 Sam Lantinga 2009-10-16 21:59:06 UTC
I haven't been able to build it, but I think the problem is in these functions:

        // Color
        Uint32 Color::pack() const
        {
                return (SDL_MapRGB(&_glFormat, r, g, b) & 0x00ffffff) | (a << 24);
        }

        void  Color::unpack(const Uint32 packedValue)
        {
                SDL_GetRGB(packedValue, &_glFormat, &r, &g, &b);
                a = packedValue >> 24;
        }

They assume that the alpha is in the high bits, which isn't necessarily the case.  I believe they want to use SDL_MapRGBA() and SDL_GetRGBA() instead.
Comment 2 Kieran P 2009-10-16 22:10:49 UTC
(In reply to comment #1)
> I haven't been able to build it, but I think the problem is in these functions:

The mac scons scripts looks for libraries in /opt/local. Will probably need to add /usr and /usr/local at some point. You can just do a find and replace of /opt/local in SConstruct with the prefix where boost etc are installed.

>         // Color
>         Uint32 Color::pack() const
>         {
>                 return (SDL_MapRGB(&_glFormat, r, g, b) & 0x00ffffff) | (a <<
> 24);
>         }
> 
>         void  Color::unpack(const Uint32 packedValue)
>         {
>                 SDL_GetRGB(packedValue, &_glFormat, &r, &g, &b);
>                 a = packedValue >> 24;
>         }
> 
> They assume that the alpha is in the high bits, which isn't necessarily the
> case.  I believe they want to use SDL_MapRGBA() and SDL_GetRGBA() instead.

Are you able to provide a quick diff for testing please? As I stated earlier, I don't know c++ myself, and given the release of this version within a day or two, it would be good to get this sorted beforehand.
Comment 3 Sam Lantinga 2009-10-16 22:28:15 UTC
Created attachment 420 [details]
Fix for Globulation 2
Comment 4 Sam Lantinga 2009-10-16 22:29:36 UTC
Yep this was a bug in Globulation where it assumed that the alpha channel was in the high bits.  I suspect all of the other windowed color issues on Snow Leopard will be the same thing.
Comment 5 Kieran P 2009-10-16 22:45:04 UTC
(In reply to comment #4)
> Yep this was a bug in Globulation where it assumed that the alpha channel was
> in the high bits.  I suspect all of the other windowed color issues on Snow
> Leopard will be the same thing.


Hmm, there are still some graphics issues, though thankfully not as much now :-D

http://skitch.com/k776/ndt19/dock

Any ideas? I did a search for SDL_MapRGB and SDL_GetRGB  but there are no more.
Comment 6 Sam Lantinga 2009-10-16 22:50:29 UTC
Nope, you can contact the authors and let them know about this bug though, and they'll hopefully be able to track it down.