I'm trying to load dynamic textures on runtime. My steps are separated in this way :
1. Convert my custom image data to an ::Ogre::Image
2. Create a manual texture with ::Ogre::TextureManager::createManual OR with ::Ogre::TextureManager::create
3. Load the image into the texture
4. Set the texture to a material somewhere else in the code
Between each steps, i can check my image data by exporting them to .jpg with image.save() after step 1/3 and visualise the texture after step 4 in the Ogre Engine. JPG data look fine and correspond to my real image, the texture on the scene looks like this : It seems that it is the default Texture when it has not been set, am i right?
Because my texture creation and it's allocation to the material are made in different places in my code, I tried to check if I got the same pointer when I create the texture with the TextureManager and when i'm getting it before calling setTextureUnitState. I've got the same pointers (pRep / pInfo) so I'm really stuck in this problem...
Here are some samples of my code :
* Code to generate the texture :
Code: Select all
::Ogre::Image imageOgre = convertMyImageToOgreImage( myImage );
imageOgre.save("monImage.jpg"); // Check if conversion is OK
// Old loading image on the texture, same error appears
// ::Ogre::TextureManager::getSingletonPtr()->loadImage(
// m_textureName,
// myImage->getName(),
// ::Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
// imageOgre);
::Ogre::TexturePtr tex = ::Ogre::TextureManager::getSingletonPtr()->createManual(
m_textureName,
::Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
::Ogre::TEX_TYPE_2D,
imageOgre.getWidth(),
imageOgre.getHeight(),
0, ::Ogre::PF_R8G8B8,
::Ogre::TU_DYNAMIC_WRITE_ONLY);
tex->loadImage(imageOgre);
// Check if Texture image allocation is OK
// Declare buffer
const size_t buffSize = (tex->getWidth() * tex->getHeight() * 3);
unsigned char *data = OGRE_ALLOC_T(unsigned char,buffSize,Ogre::MEMCATEGORY_GENERAL);
// Clear buffer
memset(data, 0, buffSize);
// Setup Image with correct settings
Ogre::Image i;
i.loadDynamicImage(data, tex->getWidth(), tex->getHeight(), 1, Ogre::PF_R8G8B8, true);
// Copy Texture buffer contents to image buffer
Ogre::HardwarePixelBufferSharedPtr buf = tex->getBuffer();
const Ogre::PixelBox destBox = i.getPixelBox();
buf->blitToMemory(destBox);
// Save to disk!
i.save("texImage.jpg");
Code: Select all
// Try to find textureName (just to check pRep and PInfo value)
::Ogre::TexturePtr texture = ::Ogre::TextureManager::getSingletonPtr()->getByName(
m_textureName, ::Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
if (!texture.isNull())
{
m_material->getTechnique(0)->getPass(0)->createTextureUnitState(m_textureName);
}
Thanks