SDL_SetGamma not working under Windows... Fix

Hi,

there is a bug that stops the SDL_SetGamma() call from working
with the “directx” driver (it seems to work with “windib”).

There are several occurances of code like this :

#ifdef IID_IDirectDrawGammaControl

#endif

that enables the gamma code for the “directx” drivers, but this
doesn’t work because IDirectDrawGammaControl isn’t a macro symbol!

I would suggest using :

#ifdef IDirectDrawGammaControl_SetGammaRamp

#endif

[I just did a quick search and replace]

This seems to work, but only when in -fullscreen mode
(as documented in the DirectX documentation).

It is also worth making sure that the correct versions of the DirectX
headers are being included,

cheers,
John Popplewell.> ----- Original Message -----

From: slouken@devolution.com (Sam Lantinga)
To:
Sent: Tuesday, April 09, 2002 5:29 PM
Subject: Re: [SDL] SDL_SetGamma not working under Windows…

static void DIB_CheckGamma(_THIS)
{
#ifndef NO_GAMMA_SUPPORT
HDC hdc;
WORD ramp[3*256];

/* If we fail to get gamma, disable gamma control */
hdc = GetDC(SDL_Window);
if ( ! GetDeviceGammaRamp(hdc, ramp) ) {
    this->GetGammaRamp = NULL;
    this->SetGammaRamp = NULL;
}
ReleaseDC(SDL_Window, hdc);

#endif /* !NO_GAMMA_SUPPORT */
}

If this code is failing (you might add some debug output or something
maybe?) that would explain it. In what cases this code succeeds though,
I

can’t guess.

The windx5 directory has a much messier set of DirectDraw gamma code,
but

that doesn’t even work with OpenGL windows since they don’t have DDraw
contexts. Sam, could you add GetDeviceGammaRamp/SetDeviceGammaRamp
support to the windx5 backend for non-DDraw windows? Looks easy enough
to

do, but without a winbox to test on, I’m hesitant to touch it.

It’s not trivial. There’s a whole bunch of code and associated data
relating to saving and restoring the gamma ramp which is specific to
the DIB version of the driver. The whole “fake-DIB-with-OpenGL” hack
really needs to be redesigned properly with SDL 1.3.

See ya,
-Sam Lantinga, Software Engineer, Blizzard Entertainment


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

Hi John,
Thanks for pointing this out.
Sam is this likely to make it into the 1.2.4 release?

Thanks again,

Dominique.

John Popplewell wrote:> Hi,

there is a bug that stops the SDL_SetGamma() call from working
with the “directx” driver (it seems to work with “windib”).

There are several occurances of code like this :

#ifdef IID_IDirectDrawGammaControl

#endif

that enables the gamma code for the “directx” drivers, but this
doesn’t work because IDirectDrawGammaControl isn’t a macro symbol!

I would suggest using :

#ifdef IDirectDrawGammaControl_SetGammaRamp

#endif

[I just did a quick search and replace]

This seems to work, but only when in -fullscreen mode
(as documented in the DirectX documentation).

It is also worth making sure that the correct versions of the DirectX
headers are being included,

cheers,
John Popplewell.

----- Original Message -----
From: “Sam Lantinga”
To:
Sent: Tuesday, April 09, 2002 5:29 PM
Subject: Re: [SDL] SDL_SetGamma not working under Windows…

static void DIB_CheckGamma(_THIS)
{
#ifndef NO_GAMMA_SUPPORT
HDC hdc;
WORD ramp[3*256];

/* If we fail to get gamma, disable gamma control /
hdc = GetDC(SDL_Window);
if ( ! GetDeviceGammaRamp(hdc, ramp) ) {
this->GetGammaRamp = NULL;
this->SetGammaRamp = NULL;
}
ReleaseDC(SDL_Window, hdc);
#endif /
!NO_GAMMA_SUPPORT */
}

If this code is failing (you might add some debug output or something
maybe?) that would explain it. In what cases this code succeeds though,

I

can’t guess.

The windx5 directory has a much messier set of DirectDraw gamma code,

but

that doesn’t even work with OpenGL windows since they don’t have DDraw
contexts. Sam, could you add GetDeviceGammaRamp/SetDeviceGammaRamp
support to the windx5 backend for non-DDraw windows? Looks easy enough

to

do, but without a winbox to test on, I’m hesitant to touch it.

It’s not trivial. There’s a whole bunch of code and associated data
relating to saving and restoring the gamma ramp which is specific to
the DIB version of the driver. The whole “fake-DIB-with-OpenGL” hack
really needs to be redesigned properly with SDL 1.3.

