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 2153

Summary: SDL_SetWindowBrightness() sets gamma for entire monitor, not window!
Product: SDL Reporter: Waxhead <waxhead>
Component: videoAssignee: Sam Lantinga <slouken>
Status: ASSIGNED --- QA Contact: Sam Lantinga <slouken>
Severity: major    
Priority: P2 CC: adam, waxhead
Version: HG 2.1   
Hardware: x86   
OS: Windows (XP)   

Description Waxhead 2013-10-13 22:16:25 UTC
System:
WinXPsp3 (32bit) 
3 monitor setup 2x Connected to nvidia geforce 8600gts and the third monitor connected to a geforce 7300gt.
nvidia 280.26 driver

Problem:
the SDL_SetWindowBrightness() function sets gamma for the entire monitor instead of just the window (as one might expect) as long as the SDL window has focus. If it is unfocused it restore the gamma for the monitor.

Also if I move away the window to a second monitor the gamma is NOT restored once the window leaves the monitor (forgets about it). It will however restore if the window is moved back to the original monitor where gamma was set.

Reproducible:
Always
Comment 1 Sam Lantinga 2014-06-22 18:18:51 UTC
That's correct, the brightness is implemented using the device gamma ramp which affects the whole monitor. If you implement your own 3D renderer you can implement brightness as a separate composition pass, but that's more performance intensive.
Comment 2 Waxhead 2014-06-23 15:54:54 UTC
(In reply to Sam Lantinga from comment #1)
> That's correct, the brightness is implemented using the device gamma ramp
> which affects the whole monitor. If you implement your own 3D renderer you
> can implement brightness as a separate composition pass, but that's more
> performance intensive.

The documentation states "Use this function to set the brightness (gamma correction) for a window." https://wiki.libsdl.org/SDL_SetWindowBrightness?highlight=%28\bCategoryAPI\b%29|%28SDLFunctionTemplate%29

Since when was a Window synonymous with a monitor?! This is not obvious for the programmer and I suggest either updating the documentation or renaming the function to something a bit more accurate. It is obvious that it does not set the brightness for the window as one might expect.

Also regardless if this function was renamed SDL_SetOutputGamma() or something else there is still a bug, if you move the window to another monitor the gamma is not restored on the monitor it was moved from and the monitor the window is moved to does not inherit the gamma. E.g. the monitor that the window was opened on still has a higher gamma and the other monitor no adjustments made.
Comment 3 Adam M. 2014-06-23 22:37:22 UTC
It is terribly unintuitive, and the . I would personally vote for the functions to be deprecated in favor of SDL_GetDisplayBrightness(int displayIndex) and SDL_SetDisplayBrightness(int displayIndex, float brightness). Temporary macro and wrapper functions called SDL_SetWindowBrightness could prevent breaking existing code (and also emit a compiler warning about the functions being deprecated).

But I would understand if policy stated that SDL 2.0 APIs must never break backwards compatibility. In the mean time, I've updated the documentation.
Comment 4 Adam M. 2014-06-23 22:40:25 UTC
What about SDL_GetWindowGammaRamp and SDL_SetWindowGammaRamp? Do those have the same problems?
Comment 5 Adam M. 2014-06-23 22:41:56 UTC
Also, do the functions support brightnesses outside the range of 0 to 1? Could it be set to 1.5, for instance?
Comment 6 Waxhead 2014-06-25 17:54:43 UTC
(In reply to Adam M. from comment #3)
> It is terribly unintuitive, and the . I would personally vote for the
> functions to be deprecated in favor of SDL_GetDisplayBrightness(int
> displayIndex) and SDL_SetDisplayBrightness(int displayIndex, float
> brightness). Temporary macro and wrapper functions called
> SDL_SetWindowBrightness could prevent breaking existing code (and also emit
> a compiler warning about the functions being deprecated).
> 
> But I would understand if policy stated that SDL 2.0 APIs must never break
> backwards compatibility. In the mean time, I've updated the documentation.

Speaking for myself I am happy with the changes to the documentation as it clearly states how the function works (no one would like a function called DeleteFile() to nuke a directory right?), however the bug that I mentioned is still there to my best knowledge. I don't use Windows anymore :) so I can't test any potential fixes.
Comment 7 Sam Lantinga 2014-06-26 04:13:40 UTC
SDL_SetWindowBrightness() is implemented using SDL_SetWindowGammaRamp(), so it has the same issue.

You can set the brightness to any valid gamma correction value. Typical values are in the range of 0.2 to 5.0.
Comment 8 Adam M. 2014-06-27 00:42:54 UTC
I've updated the documentation for SDL_Get/SetWindowGammaRamp as well, then.
Comment 9 Sam Lantinga 2017-08-15 05:22:20 UTC
Marking for review for SDL 2.1