-void Texture_Gamma (void)
-{
- int i, adjusted;
- double invgamma;
-
- texture_gamma = 1;
- if ((i = COM_CheckParm("-gamma")))
- texture_gamma = atof(com_argv[i+1]);
- texture_gamma = bound(0.1, texture_gamma, 5.0);
-
- if (texture_gamma == 1) // LordHavoc: dodge the math
- {
- for (i = 0;i < 256;i++)
- texgamma[i] = i;
- }
- else
- {
- invgamma = 1.0 / texture_gamma;
- for (i = 0;i < 256;i++)
- {
- adjusted = (int) ((255.0 * pow((double) i / 255.0, invgamma)) + 0.5);
- texgamma[i] = bound(0, adjusted, 255);
- }
- }
-}
-
-qboolean hardwaregammasupported = false;
-void VID_UpdateGamma(qboolean force)
-{
- static float cachegamma = -1, cachebrightness = -1, cachecontrast = -1, cachelighthalf = -1;
- if (!force && vid_gamma.value == cachegamma && vid_brightness.value == cachebrightness && vid_contrast.value == cachecontrast && lighthalf == cachelighthalf)
- return;
-
- if (vid_gamma.value < 0.1)
- Cvar_SetValue("vid_gamma", 0.1);
- if (vid_gamma.value > 5.0)
- Cvar_SetValue("vid_gamma", 5.0);
-
- if (vid_brightness.value < 1.0)
- Cvar_SetValue("vid_brightness", 1.0);
- if (vid_brightness.value > 5.0)
- Cvar_SetValue("vid_brightness", 5.0);
-
- if (vid_contrast.value < 0.2)
- Cvar_SetValue("vid_contrast", 0.2);
- if (vid_contrast.value > 1)
- Cvar_SetValue("vid_contrast", 1);
-
- cachegamma = vid_gamma.value;
- cachebrightness = vid_brightness.value;
- cachecontrast = vid_contrast.value;
- cachelighthalf = lighthalf;
-
- hardwaregammasupported = VID_SetGamma((cachelighthalf ? 2.0f : 1.0f), cachegamma, cachebrightness * cachecontrast, 1 - cachecontrast);
- if (!hardwaregammasupported)
- Con_Printf("Hardware gamma not supported.\n");
-}
-
-void Gamma_Init(void)
-{
- Cvar_RegisterVariable(&vid_gamma);
- Cvar_RegisterVariable(&vid_brightness);
- Cvar_RegisterVariable(&vid_contrast);
-}
-