Use openmw.png for SDL_SetWindowIcon

actorid
scrawl 12 years ago
parent 705488ddfb
commit 403704b92a

@ -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";

@ -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

@ -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

@ -84,6 +84,7 @@ set(MYGUI_FILES
smallbars.png
DejaVuLGCSansMono.ttf
markers.png
../launcher/images/openmw.png
)

@ -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, &params);
// 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;
}

@ -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<Ogre::ParticleAffectorFactory*> 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

Loading…
Cancel
Save