Jump to content
  • Advertisement
Sign in to follow this  
Boat Bum

OpenGL Trying to invert the colors on the display with gamma table

This topic is 3080 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

I have the need to invert the colors on a windows display. I need to be able to switch this on and off very quickly and have it effect all applications so it seems to me that modifying the gamma table would be the best way to achieve my goal.

My application will run on XP and use an ATI 4670 based graphics card. I first tried to use the ATI SDK but apparently the public APIs only allow you to modify the gamma ramp with one exponent per color.

I then switched to the WIN32 SetDeviceGammaRamp call. This works well for modifying the gamma table as long as I don’t make the slope too flat or (as I need) invert the slope. The API seems to reject a table with the data I need to invert the display’s colors.

Finally I’m trying the DirectX lpDDGammaControl->SetGammaRamp() call. I can get a copy of the current gamma table with lpDDGammaControl->GetGammaRamp() but when I try to modify it and write it the call fails to work even though it returns S_OK.

I would appreciate any help getting this effect working. I’m an OpenGL programmer and know very little about DirectX so this could be something very simple. Does anyone know what I’m doing wrong or could you refer me to some code that does this kind of thing.

I would also appreciate any programmatic solution to modifying the gamma table to invert the colors. My solution doesn’t have to use DirectX calls.

Thanks

bool SetUpGamma(HWND hwnd)
{
DDSURFACEDESC ddsd;
HRESULT ddrval;


/*
* create the main DirectDraw object
*/
ddrval = DirectDrawCreate( NULL, &lpDD, NULL );
if(ddrval != DD_OK )
{
return(false);
}

// using DDSCL_NORMAL means we will coexist with GDI
ddrval = lpDD->SetCooperativeLevel( hwnd, DDSCL_NORMAL );
if( ddrval != DD_OK )
{
lpDD->Release();
return(false);
}

memset( &ddsd, 0, sizeof(ddsd) );
ddsd.dwSize = sizeof( ddsd );
ddsd.dwFlags = DDSD_CAPS;
ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;

// The primary surface is not a page flipping surface this time
ddrval = lpDD->CreateSurface( &ddsd, &lpDDSPrimary, NULL );
if( ddrval != DD_OK )
{
lpDD->Release();
return(false);
}
lpDDSPrimary->QueryInterface(IID_IDirectDrawGammaControl,(void **)&lpDDGammaControl);
lpDDGammaControl->GetGammaRamp(0, &DDGammaOld);

for (int i=0;i<256;i++)
{
DDGammaInvert.blue = DDGammaOld.blue[255-i];
DDGammaInvert.green = DDGammaOld.green[255-i];
DDGammaInvert.red = DDGammaOld.red[255-i];
}
return true;
}


And I later try to set the gamma table with.

HRESULT hr = lpDDGammaControl->SetGammaRamp(0, &DDGammaInvert);

Share this post


Link to post
Share on other sites
Advertisement
Try reading this old thread: http://www.gamedev.net/community/forums/topic.asp?topic_id=516864

Unfortunately it only provides a solution for Nvidia cards.

Share this post


Link to post
Share on other sites
Thanks Adam_42,
I read that in my search for an answer. It was good to understanding that the WIN32 approach wouldn't work but I need to do this on a specific chip (the ATI 4600 series) so I still need an ATI solution.

I do wish I could use the NVIDIA chip but not for this project.

Still searching for a method to invert output on an ATI chip....

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!