From 403704b92ac2b9c47c2f48a0f86225be2f99177b Mon Sep 17 00:00:00 2001 From: scrawl Date: Wed, 12 Jun 2013 16:15:04 +0200 Subject: [PATCH] Use openmw.png for SDL_SetWindowIcon --- apps/openmw/engine.cpp | 1 + apps/openmw/mwrender/renderingmanager.cpp | 4 +- extern/sdl4ogre/sdlinputwrapper.cpp | 4 +- files/mygui/CMakeLists.txt | 1 + libs/openengine/ogre/renderer.cpp | 67 ++++++++++++++++++++++- libs/openengine/ogre/renderer.hpp | 6 ++ 6 files changed, 78 insertions(+), 5 deletions(-) diff --git a/apps/openmw/engine.cpp b/apps/openmw/engine.cpp index 92904b166..95f6e6e92 100644 --- a/apps/openmw/engine.cpp +++ b/apps/openmw/engine.cpp @@ -421,6 +421,7 @@ void OMW::Engine::prepareEngine (Settings::Manager & settings) windowSettings.window_x = settings.getInt("resolution x", "Video"); windowSettings.window_y = settings.getInt("resolution y", "Video"); windowSettings.vsync = settings.getBool("vsync", "Video"); + 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"; diff --git a/apps/openmw/mwrender/renderingmanager.cpp b/apps/openmw/mwrender/renderingmanager.cpp index df5293d73..bb187d8ca 100644 --- a/apps/openmw/mwrender/renderingmanager.cpp +++ b/apps/openmw/mwrender/renderingmanager.cpp @@ -131,7 +131,7 @@ RenderingManager::RenderingManager(OEngine::Render::OgreRenderer& _rend, const b Ogre::TextureManager::getSingleton().setMemoryBudget(126*1024*1024); Ogre::MeshManager::getSingleton().setMemoryBudget(64*1024*1024); - ResourceGroupManager::getSingleton().initialiseAllResourceGroups(); + Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups(); // disable unsupported effects if (!Settings::Manager::getBool("shaders", "Objects")) @@ -312,7 +312,7 @@ void RenderingManager::update (float duration, bool paused) MWWorld::Ptr player = world->getPlayer().getPlayer(); int blind = MWWorld::Class::get(player).getCreatureStats(player).getMagicEffects().get(MWMechanics::EffectKey(ESM::MagicEffect::Blind)).mMagnitude; - mRendering.getFader()->setFactor(1.f-(blind / 100.f)); + mRendering.getFader()->setFactor(std::max(0.f, 1.f-(blind / 100.f))); setAmbientMode(); // player position diff --git a/extern/sdl4ogre/sdlinputwrapper.cpp b/extern/sdl4ogre/sdlinputwrapper.cpp index a500bc531..70a775113 100644 --- a/extern/sdl4ogre/sdlinputwrapper.cpp +++ b/extern/sdl4ogre/sdlinputwrapper.cpp @@ -205,8 +205,8 @@ namespace SFO SDL_GetWindowSize(mSDLWindow, &width, &height); - const int FUDGE_FACTOR_X = width / 8; - const int FUDGE_FACTOR_Y = height / 8; + const int FUDGE_FACTOR_X = width; + const int FUDGE_FACTOR_Y = height; //warp the mouse if it's about to go outside the window if(evt.x - FUDGE_FACTOR_X < 0 || evt.x + FUDGE_FACTOR_X > width diff --git a/files/mygui/CMakeLists.txt b/files/mygui/CMakeLists.txt index af695ac6c..1ec1e08cb 100644 --- a/files/mygui/CMakeLists.txt +++ b/files/mygui/CMakeLists.txt @@ -84,6 +84,7 @@ set(MYGUI_FILES smallbars.png DejaVuLGCSansMono.ttf markers.png + ../launcher/images/openmw.png ) diff --git a/libs/openengine/ogre/renderer.cpp b/libs/openengine/ogre/renderer.cpp index 66472cda0..193e094bc 100644 --- a/libs/openengine/ogre/renderer.cpp +++ b/libs/openengine/ogre/renderer.cpp @@ -54,6 +54,9 @@ void OgreRenderer::cleanup() delete mRoot; mRoot = NULL; + if (mWindowIconSurface) + SDL_FreeSurface(mWindowIconSurface); + // If we don't do this, the desktop resolution is not restored on exit SDL_SetWindowFullscreen(mSDLWindow, 0); @@ -289,7 +292,6 @@ void OgreRenderer::createWindow(const std::string &title, const WindowSettings& | (settings.fullscreen ? SDL_WINDOW_FULLSCREEN : 0) ); - //get the native whnd struct SDL_SysWMinfo wmInfo; SDL_VERSION(&wmInfo.version); @@ -330,6 +332,13 @@ void OgreRenderer::createWindow(const std::string &title, const WindowSettings& mWindow = mRoot->createRenderWindow(title, settings.window_x, settings.window_y, settings.fullscreen, ¶ms); + // Set the window icon + if (settings.icon != "") + { + mWindowIconSurface = ogreTextureToSDLSurface(settings.icon); + SDL_SetWindowIcon(mSDLWindow, mWindowIconSurface); + } + // create the semi-transparent black background texture used by the GUI. // has to be created in code with TU_DYNAMIC_WRITE_ONLY param // so that it can be modified at runtime. @@ -388,3 +397,59 @@ void OgreRenderer::setFov(float fov) { mCamera->setFOVy(Degree(fov)); } + +SDL_Surface* OgreRenderer::ogreTextureToSDLSurface(const std::string& name) +{ + Ogre::TexturePtr texture = Ogre::TextureManager::getSingleton().load(name, Ogre::ResourceGroupManager::AUTODETECT_RESOURCE_GROUP_NAME); + if (texture.isNull()) + { + std::stringstream error; + error << "Window icon not found: " << name; + throw std::runtime_error(error.str()); + } + Ogre::Image image; + texture->convertToImage(image); + + SDL_Surface* surface = SDL_CreateRGBSurface(0,texture->getWidth(),texture->getHeight(),32,0xFF000000,0x00FF0000,0x0000FF00,0x000000FF); + + //copy the Ogre texture to an SDL surface + for(size_t x = 0; x < texture->getWidth(); ++x) + { + for(size_t y = 0; y < texture->getHeight(); ++y) + { + Ogre::ColourValue clr = image.getColourAt(x, y, 0); + + //set the pixel on the SDL surface to the same value as the Ogre texture's + int bpp = surface->format->BytesPerPixel; + /* Here p is the address to the pixel we want to set */ + Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; + Uint32 pixel = SDL_MapRGBA(surface->format, clr.r*255, clr.g*255, clr.b*255, clr.a*255); + switch(bpp) { + case 1: + *p = pixel; + break; + + case 2: + *(Uint16 *)p = pixel; + break; + + case 3: + if(SDL_BYTEORDER == SDL_BIG_ENDIAN) { + p[0] = (pixel >> 16) & 0xff; + p[1] = (pixel >> 8) & 0xff; + p[2] = pixel & 0xff; + } else { + p[0] = pixel & 0xff; + p[1] = (pixel >> 8) & 0xff; + p[2] = (pixel >> 16) & 0xff; + } + break; + + case 4: + *(Uint32 *)p = pixel; + break; + } + } + } + return surface; +} diff --git a/libs/openengine/ogre/renderer.hpp b/libs/openengine/ogre/renderer.hpp index 60934dda6..8b73675c3 100644 --- a/libs/openengine/ogre/renderer.hpp +++ b/libs/openengine/ogre/renderer.hpp @@ -32,6 +32,7 @@ #endif struct SDL_Window; +struct SDL_Surface; namespace Ogre { @@ -56,6 +57,7 @@ namespace OEngine bool fullscreen; int window_x, window_y; std::string fsaa; + std::string icon; }; #if defined(__APPLE__) && !defined(__LP64__) @@ -80,6 +82,7 @@ namespace OEngine #endif Ogre::RenderWindow *mWindow; SDL_Window *mSDLWindow; + SDL_Surface *mWindowIconSurface; Ogre::SceneManager *mScene; Ogre::Camera *mCamera; Ogre::Viewport *mView; @@ -103,6 +106,8 @@ namespace OEngine std::vector mAffectorFactories; bool logging; + SDL_Surface* ogreTextureToSDLSurface(const std::string& name); + public: OgreRenderer() : mRoot(NULL) @@ -111,6 +116,7 @@ namespace OEngine , mScene(NULL) , mCamera(NULL) , mView(NULL) + , mWindowIconSurface(NULL) #ifdef ENABLE_PLUGIN_CgProgramManager , mCgPlugin(NULL) #endif