Brought back non-relative gamma ramp generation.

This commit is contained in:
Camilla Berglund 2011-09-20 15:44:54 +02:00
parent e31042c0dc
commit 554bf5d321

View File

@ -62,10 +62,6 @@ GLFWAPI void glfwSetGamma(float gamma)
for (i = 0; i < size; i++) for (i = 0; i < size; i++)
{ {
float value = (float) i / ((float) (size - 1)); float value = (float) i / ((float) (size - 1));
int diffRed, diffGreen, diffBlue, newRed, newGreen, newBlue, pow1;
// Reference our gamma 1.0f
pow1 = value * 65535.f + 0.5;
// Apply gamma // Apply gamma
value = (float) pow(value, 1.f / gamma) * 65535.f + 0.5f; value = (float) pow(value, 1.f / gamma) * 65535.f + 0.5f;
@ -76,20 +72,10 @@ GLFWAPI void glfwSetGamma(float gamma)
else if (value > 65535.f) else if (value > 65535.f)
value = 65535.f; value = 65535.f;
// Use original gamma as reference // Set the gamma ramp values
diffRed = _glfwLibrary.originalRamp.red[i] - pow1; ramp.red[i] = (unsigned short) value;
diffGreen = _glfwLibrary.originalRamp.green[i] - pow1; ramp.green[i] = (unsigned short) value;
diffBlue = _glfwLibrary.originalRamp.blue[i] - pow1; ramp.blue[i] = (unsigned short) value;
// Calculate new values
newRed = diffRed + (unsigned short) value;
newGreen = diffGreen + (unsigned short) value;
newBlue = diffBlue + (unsigned short) value;
// Set the gamma ramp values (whilst clamping)
ramp.red[i] = newRed > 65535 ? 65535 : newRed < 0 ? 0 : newRed;
ramp.green[i] = newGreen > 65535 ? 65535 : newGreen < 0 ? 0 : newGreen;
ramp.blue[i] = newBlue > 65535 ? 65535 : newBlue < 0 ? 0 : newBlue;
} }
glfwSetGammaRamp(&ramp); glfwSetGammaRamp(&ramp);