Merge remote-tracking branch 'mrcheko/master'

moveref
Marc Zinnschlag 10 years ago
commit ec1df719fe

@ -208,6 +208,7 @@ OMW::Engine::Engine(Files::ConfigurationManager& configurationManager)
OMW::Engine::~Engine() OMW::Engine::~Engine()
{ {
mOgre->restoreWindowGammaRamp();
mEnvironment.cleanup(); mEnvironment.cleanup();
delete mScriptContext; delete mScriptContext;
delete mOgre; delete mOgre;
@ -382,6 +383,8 @@ void OMW::Engine::prepareEngine (Settings::Manager & settings)
// Create sound system // Create sound system
mEnvironment.setSoundManager (new MWSound::SoundManager(mUseSound)); mEnvironment.setSoundManager (new MWSound::SoundManager(mUseSound));
mOgre->setWindowGammaContrast(Settings::Manager::getFloat("gamma", "General"), Settings::Manager::getFloat("contrast", "General"));
if (!mSkipMenu) if (!mSkipMenu)
{ {
std::string logo = mFallbackMap["Movies_Company_Logo"]; std::string logo = mFallbackMap["Movies_Company_Logo"];

@ -182,6 +182,20 @@ namespace MWGui
getWidget(mRefractionButton, "RefractionButton"); getWidget(mRefractionButton, "RefractionButton");
getWidget(mDifficultySlider, "DifficultySlider"); getWidget(mDifficultySlider, "DifficultySlider");
#ifndef WIN32
// hide gamma controls since it currently does not work under Linux
MyGUI::ScrollBar *gammaSlider;
getWidget(gammaSlider, "GammaSlider");
gammaSlider->setVisible(false);
MyGUI::TextBox *textBox;
getWidget(textBox, "GammaText");
textBox->setVisible(false);
getWidget(textBox, "GammaTextDark");
textBox->setVisible(false);
getWidget(textBox, "GammaTextLight");
textBox->setVisible(false);
#endif
mMainWidget->castType<MyGUI::Window>()->eventWindowChangeCoord += MyGUI::newDelegate(this, &SettingsWindow::onWindowResize); mMainWidget->castType<MyGUI::Window>()->eventWindowChangeCoord += MyGUI::newDelegate(this, &SettingsWindow::onWindowResize);
mOkButton->eventMouseButtonClick += MyGUI::newDelegate(this, &SettingsWindow::onOkButtonClicked); mOkButton->eventMouseButtonClick += MyGUI::newDelegate(this, &SettingsWindow::onOkButtonClicked);

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

@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<MyGUI type="Layout" version="3.2.0"> <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 485" layer="Windows" name="_Main">
<Property key="MinSize" value="430 446"/> <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 405" align="Stretch" name="SettingsTab">
<Property key="ButtonAutoWidth" value="true"/> <Property key="ButtonAutoWidth" value="true"/>
<Widget type="TabItem" skin="" position="4 32 360 308"> <Widget type="TabItem" skin="" position="4 32 360 308">
<Property key="Caption" value=" #{sPrefs} "/> <Property key="Caption" value=" #{sPrefs} "/>
@ -214,7 +214,7 @@
</Widget> </Widget>
<Widget type="TabItem" skin="" position="4 32 360 308"> <Widget type="TabItem" skin="" position="4 32 360 308">
<Property key="Caption" value=" #{sVideo} "/> <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"/> <Property key="ButtonAutoWidth" value="true"/>
<Widget type="TabItem" skin="" position="0 28 352 268" align="Stretch"> <Widget type="TabItem" skin="" position="0 28 352 268" align="Stretch">
<Property key="Caption" value=" Video "/> <Property key="Caption" value=" Video "/>
@ -292,6 +292,27 @@
<Property key="Caption" value="#{sHigh}"/> <Property key="Caption" value="#{sHigh}"/>
<Property key="TextAlign" value="Right"/> <Property key="TextAlign" value="Right"/>
</Widget> </Widget>
<Widget type="TextBox" skin="NormalText" position="0 268 329 18" align="Left Top" name="GammaText">
<Property key="Caption" value="#{sGamma_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="SandText" position="0 316 329 18" align="Left Top" name="GammaTextDark">
<Property key="Caption" value="#{sDark_Gamma}"/>
<Property key="TextAlign" value="Left"/>
</Widget>
<Widget type="TextBox" skin="SandText" position="0 316 329 18" align="Right Top" name="GammaTextLight">
<Property key="Caption" value="#{sLight_Gamma}"/>
<Property key="TextAlign" value="Right"/>
</Widget>
</Widget> </Widget>
<Widget type="TabItem" skin="" position="0 28 352 268"> <Widget type="TabItem" skin="" position="0 28 352 268">
<Property key="Caption" value=" Detail "/> <Property key="Caption" value=" Detail "/>
@ -470,7 +491,7 @@
</Widget> </Widget>
</Widget> </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 420 56 24" align="Right Bottom" name="OkButton">
<Property key="ExpandDirection" value="Left"/> <Property key="ExpandDirection" value="Left"/>
<Property key="Caption" value="#{sOK}"/> <Property key="Caption" value="#{sOK}"/>
</Widget> </Widget>

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

@ -23,6 +23,11 @@
using namespace Ogre; using namespace Ogre;
using namespace OEngine::Render; using namespace OEngine::Render;
OgreRenderer::~OgreRenderer()
{
cleanup();
restoreWindowGammaRamp();
}
void OgreRenderer::cleanup() void OgreRenderer::cleanup()
{ {
@ -140,6 +145,7 @@ void OgreRenderer::createWindow(const std::string &title, const WindowSettings&
helper.setWindowIcon(settings.icon); helper.setWindowIcon(settings.icon);
mWindow = helper.getWindow(); mWindow = helper.getWindow();
SDL_GetWindowGammaRamp(mSDLWindow, mOldSystemGammaRamp, &mOldSystemGammaRamp[256], &mOldSystemGammaRamp[512]);
// create the semi-transparent black background texture used by the GUI. // create the semi-transparent black background texture used by the GUI.
// has to be created in code with TU_DYNAMIC_WRITE_ONLY param // has to be created in code with TU_DYNAMIC_WRITE_ONLY param
@ -163,6 +169,35 @@ void OgreRenderer::createWindow(const std::string &title, const WindowSettings&
mCamera->setAspectRatio(Real(mView->getActualWidth()) / Real(mView->getActualHeight())); mCamera->setAspectRatio(Real(mView->getActualWidth()) / Real(mView->getActualHeight()));
} }
void OgreRenderer::setWindowGammaContrast(float gamma, float contrast)
{
if (mSDLWindow == NULL) return;
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;
}
if (SDL_SetWindowGammaRamp(mSDLWindow, red, green, blue) < 0)
std::cout << "Couldn't set gamma: " << SDL_GetError() << std::endl;
}
void OgreRenderer::restoreWindowGammaRamp()
{
if (mSDLWindow != NULL)
{
SDL_SetWindowGammaRamp(mSDLWindow, mOldSystemGammaRamp, &mOldSystemGammaRamp[256], &mOldSystemGammaRamp[512]);
}
}
void OgreRenderer::adjustCamera(float fov, float nearClip) void OgreRenderer::adjustCamera(float fov, float nearClip)
{ {
mCamera->setNearClipDistance(nearClip); mCamera->setNearClipDistance(nearClip);

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

Loading…
Cancel
Save