Put on your adult-diapers folks because you're about to pee your pants. I have deciphered the GammaControl object included with DirectX7, and now have the ability to alter the screen's colour output at will. I can fade out, fade in, filter only the red channel, blue channel, green channel or any combination. I can do flashes of light (such as the red flash you see when you're hit in Quake) and all manner of other funky things. Have you wet yourself yet?
There were a few hindrances that had previously stopped VB programmers from using the GammaControl, most notably the fact that Gamma Ramps are arrays of unsigned integers. Visual Basic does not support unsigned integers, so I've written two cheesy little functions to handle the conversion:
Public Function ConvToUnSignedValue(intValue As Integer) As Long
End Function
End Function
If intValue >= 0 Then
ConvToUnSignedValue = intValue
End If
Exit Function
ConvToUnSignedValue = intValue + 65535
Public Function ConvToSignedValue(lngValue As Long) As IntegerIf lngValue <= 32767 Then
ConvToSignedValue = CInt(lngValue)
End If
Exit Function
ConvToSignedValue = CInt(lngValue - 65535)
Keeping this knowledge in mind, we can continue. It is advisable to ensure that Gamma Ramp Support is in fact present within the computer's hardware before proceeding:
Dim dx As New DirectX7
Dim dd As DirectDraw7
Dim hwCaps As DDCAPS
Dim helCaps As DDCAPSSet dd = dx.DirectDrawCreate("")
This code will create the DirectDraw object and then poll it for capabilities. If the DDSCAPS2_PRIMARYGAMMA capability is not
present within the hwCaps.lCaps2 then an error message is display and execution stops.
dd.GetCaps hwCaps, helCaps
If (hwCaps.lCaps2 And DDCAPS2_PRIMARYGAMMA) = 0 Then
MsgBox "Your system does not have Gamma Ramp Support", vbOKOnly, "No Gamma Support"
End If
End
Now, if the computer passes this test then we can set up a primary surface and use it to produce a Gamma Control. Note, Gamma Controls can ONLY be used on primary surfaces. The following code assumes a primary surface has been set up appropriately:
Dim GammaControler As DirectDrawGammaControl
Set GammaControler = Primary.GetDirectDrawGammaControl
Dim GammaRamp As DDGAMMARAMP
Dim OriginalRamp As DDGAMMARAMPGammaControler.GetGammaRamp DDSGR_DEFAULT, OriginalRamp
Public Sub SetGamma(bytRed As Byte, bytGreen As Byte, bytBlue As Byte)
Dim i as Integer
End Sub
For i = 0 To 255
GammaRamp.red(i) = ConvToSignedValue(ConvToUnSignedValue(OriginalRamp.red(i)) * bytRed / 100)
Next
GammaRamp.green(i) = ConvToSignedValue(ConvToUnSignedValue(OriginalRamp.green(i)) * bytGreen / 100)
GammaRamp.blue(i) = ConvToSignedValue(ConvToUnSignedValue(OriginalRamp.blue(i)) * bytBlue / 100)
GammaControler.SetGammaRamp DDSGR_DEFAULT, GammaRamp
Now the technical aspect involved in utilizing the Gamma Control may sound somewhat daunting, but I assure you it is very simple. Have a look at my sample project, and you'll see just how easy it is.