mirror of
https://github.com/yquake2/yquake2remaster.git
synced 2024-11-14 00:41:03 +00:00
Let SDL calculate the gamma ramp now that X11GAMMA and SDL 1.2 are gone.
This commit is contained in:
parent
1b68da9a0f
commit
5ec3bcdb49
1 changed files with 3 additions and 44 deletions
|
@ -50,57 +50,16 @@ GLimp_GetProcAddress (const char* proc)
|
||||||
return SDL_GL_GetProcAddress ( proc );
|
return SDL_GL_GetProcAddress ( proc );
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* from SDL2 SDL_CalculateGammaRamp, adjusted for arbitrary ramp sizes
|
|
||||||
* because xrandr seems to support ramp sizes != 256 (in theory at least)
|
|
||||||
*/
|
|
||||||
void CalculateGammaRamp(float gamma, Uint16* ramp, int len)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
|
|
||||||
/* Input validation */
|
|
||||||
if (gamma < 0.0f ){
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (ramp == NULL) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* 0.0 gamma is all black */
|
|
||||||
if (gamma == 0.0f) {
|
|
||||||
for (i = 0; i < len; ++i) {
|
|
||||||
ramp[i] = 0;
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
} else if (gamma == 1.0f) {
|
|
||||||
/* 1.0 gamma is identity */
|
|
||||||
for (i = 0; i < len; ++i) {
|
|
||||||
ramp[i] = (i << 8) | i;
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
} else {
|
|
||||||
/* Calculate a real gamma ramp */
|
|
||||||
int value;
|
|
||||||
gamma = 1.0f / gamma;
|
|
||||||
for (i = 0; i < len; ++i) {
|
|
||||||
value = (int) (pow((double) i / (double) len, gamma) * 65535.0 + 0.5);
|
|
||||||
if (value > 65535) {
|
|
||||||
value = 65535;
|
|
||||||
}
|
|
||||||
ramp[i] = (Uint16) value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
UpdateHardwareGamma(void)
|
UpdateHardwareGamma(void)
|
||||||
{
|
{
|
||||||
float gamma = (vid_gamma->value);
|
float gamma = (vid_gamma->value);
|
||||||
|
|
||||||
Uint16 ramp[256];
|
Uint16 ramp[256];
|
||||||
CalculateGammaRamp(gamma, ramp, 256);
|
SDL_CalculateGammaRamp(gamma, ramp);
|
||||||
|
|
||||||
if(SDL_SetWindowGammaRamp(window, ramp, ramp, ramp) != 0) {
|
if(SDL_SetWindowGammaRamp(window, ramp, ramp, ramp) != 0)
|
||||||
|
{
|
||||||
R_Printf(PRINT_ALL, "Setting gamma failed: %s\n", SDL_GetError());
|
R_Printf(PRINT_ALL, "Setting gamma failed: %s\n", SDL_GetError());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue