In Ogre3D, how to export texture pixel value to physical memory

132 views Asked by At

I am using Ogre3D.

I have a texture defined as:

rtt_texture = Ogre::TextureManager::getSingleton().createManual("RttTex", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, Ogre::TEX_TYPE_2D, texWidth, texHeight, 0, Ogre::PF_R8G8B8, Ogre::TU_RENDERTARGET);

I am trying to use the following code to copy its pixel value to memory, but the data I got differs from what has been rendered:

unsigned char* data = new unsigned char[texWidth * texHeight * 3];
data = (unsigned char*)rtt_texture->getBuffer()->lock(0, texWidth*texHeight*3, Ogre::HardwareBuffer::HBL_READ_ONLY);

Are there any errors here?

1

There are 1 answers

0
shapeare On BEST ANSWER

I found that I actually need to replace

texWidth * texHeight * 3

everywhere with

texWidth * texHeight * 4