Difference between revisions of "Rendering to texture (RTT) in CEGUI"
From CEGUI Wiki - Crazy Eddie's GUI System (Open Source)
Line 6: | Line 6: | ||
<source lang="cpp"> | <source lang="cpp"> | ||
− | //Taking some random values as example for a | + | CEGUI::System& ceSystem = CEGUI::System::getSingleton(); |
+ | //Taking some random values as example for a GUIContext size. | ||
int width = 1024; | int width = 1024; | ||
int height = 800; | int height = 800; | ||
Line 12: | Line 13: | ||
// We create a CEGUI texture target and create a GUIContext that will use it. | // We create a CEGUI texture target and create a GUIContext that will use it. | ||
− | CEGUI::TextureTarget* renderTextureTarget = | + | CEGUI::TextureTarget* renderTextureTarget = ceSystem.getRenderer()->createTextureTarget(); |
− | CEGUI::GUIContext* renderGuiContext = | + | CEGUI::GUIContext* renderGuiContext = ceSystem.createGUIContext(static_cast<CEGUI::RenderTarget&>(*renderTextureTarget) ); |
renderTextureTarget->declareRenderSize(size); | renderTextureTarget->declareRenderSize(size); | ||
// We create a BasicImage and set the Texture | // We create a BasicImage and set the Texture | ||
− | + | textureTargetImage = static_cast<CEGUI::BitmapImage*>(&CEGUI::ImageManager::getSingleton().create("BitmapImage", "SomeGroup/MyTexturesName")); | |
− | + | textureTargetImage->setTexture(&renderTextureTarget->getTexture()); | |
// We size the image using a function | // We size the image using a function | ||
Line 32: | Line 33: | ||
if(d_textureTarget) | if(d_textureTarget) | ||
{ | { | ||
− | bool isTextureTargetVerticallyFlipped = | + | bool isTextureTargetVerticallyFlipped = renderTextureTarget->isRenderingInverted(); |
CEGUI::Rectf renderArea; | CEGUI::Rectf renderArea; | ||
− | if(isTextureTargetVerticallyFlipped) | + | if (isTextureTargetVerticallyFlipped) |
renderArea = CEGUI::Rectf(0.0f, height, width, 0.0f); | renderArea = CEGUI::Rectf(0.0f, height, width, 0.0f); | ||
else | else | ||
Line 40: | Line 41: | ||
− | if( | + | if(textureTargetImage) |
− | + | textureTargetImage->setImageArea(renderArea); | |
} | } | ||
} | } | ||
Line 47: | Line 48: | ||
− | + | If you want to retrieve the renderer-specific texture from a CEGUI texture you will need to cast it: | |
For example for OpenGL: | For example for OpenGL: | ||
Line 54: | Line 55: | ||
</source> | </source> | ||
− | After that | + | After that you can use the member function to receive whatever render-specific traits you need, such as the textureID in Opengl as an unsigned integer, etc. |
[[Category:HowTo]] | [[Category:HowTo]] |
Revision as of 19:19, 3 March 2014
Written for CEGUI 0.8
Works with versions 0.8.x (stable)
Works with latest CEGUI stable!
Since version 0.8 the new GUIContext class allows it to render your CEGUI interface into a texture instead of rendering it normally into your main buffer.
CEGUI::System& ceSystem = CEGUI::System::getSingleton(); //Taking some random values as example for a GUIContext size. int width = 1024; int height = 800; CEGUI::Sizef size(static_cast<float>(width), static_cast<float>(height)); // We create a CEGUI texture target and create a GUIContext that will use it. CEGUI::TextureTarget* renderTextureTarget = ceSystem.getRenderer()->createTextureTarget(); CEGUI::GUIContext* renderGuiContext = ceSystem.createGUIContext(static_cast<CEGUI::RenderTarget&>(*renderTextureTarget) ); renderTextureTarget->declareRenderSize(size); // We create a BasicImage and set the Texture textureTargetImage = static_cast<CEGUI::BitmapImage*>(&CEGUI::ImageManager::getSingleton().create("BitmapImage", "SomeGroup/MyTexturesName")); textureTargetImage->setTexture(&renderTextureTarget->getTexture()); // We size the image using a function setTextureTargetImageArea(static_cast<float>(height), static_cast<float>(width));
Here is the function for sizing the BasicImage:
void setTextureTargetImageArea(float height, float width) { if(d_textureTarget) { bool isTextureTargetVerticallyFlipped = renderTextureTarget->isRenderingInverted(); CEGUI::Rectf renderArea; if (isTextureTargetVerticallyFlipped) renderArea = CEGUI::Rectf(0.0f, height, width, 0.0f); else renderArea = CEGUI::Rectf(0.0f, 0.0f, width, height); if(textureTargetImage) textureTargetImage->setImageArea(renderArea); } }
If you want to retrieve the renderer-specific texture from a CEGUI texture you will need to cast it:
For example for OpenGL:
CEGUI::OpenGLTexture& glTexture = static_cast<CEGUI::OpenGLTexture&>(d_textureTarget->getTexture());
After that you can use the member function to receive whatever render-specific traits you need, such as the textureID in Opengl as an unsigned integer, etc.