Dynamic Textures and Prefabricated planes

Kodachi_Garou

07-08-2006 16:10:32

I'm trying to render a dynamic texture from an image file using the prefabricated plane from scene manager but I've run into a number of difficulties. I'll try to be brief and to the point in each of them:

1 - Creating the texture

TexturePtr texturePtr = TextureManager.Instance.CreateManual(
textureName, groupName, TextureType.TEX_TYPE_2D,
512, 512, 0, PixelFormat.PF_BYTE_BGRA);

mTexture = texturePtr.Get();
HardwarePixelBufferSharedPtr bufferSharedPtr = mTexture.getBuffer();
mBuffer = bufferSharedPtr.Get();

ResourcePtr resourcePtr = MaterialManager.Instance.Create(materialName, groupName);
MaterialPtr materialPtr = new MaterialPtr(ResourcePtr.getCPtr(resourcePtr).Handle, false);
TextureUnitState tState = materialPtr.Get().GetTechnique(0).getPass(0).createTextureUnitState(textureName);
tState.SetTextureAddressingMode(TextureUnitState.TextureAddressingMode.TAM_CLAMP);


This is the code to dynamically create the texture. And next the code to write to the texture:

public void WriteFrame(byte[] frame)
{
mBuffer.Lock(HardwareBuffer.LockOptions.HBL_NORMAL);

PixelBox pBox = mBuffer.getCurrentLock();
MemoryDataStream mds = new MemoryDataStream(pBox.data, 512 * 512 * 3, false);
mds.SetBuffer(frame, 0, (uint)frame.Length);

mBuffer.Unlock();
}


2 - Loading images

I've attempted to load different types of images into the texture and all of them have their colors messed up, even though I've tried numerous convertion schemes.

Marching through the forums I find that everyone seems to use either BGRA and force convert to this format or Ogre::Image, which, I think, isn't yet available to ODN.

My question is then: Is it necessary to force convert to BGRA, or can we use other pixel formats? Also, where is Ogre::Image?

3 - Creating the render entity

Entity videoBox = mSceneManager.CreateEntity("vidBox", SceneManager.PrefabType.PT_PLANE);

This is the type of code used to create my render plane. Unfortunately, my dynamically created texture doesn't cover the entire area of the plane, despite the TAM_CLAMP parameter. Any idea why this happens?

Thanks for all the attention,