Main Site Links Resources Tutorials
News VB Gaming Code Downloads DirectX 7
Contact Webmaster VB Programming Product Reviews DirectX 8
  General Multimedia Articles DirectX 9
      Miscellaneous

DirectDraw: Gamma Control
By: Jack Hoxley
Written: May 2000
Download: DD_Gamma.Zip (566kb)


Gamma control, when used properly, can allow you to achieve some amazing effects. The only serious problem with using it is that it isn't well supported; only computers with new or nearly-new graphics cards inside them will be able to support this effect. Because of this downside it is advisable that you dont rely to heavily on it's use - as the fruitworld game example does.

In the fruitworld game example it uses the control to achieve cinematic effects as it fades the credits in with different amounts of colour; then, during the game, it uses it to create lighting effects. It is possible to recreate this effect using several other, more widely supported methods, such as these:

  1. Memory Access. A formula could have been written to go through every pixel and fade it out slightly each time. The only drawback being that it is very slow.
  2. Palette animation. This is very fast, and extremely easy to use. The only drawback is that it will require the display to be in 8bit paletised mode.

Gamma control is done through an interface of ramps. Put simply it alters the amount of red green or blue there is in every pixel. This is done between the time the primary surface is updated and the time that the monitor DAC (Digital to Analogue Convertor) gets the information; because it is done in this way it doesn't actually alter the values stored in your surfaces.

The interface is called a ramp, it can be visualised as a straight-line graph. Every colour component on the primary buffer is represented by a value 0 to 65535. This is then converted into a table of 256 different entries - which is basically the same as when you set a colour using a number between 0 and 255. Directdraw then reads off this graph what the output colour should be if the input colour is ??? If the graph is a simple X=Y line, the value that goes in is the value that comes out; by default this is how everything appears.

Using the access to the gamma ramps we can modify the relationship between input colour and output colour; depending on how you set the graph, you could make it so that half the amount going in actually appears on the screen. Have a look at these graphs for a better example:

These two graphs represent what was just discussed above. "Ramp 1" represents a normal gamma ramp; if you put in a value of 9620 you would get a value of 9620 appear on the screen - what goes in comes out. "Ramp 2" represents a modified gamma ramp, the value that comes out will be less than the value that went in, although the image is not accurate it should be roughly half.

These graphs could represent any of the three channels - Red, Green or Blue. Each channel can have a different gamma ramp attached to it; because of this you can dynamically fade in and fade out each colour. Using gamma correction has very little if any hardware overhead, so using it will not bring the computer to a grinding halt. Which is good.

I have written an example project that shows you how to implement the use of gamma correction in your games/programs. You can download it from the top of the page or from the Downloads page.

DirectX 4 VB © 2000 Jack Hoxley. All rights reserved.
Reproduction of this site and it's contents, in whole or in part, is prohibited,
except where explicitly stated otherwise.
Design by Mateo
Contact Webmaster