See ya,
-Sam Lantinga, Software Engineer, Blizzard Entertainment


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl


http://www.DelphiGamer.com := for all your Object Pascal game
development needs;
http://www.delphi-jedi.org/Jedi:TEAM_SDL_HOME := Home of JEDI-SDL;
Cross-platform game development with Pascal, has never been easier.

there is a bug that stops the SDL_SetGamma() call from working
with the “directx” driver (it seems to work with “windib”).

I would suggest using :

#ifdef IDirectDrawGammaControl_SetGammaRamp

#endif

Thanks! I’ve added this one to CVS as well.
It might be worth using the DIB gamma ramp code with the DirectX driver,
for windowed mode as well as OpenGL. Want to take a crack at it? The
important hairy parts are saving and swapping the gamma ramps when gaining
or losing focus.

See ya,
-Sam Lantinga, Software Engineer, Blizzard Entertainment

Hi Sam,

I will take a look at it, off to get some sleep now.

It might be worth using the DIB gamma ramp code with the DirectX driver,

Whilst reading the docs I found this :

“”“
Note Those very familiar with the Win32? API might wonder why DirectDraw
exposes an interface like IDirectDrawGammaControl, when Win32 offers the
GetDeviceGammaRamp and SetDeviceGammaRamp functions for the same surfaces.
Although the Win32 API includes these functions, they do not always succeed
on all Windows platforms like the methods of the IDirectDrawGammaControl
interface
”""

Quite what this means, I don’t know. The DX gamma stuff doesn’t work on
one of my video cards (S3 Virge),

cheers,
John.> ----- Original Message -----

From: slouken@devolution.com (Sam Lantinga)
To:
Sent: Wednesday, April 10, 2002 12:51 AM
Subject: Re: [SDL] SDL_SetGamma not working under Windows… Fix.

there is a bug that stops the SDL_SetGamma() call from working
with the “directx” driver (it seems to work with “windib”).

I would suggest using :

#ifdef IDirectDrawGammaControl_SetGammaRamp

#endif

Thanks! I’ve added this one to CVS as well.
It might be worth using the DIB gamma ramp code with the DirectX driver,
for windowed mode as well as OpenGL. Want to take a crack at it? The
important hairy parts are saving and swapping the gamma ramps when gaining
or losing focus.

See ya,
-Sam Lantinga, Software Engineer, Blizzard Entertainment


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

Whilst reading the docs I found this :

“”“
Note Those very familiar with the Win32? API might wonder why DirectDraw
exposes an interface like IDirectDrawGammaControl, when Win32 offers the
GetDeviceGammaRamp and SetDeviceGammaRamp functions for the same surfaces.
Although the Win32 API includes these functions, they do not always succeed
on all Windows platforms like the methods of the IDirectDrawGammaControl
interface
”""

Quite what this means, I don’t know. The DX gamma stuff doesn’t work on
one of my video cards (S3 Virge),

This means that while the GDI driver may not have access to the gamma ramps,
the fullscreen DirectX driver may.

See ya,
-Sam Lantinga, Software Engineer, Blizzard Entertainment

It might be worth using the DIB gamma ramp code with the DirectX driver,
for windowed mode as well as OpenGL. Want to take a crack at it? The
important hairy parts are saving and swapping the gamma ramps when gaining
or losing focus.

It is a bit messy, but seems to work ok. I tested it using “testgamma” and
a modifed version of “testgl” (just added the up/down key handlers from
"testgamma"). Oh yeah, I also changed the LOGO_FILE to “sample.bmp” so
that I could see the effect - I think it works …

One of my concerns is the modification to this :

/* Private display data */
struct SDL_PrivateVideoData {
LPDIRECTDRAW2 ddraw2;
LPDIRECTDRAWSURFACE3 SDL_primary;

SDL_Rect **SDL_modelist[NUM_MODELISTS];
int SDL_modeindex[NUM_MODELISTS];

WORD *gamma_saved;        <--- added this

};

This is a private data structure, so binary compatability with existing
apps will be ok won’t it?

Also, my use of #ifdefs is a bit hairy in there!
Hope it checks out,

cheers,
John Popplewell.

-------------- next part --------------
A non-text attachment was scrubbed…
Name: dx-gamma-patch.pat
Type: application/octet-stream
Size: 9036 bytes
Desc: not available
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20020410/90f387e7/attachment.objFrom: slouken@libsdl.org (slouken)