Creating dynamic textures
Minimal example of how you can create dynamic textures
Welcome to the new Ogre Wiki!
If you haven't done so already, be sure to visit the Wiki Portal to read about how the wiki works. Especially the Ogre Wiki Overview page.
If you haven't done so already, be sure to visit the Wiki Portal to read about how the wiki works. Especially the Ogre Wiki Overview page.
This is a minimal example of how you can create dynamic textures (and programmatically create materials using them). It doesn't show how to use ManualResourceLoaders, though.
#include "OgreHardwarePixelBuffer.h"// Create the texture TexturePtr texture = TextureManager::getSingleton().createManual( "DynamicTexture", // name ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, TEX_TYPE_2D, // type 256, 256, // width & height 0, // number of mipmaps PF_BYTE_BGRA, // pixel format TU_DEFAULT); // usage; should be TU_DYNAMIC_WRITE_ONLY_DISCARDABLE for // textures updated very often (e.g. each frame) // Get the pixel buffer HardwarePixelBufferSharedPtr pixelBuffer = texture->getBuffer(); // Lock the pixel buffer and get a pixel box pixelBuffer->lock(HardwareBuffer::HBL_NORMAL); // for best performance use HBL_DISCARD! const PixelBox& pixelBox = pixelBuffer->getCurrentLock(); uint8* pDest = static_cast<uint8*>(pixelBox.data); // Fill in some pixel data. This will give a semi-transparent blue, // but this is of course dependent on the chosen pixel format. for (size_t j = 0; j < 256; j++) for(size_t i = 0; i < 256; i++) { *pDest++ = 255; // B *pDest++ = 0; // G *pDest++ = 0; // R *pDest++ = 127; // A } // Unlock the pixel buffer pixelBuffer->unlock(); // Create a material using the texture MaterialPtr material = MaterialManager::getSingleton().create( "DynamicTextureMaterial", // name ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME); material->getTechnique(0)->getPass(0)->createTextureUnitState("DynamicTexture"); material->getTechnique(0)->getPass(0)->setSceneBlending(SBT_TRANSPARENT_ALPHA);
See also
--DWORD 14:58, 29 Apr 2005 (CDT)
Contributors to this page: Beauty
,
OgreWikiBot
and
jacmoe
.
Page last modified on Wednesday 19 of January, 2011 00:43:48 GMT by Beauty
.
The content on this page is licensed under the terms of the Creative Commons Attribution-ShareAlike License.
As an exception, any source code contributed within the content is released into the Public Domain.
Sidebar
Search box
Online users
45
online users

