Changing Bitmap Texture Map Gamma
 
 
 

In order to change the gamma value of a Bitmap Texture that has been loaded, it is recommended that you reload the bitmap from disk. This can be accomplished using BitmapTex::ReloadBitmapAndUpdate().

In order to assure that bitmap is reloaded with the desired gamma value, you must change the gamma setting of the bitmap info (BitmapInfo) stored in the bitmap texture's parameter block. This must be done prior to the reload.

In order for the custom gamma to take effect when reloading the bitmap, the BMM_CUSTOM_GAMMA flag must be set on the bitmap info using BitmapInfo::SetCustomFlag(). The gamma value itself can be set using the method BitmapInfo::SetCustomGamma().

The following code demonstrates this.

void SetBitmapTextureGamma(BitmapTex* texmap)
{
   IParamBlock2* pb2 = texmap->GetParamBlock(0);
 
  // get the bitmap parameter
  int n = pb2->GetDesc()->NameToIndex("bitmap");
  ParamID id = pb2->GetDesc()->IndexToID(n);        
  PBBitmap* pbBitmap = pb2->GetBitmap(id);
 
  // tell the bitmap info struct to use a gamma value
  pbBitmap->bi.SetCustomFlag( BMM_CUSTOM_GAMMA );
 
   // set a fake gamma value for demonstration purposes
  pbBitmap->bi.SetCustomGamma( 2.5f );
 
   // now reload the bitmap from the disk.
  texmap->ReloadBitmapAndUpdate();
}