今天做到小地图这块。网上百了点资料。也不是很全。看了ogre1.70里面的几个例子。从动态纹理 企鹅扫雪 那个例子中得到启发。先用一个做好的地图缩略图。然后再创建一个同样大小的图片。两张图片进行颜色混合。然后采用overlay来显示我们创建的材质文件。
************************困扰我的问题出现啦。当只有材质文件时将材质文件设置到某个平面上时。会显示颜色的混合。而当你一旦创建一个*.overlay文件时。混合的效果不再会出现。我想了想。大胆猜测一下。可能是当我们初始化资源时。一旦有了overlay文件。并且材质文件在overlay文件中使用了。那么材质文件就被锁定了。不能再更新了。(有正确或者更合理解释的望赐教)那这种情况怎么办呢?怎么办呢?怎么办呢?******************************
由于不能通过脚本定义overlay那么就动态的定义overlay。这样就解决了问题啦.
具体实现过程
1. 首先在Examples.material文件中加入下面这个材质
material SdkTrays/small_map
{
technique
{
pass
{
texture_unit
{
texture map.png
}
texture_unit
{
texture qingwa
}
}
}
}
2 程序完整代码 只是演示如何动态去对蒙皮图片改变 ---------将注视去掉将会得到不同的效果
#include "ExampleApplication.h" using namespace Ogre; class TutorialApplication : public ExampleApplication { public: TutorialApplication() { } ~TutorialApplication() { } protected: void createScene(void) { mSceneMgr->setSkyBox(true, "Examples/StormySkyBox"); mSceneMgr->setAmbientLight(ColourValue(0.5, 0.5, 0.5)); mSceneMgr->createLight()->setPosition(20, 80, 50); m_mapture=TextureManager::getSingleton().createManual("qingwa","Popular", TEX_TYPE_2D, 100,100, 0, PF_A8R8G8B8, TU_DYNAMIC_WRITE_ONLY); mTexBuf = m_mapture->getBuffer(); mTexBuf->lock(HardwareBuffer::HBL_DISCARD); memset(mTexBuf->getCurrentLock().data, 0xFF, mTexBuf->getSizeInBytes()); mTexBuf->unlock(); m_pSmallmap=Ogre::OverlayManager::getSingletonPtr()->create("smallmap"); m_pMapElement=Ogre::OverlayManager::getSingletonPtr()->createOverlayElement("Panel","wa"); m_pMapElement->setParameter("material","SdkTrays/small_map"); m_pMapElement->setParameter("metrics_mode","pixels"); m_pMapElement->setParameter("horz_align","center"); m_pMapElement->setParameter("width","500"); m_pMapElement->setParameter("height","700"); m_pSmallmap->add2D((Ogre::OverlayContainer *)m_pMapElement); m_pSmallmap->show(); /* mTexBuf->lock(HardwareBuffer::HBL_NORMAL); // get access to raw texel data Ogre::uint32* data = (Ogre::uint32*)mTexBuf->getCurrentLock().data; // go through every texel... for (unsigned int y = 0; y < 100; y++) { for (unsigned int x = 0; x < 100; x++) { *data=0xff0000; data++; } } mTexBuf->unlock();*/ } Ogre::Overlay* m_pSmallmap; Ogre::OverlayElement* m_pMapElement; Ogre::TexturePtr m_mapture; HardwarePixelBufferSharedPtr mTexBuf; }; #if OGRE_PLATFORM == PLATFORM_WIN32 || OGRE_PLATFORM == OGRE_PLATFORM_WIN32 #define WIN32_LEAN_AND_MEAN #include "windows.h" INT WINAPI WinMain(HINSTANCE hInst, HINSTANCE, LPSTR strCmdLine, INT) #else int main(int argc, char **argv) #endif { // Create application object TutorialApplication app; try { app.go(); } catch(Exception& e) { #if OGRE_PLATFORM == PLATFORM_WIN32 || OGRE_PLATFORM == OGRE_PLATFORM_WIN32 MessageBox(NULL, e.getFullDescription().c_str(), "An exception has occurred!", MB_OK | MB_ICONERROR | MB_TASKMODAL); #else fprintf(stderr, "An exception has occurred: %s\n", e.getFullDescription().c_str()); #endif } return 0; }
效果图