gamma/contrast system reworked

moveref
mrcheko 10 years ago
parent 49e2b14d05
commit 04d95810d1

@ -358,6 +358,8 @@ void OMW::Engine::prepareEngine (Settings::Manager & settings)
windowSettings.icon = "openmw.png";
std::string aa = settings.getString("antialiasing", "Video");
windowSettings.fsaa = (aa.substr(0, 4) == "MSAA") ? aa.substr(5, aa.size()-5) : "0";
windowSettings.gamma = Settings::Manager::getFloat("gamma", "General");
windowSettings.contrast = Settings::Manager::getFloat("contrast", "General");
SDL_SetHint(SDL_HINT_VIDEO_MINIMIZE_ON_FOCUS_LOSS,
settings.getBool("minimize on focus loss", "Video") ? "1" : "0");

@ -757,6 +757,10 @@ void RenderingManager::processChangedSettings(const Settings::CategorySettingVec
changeRes = true;
else if (it->second == "field of view" && it->first == "General")
mRendering.setFov(Settings::Manager::getFloat("field of view", "General"));
else if ((it->second == "gamma" || it->second == "contrast") && it->first == "General")
{
mRendering.setWindowGammaContrast(Settings::Manager::getFloat("gamma", "General"), Settings::Manager::getFloat("contrast", "General"));
}
else if ((it->second == "texture filtering" && it->first == "General")
|| (it->second == "anisotropy" && it->first == "General"))
{

@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<MyGUI type="Layout" version="3.2.0">
<Widget type="Window" skin="MW_Window" position="0 0 400 426" layer="Windows" name="_Main">
<Widget type="Window" skin="MW_Window" position="0 0 400 505" layer="Windows" name="_Main">
<Property key="MinSize" value="430 446"/>
<Widget type="TabControl" skin="TabControl" position="8 8 368 340" align="Stretch" name="SettingsTab">
<Widget type="TabControl" skin="TabControl" position="8 8 368 430" align="Stretch" name="SettingsTab">
<Property key="ButtonAutoWidth" value="true"/>
<Widget type="TabItem" skin="" position="4 32 360 308">
<Property key="Caption" value=" #{sPrefs} "/>
@ -214,7 +214,7 @@
</Widget>
<Widget type="TabItem" skin="" position="4 32 360 308">
<Property key="Caption" value=" #{sVideo} "/>
<Widget type="TabControl" skin="TabControlInner" position="4 4 352 296" align="Stretch">
<Widget type="TabControl" skin="TabControlInner" position="4 4 352 390" align="Stretch">
<Property key="ButtonAutoWidth" value="true"/>
<Widget type="TabItem" skin="" position="0 28 352 268" align="Stretch">
<Property key="Caption" value=" Video "/>
@ -292,6 +292,32 @@
<Property key="Caption" value="#{sHigh}"/>
<Property key="TextAlign" value="Right"/>
</Widget>
<Widget type="TextBox" skin="NormalText" position="0 268 329 18" align="Left Top" name="GammaText">
<Property key="Caption" value="Gamma Correction"/>
</Widget>
<Widget type="MWScrollBar" skin="MW_HScroll" position="0 292 329 18" align="HStretch Top" name="GammaSlider">
<Property key="Range" value="10000"/>
<Property key="Page" value="300"/>
<UserString key="SettingType" value="Slider"/>
<UserString key="SettingCategory" value="General"/>
<UserString key="SettingName" value="gamma"/>
<UserString key="SettingValueType" value="Float"/>
<UserString key="SettingMin" value="0.1"/>
<UserString key="SettingMax" value="3.0"/>
</Widget>
<Widget type="TextBox" skin="NormalText" position="0 314 329 18" align="Left Top" name="ContrastText">
<Property key="Caption" value="Contrast"/>
</Widget>
<Widget type="MWScrollBar" skin="MW_HScroll" position="0 336 329 18" align="HStretch Top" name="ContrastSlider">
<Property key="Range" value="10000"/>
<Property key="Page" value="300"/>
<UserString key="SettingType" value="Slider"/>
<UserString key="SettingCategory" value="General"/>
<UserString key="SettingName" value="contrast"/>
<UserString key="SettingValueType" value="Float"/>
<UserString key="SettingMin" value="0.1"/>
<UserString key="SettingMax" value="2.0"/>
</Widget>
</Widget>
<Widget type="TabItem" skin="" position="0 28 352 268">
<Property key="Caption" value=" Detail "/>
@ -470,7 +496,7 @@
</Widget>
</Widget>
</Widget>
<Widget type="AutoSizedButton" skin="MW_Button" position="321 355 56 24" align="Right Bottom" name="OkButton">
<Widget type="AutoSizedButton" skin="MW_Button" position="320 440 56 24" align="Right Bottom" name="OkButton">
<Property key="ExpandDirection" value="Left"/>
<Property key="Caption" value="#{sOK}"/>
</Widget>

@ -48,6 +48,8 @@ werewolf overlay = true
[General]
# Camera field of view
field of view = 55
gamma = 1.34
contrast = 0.98
# Texture filtering mode. valid values:
# none

@ -23,6 +23,12 @@
using namespace Ogre;
using namespace OEngine::Render;
OgreRenderer::~OgreRenderer()
{
cleanup();
// restore system gamma ramp
SDL_SetWindowGammaRamp(mSDLWindow, mOldSystemGammaRamp, &mOldSystemGammaRamp[256], &mOldSystemGammaRamp[512]);
}
void OgreRenderer::cleanup()
{
@ -138,6 +144,8 @@ void OgreRenderer::createWindow(const std::string &title, const WindowSettings&
helper.setWindowIcon(settings.icon);
mWindow = helper.getWindow();
SDL_GetWindowGammaRamp(mSDLWindow, mOldSystemGammaRamp, &mOldSystemGammaRamp[256], &mOldSystemGammaRamp[512]);
setWindowGammaContrast(settings.gamma, settings.contrast);
// create the semi-transparent black background texture used by the GUI.
// has to be created in code with TU_DYNAMIC_WRITE_ONLY param
@ -161,6 +169,24 @@ void OgreRenderer::createWindow(const std::string &title, const WindowSettings&
mCamera->setAspectRatio(Real(mView->getActualWidth()) / Real(mView->getActualHeight()));
}
void OgreRenderer::setWindowGammaContrast(float gamma, float contrast)
{
Uint16 red[256], green[256], blue[256];
for (int i = 0; i < 256; i++)
{
float k = i/256.0f;
k = (k - 0.5f) * contrast + 0.5f;
k = pow(k, 1.f/gamma);
k *= 256;
float value = k*256;
if (value > 65535) value = 65535;
else if (value < 0) value = 0;
red[i] = green[i] = blue[i] = value;
}
SDL_SetWindowGammaRamp(mSDLWindow, red, green, blue);
}
void OgreRenderer::adjustCamera(float fov, float nearClip)
{
mCamera->setNearClipDistance(nearClip);

@ -42,6 +42,8 @@ namespace OEngine
int screen;
std::string fsaa;
std::string icon;
float gamma;
float contrast;
};
class WindowSizeListener
@ -67,6 +69,9 @@ namespace OEngine
int mWindowHeight;
bool mOutstandingResize;
// Store system gamma ramp on window creation. Restore system gamma ramp on exit
uint16_t mOldSystemGammaRamp[256*3];
public:
OgreRenderer()
: mRoot(NULL)
@ -83,7 +88,7 @@ namespace OEngine
{
}
~OgreRenderer() { cleanup(); }
~OgreRenderer();
/** Configure the renderer. This will load configuration files and
set up the Root and logging classes. */
@ -95,6 +100,8 @@ namespace OEngine
/// Create a window with the given title
void createWindow(const std::string &title, const WindowSettings& settings);
void setWindowGammaContrast(float gamma, float contrast);
/// Set up the scene manager, camera and viewport
void adjustCamera(
float fov=55, // Field of view angle

Loading…
Cancel
Save