diff --git a/components/fontloader/fontloader.cpp b/components/fontloader/fontloader.cpp index 7635c43da..131336683 100644 --- a/components/fontloader/fontloader.cpp +++ b/components/fontloader/fontloader.cpp @@ -12,6 +12,7 @@ #include #include #include +#include #include @@ -275,18 +276,13 @@ namespace Gui std::string textureName = name; - osg::ref_ptr image = new osg::Image; - - image->allocateImage(width, height, 1, GL_RGBA, GL_UNSIGNED_BYTE); - assert (image->isDataContiguous()); - - memcpy(image->data(), &textureData[0], textureData.size()); - - osg::ref_ptr texture = new osg::Texture2D; - texture->setImage(image); - if (exportToFile) { + osg::ref_ptr image = new osg::Image; + image->allocateImage(width, height, 1, GL_RGBA, GL_UNSIGNED_BYTE); + assert (image->isDataContiguous()); + memcpy(image->data(), &textureData[0], textureData.size()); + std::cout << "Writing " << resourceName + ".png" << std::endl; osgDB::writeImageFile(*image, resourceName + ".png"); } @@ -295,9 +291,23 @@ namespace Gui MyGUI::ResourceManualFont* font = static_cast( MyGUI::FactoryManager::getInstance().createObject("Resource", "ResourceManualFont")); mFonts.push_back(font); + + MyGUI::ITexture* tex = MyGUI::RenderManager::getInstance().createTexture(bitmapFilename); + tex->createManual(width, height, MyGUI::TextureUsage::Write, MyGUI::PixelFormat::R8G8B8A8); + unsigned char* texData = reinterpret_cast(tex->lock(MyGUI::TextureUsage::Write)); + memcpy(texData, &textureData[0], textureData.size()); + tex->unlock(); + + font->setSource(bitmapFilename); + + // Using ResourceManualFont::setTexture, enable for MyGUI 3.2.3 + /* + osg::ref_ptr texture = new osg::Texture2D; + texture->setImage(image); osgMyGUI::OSGTexture* myguiTex = new osgMyGUI::OSGTexture(texture); mTextures.push_back(myguiTex); font->setTexture(myguiTex); + */ // We need to emulate loading from XML because the data members are private as of mygui 3.2.0 MyGUI::xml::Document xmlDocument; diff --git a/components/myguiplatform/myguirendermanager.cpp b/components/myguiplatform/myguirendermanager.cpp index bf1d66fe8..e00b0221d 100644 --- a/components/myguiplatform/myguirendermanager.cpp +++ b/components/myguiplatform/myguirendermanager.cpp @@ -453,8 +453,12 @@ bool RenderManager::isFormatSupported(MyGUI::PixelFormat /*format*/, MyGUI::Text MyGUI::ITexture* RenderManager::createTexture(const std::string &name) { - MapTexture::const_iterator item = mTextures.find(name); - MYGUI_PLATFORM_ASSERT(item == mTextures.end(), "Texture '"<second; + mTextures.erase(item); + } OSGTexture* texture = new OSGTexture(name, mTextureManager); mTextures.insert(std::make_pair(name, texture));