Game Development Community

Resetting gamma correction after quitting?

by Rubes · in Torque Game Engine · 11/02/2007 (7:31 pm) · 3 replies

Here's something that's baffling me...

I do most of my dev work on the Mac, but I'm also trying to keep a Windows build up to date. But I've noticed an issue when messing with the gamma correction on my Windows build, using the videoSetGammaCorrection() method.

The TDN entry for videoSetGammaCorrection() states: "The card will revert to it's default gamma setting as long as the application closes normally."

As long as I select "Quit" from my game's main menu, the game does shut down normally and it returns the gamma to its previous correction level, as it should. However, if I click on the game window's close box (or hit Alt+F4), the game quits but without returning the gamma back to its previous level. Why?

Selecting "Quit" from the main menu directly calls the quit() console function, which in the engine just calls Platform::postQuitMessage(0).

Clicking on the game window's close box (or hitting Alt+F4) puts the engine in winWindow.cc, around line 833, where it hits case WM_CLOSE which from there calls...PostQuitMessage(0). I put a little console message in there to be sure it was hitting this code, and it does.

With trace turned on, the console log appears exactly the same if I quit by either method. And both methods call PostQuitMessage(0) as the main quit event, without any other calls that I can see. So how are they different? Why does one method restore the prior gamma correction and the other does not?

Thanks...

#1
11/03/2007 (4:44 pm)
Bump....?
#2
11/03/2007 (10:17 pm)
Which version of TGE are you using? I took a quick look at the 1.5.2 source and gamma is restored by OpenGLDevice::shutdown() or D3DDevice::shutdown() depending on whether you are using opengl or directx.
TGE stores the original gamma in mOriginalRamp and is set in OpenGLDevice::activate or D3DDevice::activate.

I did not see anything offhand that should cause it to not reset the gamma on exit. I did some quick tests shutting the app down in various ways and could not duplicate what you are seeing. If you own the source (it looks like you do) then I would start by looking at the shutdown methods I listed.

And a general FYI, when postQuitMessage is called it places a quit event in the queue, this will trigger the shutdown sequence when the event is processed. You will find a shutdown method for each namespace.

I hope that helps.
#3
11/04/2007 (9:33 am)
I'm using 1.5.2.

I definitely see where gamma is supposed to be restored in the shutdown() routine, and I even put a brief console message in that code to make sure it was hitting it. The code to restore the old gamma is definitely being called no matter which method I use to quit the application (Quit from the game menu or Alt+F4), but in one case (Quit) it's restoring the old gamma level, and in the other case (Alt+F4) it is not. And this is very reproducible.

This is very puzzling.