SDL displaying wrong colors with DirectX and windowed 8bpp mode

Hi,

With QEMU and some self-written small test apps I’m unable to get the
"correct" colors if I change the Windows display resolution to 256 colors, set
SDL_VIDEODRIVER=directx and then run the application in “window” mode (not
full-screen). With SDL_VIDEODRIVER=windib everything looks ok.

I tested with SDL 1.2.9, 1.2.10 and 1.2.11 under Win98SE and WinXP SP2.

Regards

With QEMU and some self-written small test apps I’m unable to get the
"correct" colors if I change the Windows display resolution to 256 colors, set
SDL_VIDEODRIVER=directx and then run the application in “window” mode (not
full-screen). With SDL_VIDEODRIVER=windib everything looks ok.

Are you using a hardware palette? (SDL_HWPALETTE with SDL_SetVideoMode()).

–ryan.

With QEMU and some self-written small test apps I’m unable to get the
"correct" colors if I change the Windows display resolution to 256 colors, set
SDL_VIDEODRIVER=directx and then run the application in “window” mode (not
full-screen). With SDL_VIDEODRIVER=windib everything looks ok.

Are you using a hardware palette? (SDL_HWPALETTE with SDL_SetVideoMode()).

Neither SDL_HWPALETTE nor SDL_SWPALETTE. In fact, since I’m just interested in
Qemu’s behaviour, I wrote a simple test program which - I assume at least -
handles the screen the same way as Qemu, that is:

  • calling SDL_SetVideoMode() with SDL_HWSURFACE flag
  • never call SDL_SetPalette() and/or SDL_MapRGB()
  • always directly write into the surface with screen->pixels

The test program (which displays 256 rectangles representing the 256 colors)
shows a difference between SDL_VIDEODRIVER=directx and SDL_VIDEODRIVER=windib
if running in windowed 8bpp mode: with “directx” the first 10 and last 10
colors are the “reserved” windows colors, with “windib” this is not the case.
The rest of the 236 colors is somewhat “well-structured”, might be it is the
SDL “default” palette or whatever.

Neither SDL_HWPALETTE nor SDL_SWPALETTE.

Set SDL_HWPALETTE, then.

But really, something like Qemu, which wants to write to the framebuffer
directly all the time, shouldn’t be using HWSURFACE. On Linux/X11 and
windib, HWSURFACE is ignored, so they probably never noticed an issue,
but it’s probably seriously hurting performance on DirectX, which has to
keep moving the screen surface back and forth over the bus.

I still think either adding HWPALETTE or removing HWSURFACE should
probably fix the color problem, though.

–ryan.

I still think either adding HWPALETTE or removing HWSURFACE should
probably fix the color problem, though.

There is no difference adding HWPALETTE. Not that surprisingly, though, since
SDL_SetColors() and SDL_SetPalette() apparently are not called by Qemu - if
I understand SDL correctly this means Qemu does not set any colors at all and
will always use the palette as it has been initialized by SDL.

But I possibly can try to add a SDL_SetColors/SDL_SetPalette call after
SDL_SetVideoMode, setting the very same palette as it is done with
SDL_VIDEODRIVER=windib.

But I possibly can try to add a SDL_SetColors/SDL_SetPalette call after
SDL_SetVideoMode, setting the very same palette as it is done with
SDL_VIDEODRIVER=windib.

This didn’t help. I looked in the SDL source and realized that the code for
directx carefully avoids touching palette entries 0-9 and 246-255 in window
mode. So these 20 entries will always have the standard values. I’m sure there
are good reasons doing so, but OTOH it would be good if directx and windib
don’t behave differently in this regard.

announce)"
windowed 8bpp mode
SDL-announce)"

But I possibly can try to add a SDL_SetColors/SDL_SetPalette call
after SDL_SetVideoMode, setting the very same palette as it is
done with SDL_VIDEODRIVER=windib.

This didn’t help. I looked in the SDL source and realized that the
code for directx carefully avoids touching palette entries 0-9 and
246-255 in window mode. So these 20 entries will always have the
standard values. I’m sure there are good reasons doing so, but OTOH
it would be good if directx and windib don’t behave differently in
this regard.

Those pallet entries mentioned are reserved for the Windows operating
system default system colors. I’ve used them for my own purposes but
always made sure to restore them when the application finished. You
can do anything you want with software; it’s just how much flak can
you handle when your code misbehaves ? ;p

Todd> From: Japheth

Date: February 28, 2007 6:00:56 AM GMT-05:00
To: "A list for developers using the SDL library. (includes SDL-
Subject: Re: [SDL] SDL displaying wrong colors with DirectX and
Reply-To: "A list for developers using the SDL library. (includes