Page 1 of 1

Ogre texture to CEGUI texture

Posted: Sun Mar 01, 2009 17:31
by Lastmerlin
I want to convert an Ogre::TexturePtr to a CEGUI::Texture.

There are several Code examples around, but I get an error for each one ^^

This is how I create the Ogre Texture:

Code: Select all

Ogre::TexturePtr texture = Ogre::TextureManager::getSingleton().createManual( "minimap_tex",
         Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, Ogre::TEX_TYPE_2D,
   512, 512, 0, Ogre::PF_R8G8B8, Ogre::TU_RENDERTARGET );


Now three attempts for the CEGUI Texture:
1. based on Ogre wiki
http://www.ogre3d.org/wiki/index.php/File_DialogBuild.cpp

Code: Select all

CEGUI::OgreCEGUITexture* ceguiTex = (CEGUI::OgreCEGUITexture*) CEGUI::System::getSingleton().getRenderer()->createTexture();
ceguiTex->setOgreTexture(texture);


2. Based on Ogre tutorial
http://www.ogre3d.org/wiki/index.php/Basic_Tutorial_7

Code: Select all

CEGUI::OgreCEGUITexture* ceguiTex = (CEGUI::OgreCEGUITexture*) CEGUI::System::getSingleton().getRenderer()->createTexture((CEGUI::utf8*)"minimap_tex");


3. Based on some forum thread here

Code: Select all

CEGUI::OgreCEGUITexture* ceguiTex = (CEGUI::OgreCEGUITexture*) CEGUI::System::getSingleton().getRenderer()->createTexture(texture);


The first one gives a linking error
undefined reference to `CEGUI::OgreCEGUITexture::setOgreTexture(Ogre::TexturePtr&)'

while the latter two give the compile time error that I am calling createTexture with wrong arguments. I guess the first attempt is closest to the solution.

Concerning the linker error: I am already using these libs:
pkg-config --libs CEGUI-OGRE
-lCEGUIOgreRenderer -lOgreMain -lCEGUIBase

whats missing ?

Thank you very much :)

Posted: Sun Mar 01, 2009 19:14
by CrazyEddie
Hi,

I'm not sure why you get the undefined reference error, it seems strange. This probably means the solution is staring us in the face :lol:

In order to use the 'other' approach, you basically require either to cast the renderer returned from CEGUI::System to the CEGUI::OgreCEGUIRenderer (which is only to require the Ogre specific renderer header; it contains a default for the resourceGroup second parameter), or specify the second parameter explicitly yourself as, probably "General".

So:

Code: Select all

CEGUI::OgreCEGUITexture* ceguiTex = (CEGUI::OgreCEGUITexture*)((OgreCEGUIRenderer*)CEGUI::System::getSingleton().getRenderer())->createTexture((CEGUI::utf8*)"minimap_tex");

or

Code: Select all

CEGUI::OgreCEGUITexture* ceguiTex = (CEGUI::OgreCEGUITexture*)CEGUI::System::getSingleton().getRenderer()->createTexture((CEGUI::utf8*)"minimap_tex", "General");


HTH

CE

Posted: Mon Mar 02, 2009 21:01
by Lastmerlin
Thanks, code is compiling now - although not doing what it is intended to do so far :lol:
I hope to get that fixed on my own

Posted: Mon Mar 02, 2009 23:39
by Van
CEGUI: 0.6.2
Ogre: 1.6.2


Here is how we do it

Code: Select all


   // Create an Ogre Render To Texture process.
   Ogre::TexturePtr mTexturePtr = Ogre::TextureManager::getSingleton().createManual(
      "Hangar/Ship/Display/RTT",
      Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
      Ogre::TEX_TYPE_2D,
      512, 512,
      0,
      Ogre::PF_B8G8R8A8,   // <<< Note we use an ALPHA channel for transparency.
      Ogre::TU_RENDERTARGET );
     
   Ogre::RenderTarget *mRTT = mTexturePtr->getBuffer()->getRenderTarget();


... Some code for Ogre to create cameras and stuff ...

   // Create CEGUI texture from the Ogre RTT
   CEGUI::Texture *mTexture = mGlobalResource->CEGUIRenderer->createTexture( "Hangar/Ship/Display/RTT" );

   // Create CEGUI Imageset
   CEGUI::Imageset *mRTTImageSet = CEGUI::ImagesetManager::getSingleton().createImageset( "Hangar/Ship/Display/ImageSet", mTexture );
   
   // Define a CEGUI Image
   mRTTImageSet->defineImage(
      "Hangar/Ship/Display/Image",
      CEGUI::Point( 0.0f, 0.0f ),
      CEGUI::Size( mTexture->getWidth(), mTexture->getHeight() ),
      CEGUI::Point( 0.0f, 0.0f ) );

   // Set the Image in the StaticImage widow.
   mSIShipImage->setProperty( "Image", "set:Hangar/Ship/Display/ImageSet image:Hangar/Ship/Display/Image" );