Jump to content
  • Advertisement
Sign in to follow this  

Regarding use of SetDeviceGammaRamp windows API winXP check

This topic is 3457 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Okay, so first of all let me say I am not sure if this is the right place to post... I wanted to post on this thread http://www.gamedev.net/community/forums/topic.asp?topic_id=196752, but it is closed. In the last post someone asked how you could bypass the windows XP check for setting an inverse gamma ramp (which would get you a NEGATIVE image :) ) More precisely, if you do something like GetDeviceGammaRamp( getDC(NULL), γ); and then, to invert that ramp, do something like:

    for(int i=0; i < 256; i++)
     gamma.Red   = 65535 - gamma.wRed;
     gamma.Blue  = 65535 - gamma.wBlue;
     gamma.Green = 65535 - gamma.wGreen;

    SetDeviceGammaRamp(GetDC(NULL), (LPVOID)&GammaArray);

Then NOTHING would happen ( and if you would go about checking the last error by means of GetLastError() you would either get a "bad parameter" or the more revealing but still WRONG error "the specified ramp is not supported by the device". The solution is to simply bypass the winAPI functions (which are in gdi32.dll), and use two very similar functions, but this time in a NVIDIA-provided dll (nvcpl.dll) Enough talk, I'll just post the working code: ( I've been digging and google-ing this up for WEEKS, and I really feel there's not many places on the 'net covering this, if any ):

  typedef struct GAMMARAMP
        WORD wRed[256];
        WORD wGreen[256];
        WORD wBlue[256];

    HINSTANCE hCpl = LoadLibrary("nvcpl.dll");

    if(hCpl == NULL)
        MessageBox(0,"LoadLibrary failed loading DLL", "LoadLibrary failed loading DLL", 0);

    typedef BOOL (*ptrSetGammaRamp)(LPTSTR, DWORD, PGAMMARAMP);
    typedef BOOL (*ptrGetGammaRamp)(LPTSTR, PGAMMARAMP);

    ptrSetGammaRamp nvSetGamma;
    ptrGetGammaRamp nvGetGamma;

    GAMMARAMP Gamma;

    nvSetGamma = (ptrSetGammaRamp) GetProcAddress( hCpl, "NvColorSetGammaRamp");

     MessageBox(0,"GetProcAdress fail on nvSetGamma","GetProcAdress fail on nvSetGamma", 0);

    nvGetGamma = (ptrGetGammaRamp) GetProcAddress( hCpl, "NvColorGetGammaRamp");

     MessageBox(0,"GetProcAdress fail on nvGetGamma","GetProcAdress fail on nvGetGamma", 0);

    nvGetGamma("a0", Γ);

    for(int i=0; i < 256; i++)
     Gamma.wRed   = 65535 - Gamma.wRed;
     Gamma.wBlue  = 65535 - Gamma.wBlue;
     Gamma.wGreen = 65535 - Gamma.wGreen;

    nvSetGamma("a0", 0xFFFFFFFF, Γ);
ps: If anyone knows of a similar ATI .dll that has functions like these, please let me know here. I am working on a project that is basically about reducing eye strain for people like myself who spend >15hrs a day on the computer (or more :)) ) and part of that is this "negative image" thing (having a BLACK background is a true relief on your eyes, believe me). And of course, I want it to work on ATI cards too. :)

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!