[SOLVED] Rendering to Ogre texture, nothing shows up

For help with general CEGUI usage:
- Questions about the usage of CEGUI and its features, if not explained in the documentation.
- Problems with the CMAKE configuration or problems occuring during the build process/compilation.
- Errors or unexpected behaviour.

Moderators: CEGUI MVP, CEGUI Team

TheSHEEEP
Not too shy to talk
Not too shy to talk
Posts: 33
Joined: Mon Aug 12, 2013 09:59

[SOLVED] Rendering to Ogre texture, nothing shows up

Postby TheSHEEEP » Tue Mar 17, 2015 14:37

Hello again :)

I am trying to make CEGUI render to a specific texture unit in a material.
The goal is to enable rendering of any number of GUIs into any arbitrary texture units at the same time.
But I already fail with only one :rofl:

My code is the following:

Code: Select all

// Create CEGUI renderer
    CEGUI::OgreRenderer& renderer =
            CEGUI::OgreRenderer::bootstrapSystem(
                *static_cast<Ogre::RenderTarget*>(p_window->getOgreWindow())
            );
   
    // Set resource paths
    CEGUI::ImageManager::setImagesetDefaultResourceGroup("Gui");
    CEGUI::Font::setDefaultResourceGroup("Gui");
    CEGUI::Scheme::setDefaultResourceGroup("Gui");
    CEGUI::WidgetLookManager::setDefaultResourceGroup("Gui");
    CEGUI::WindowManager::setDefaultResourceGroup("Gui");
   
    // Init CEGUI
    CEGUI::ImageManager::getSingleton().loadImageset("TaharezLook.imageset", "Gui");
    CEGUI::SchemeManager::getSingleton().createFromFile("TaharezLook.scheme", "Gui");
   
    // Load a layout
    CEGUI::Window* window = CEGUI::WindowManager::getSingleton()
            .loadLayoutFromFile((CEGUI::utf8*)"TextSample.layout");
    window->setUsingAutoRenderingSurface( true );

    // Get the Ogre texture
    CEGUI::OgreTextureTarget& textureTarget =
            dynamic_cast<CEGUI::OgreTextureTarget&>(window->getRenderingSurface()->getRenderTarget());
    CEGUI::Texture& ceTex = textureTarget.getTexture();
    CEGUI::OgreTexture& ogreTexture = static_cast<CEGUI::OgreTexture&>(ceTex);   
    Ogre::TexturePtr ogreTexturePtr = ogreTexture.getOgreTexture();
   
    // Find the material
    Ogre::MaterialPtr matPtr = Ogre::MaterialManager::getSingleton().getByName("FullscreenOverlay");
    // Find the technique
    Ogre::Technique* technique = matPtr->getTechnique("Tech");
    // Find the pass
    Ogre::Pass* pass = technique->getPass("Pass");
    // Find the texture unit, get its original texture and replace the texture
    Ogre::TextureUnitState* textureUnit = pass->getTextureUnitState("Texture");
    Ogre::String name = ogreTexturePtr->getName();
    textureUnit->setTextureName(name);


It does successfully replace the texture on the material, but only with a black, transparent texture.
I assume that CEGUI never really renders into the texture, but how can I make it?
The logs do not show anything strange, so I suspect I am forgetting something here.

As an additional info, the material is on a compositor pass rendering a fullscreen quad.
Also, I am using the latest bitbucket version of 0.8.

I also read the article about general RTT ( this one ), but I do not even know where to start with that approach. How would you load and display a layout with that? When would you have to call that .draw()-function in Ogre (maybe within a RenderTargetListener?). Do you create such a context per loaded layout or per texture you want to render to?
It leaves so many open questions that I thought the above approach would be better suited. ;)
Last edited by TheSHEEEP on Wed Mar 18, 2015 19:00, edited 1 time in total.

User avatar
Ident
CEGUI Team
Posts: 1998
Joined: Sat Oct 31, 2009 13:57
Location: Austria

Re: Rendering to Ogre texture, nothing shows up

Postby Ident » Tue Mar 17, 2015 17:15

Did you manage to have CEGUI render the GUI correctly inside Ogre in the regular way, and updating/re-rendering it every frame correctly? You should start with that.
CrazyEddie: "I don't like GUIs"

User avatar
dermont
Quite a regular
Quite a regular
Posts: 75
Joined: Mon Aug 29, 2005 16:15

Re: Rendering to Ogre texture, nothing shows up

Postby dermont » Wed Mar 18, 2015 06:38

TheSHEEEP wrote:Hello again :)

I am trying to make CEGUI render to a specific texture unit in a material.
The goal is to enable rendering of any number of GUIs into any arbitrary texture units at the same time.
But I already fail with only one :rofl:

My code is the following:

Code: Select all

// Create CEGUI renderer
    CEGUI::OgreRenderer& renderer =
            CEGUI::OgreRenderer::bootstrapSystem(
                *static_cast<Ogre::RenderTarget*>(p_window->getOgreWindow())
            );
   
    // Set resource paths
    CEGUI::ImageManager::setImagesetDefaultResourceGroup("Gui");
    CEGUI::Font::setDefaultResourceGroup("Gui");
    CEGUI::Scheme::setDefaultResourceGroup("Gui");
    CEGUI::WidgetLookManager::setDefaultResourceGroup("Gui");
    CEGUI::WindowManager::setDefaultResourceGroup("Gui");
   
    // Init CEGUI
    CEGUI::ImageManager::getSingleton().loadImageset("TaharezLook.imageset", "Gui");
    CEGUI::SchemeManager::getSingleton().createFromFile("TaharezLook.scheme", "Gui");
   
    // Load a layout
    CEGUI::Window* window = CEGUI::WindowManager::getSingleton()
            .loadLayoutFromFile((CEGUI::utf8*)"TextSample.layout");
    window->setUsingAutoRenderingSurface( true );

    // Get the Ogre texture
    CEGUI::OgreTextureTarget& textureTarget =
            dynamic_cast<CEGUI::OgreTextureTarget&>(window->getRenderingSurface()->getRenderTarget());
    CEGUI::Texture& ceTex = textureTarget.getTexture();
    CEGUI::OgreTexture& ogreTexture = static_cast<CEGUI::OgreTexture&>(ceTex);   
    Ogre::TexturePtr ogreTexturePtr = ogreTexture.getOgreTexture();
   
    // Find the material
    Ogre::MaterialPtr matPtr = Ogre::MaterialManager::getSingleton().getByName("FullscreenOverlay");
    // Find the technique
    Ogre::Technique* technique = matPtr->getTechnique("Tech");
    // Find the pass
    Ogre::Pass* pass = technique->getPass("Pass");
    // Find the texture unit, get its original texture and replace the texture
    Ogre::TextureUnitState* textureUnit = pass->getTextureUnitState("Texture");
    Ogre::String name = ogreTexturePtr->getName();
    textureUnit->setTextureName(name);


It does successfully replace the texture on the material, but only with a black, transparent texture.
I assume that CEGUI never really renders into the texture, but how can I make it?
The logs do not show anything strange, so I suspect I am forgetting something here.

As an additional info, the material is on a compositor pass rendering a fullscreen quad.
Also, I am using the latest bitbucket version of 0.8.

I also read the article about general RTT ( this one ), but I do not even know where to start with that approach. How would you load and display a layout with that? When would you have to call that .draw()-function in Ogre (maybe within a RenderTargetListener?). Do you create such a context per loaded layout or per texture you want to render to?
It leaves so many open questions that I thought the above approach would be better suited. ;)


I think the problem may be that main window from your layout is not being displayed either via setWindowRoot or added as a child of another windown being rendered. In your main loop try adding window->render(), this should update your texture but will also render the layout window in the CEGUI default window which I guess you don't want.

Maybe you could try the above with a context you create yourself, don't draw, just render the window. I think that since CEGUI isn't the owner of the context it won't render to the screen, just your texture.

For example (won't work for a DefaultWindow), sorry about the code code cut and paste job:

Code: Select all

#include "Ogre.h"
#define OIS_DYNAMIC_LIB
#include <OIS/OIS.h>
#include "CEGUI/CEGUI.h"
#include "CEGUI/RendererModules/Ogre/Renderer.h"
#include <CEGUI/RendererModules/Ogre/WindowTarget.h>
#include <CEGUI/RendererModules/Ogre/RenderTarget.h>
#include <CEGUI/RendererModules/Ogre/TextureTarget.h>
#include "CEGUI/RendererModules/Ogre/Texture.h"

# include <CEGUI/PropertyHelper.h>
# include <CEGUI/SystemKeys.h>

#include <CEGUI/Window.h>
#include <CEGUI/BasicImage.h>
#include <CEGUI/ImageManager.h>
#include <CEGUI/ImageFactory.h>

#include <CEGUI/CEGUI.h>
#include <CEGUI/System.h>
#include <CEGUI/SchemeManager.h>
#include <CEGUI/Singleton.h>
#include <CEGUI/WindowManager.h>
#include <CEGUI/UDim.h>
#include <CEGUI/DefaultResourceProvider.h>

#include <stddef.h>

#include "CEGUI/ColourRect.h"
#include "CEGUI/widgets/ListboxItem.h"
#include "OgreTexture.h"
#include "CEGUI/Image.h"
#include "CEGUI/CEGUI.h"

CEGUI::GUIContext* OgrerenderGuiContext;
CEGUI::TextureTarget* OgrerenderTextureTarget;

using namespace Ogre;


class RTTWindow
{
protected:
    CEGUI::Window* mParent;
    CEGUI::RenderingSurface* mRenderSurface;
    Rectangle2D* rect;
public:
    RTTWindow(CEGUI::Window *window,Ogre::SceneManager* mSceneMgr)
    {
         mParent = window;
        // Get the Ogre texture
        CEGUI::OgreTextureTarget& textureTarget =
              dynamic_cast<CEGUI::OgreTextureTarget&>(window->getRenderingSurface()->getRenderTarget());
        CEGUI::Texture& ceTex = textureTarget.getTexture();
        CEGUI::OgreTexture& ogreTexture = static_cast<CEGUI::OgreTexture&>(ceTex);   
        Ogre::TexturePtr ogreTexturePtr = ogreTexture.getOgreTexture();
        // Find the material
        Ogre::MaterialPtr matPtr = Ogre::MaterialManager::getSingleton().getByName("Examples/BeachStones");
        // Find the technique
        Ogre::Technique* technique = matPtr->getTechnique(0);
        // Find the pass
        Ogre::Pass* pass = technique->getPass(0);
        // Find the texture unit, get its original texture and replace the texture
        Ogre::TextureUnitState* textureUnit = pass->getTextureUnitState(0);
        Ogre::String name = ogreTexturePtr->getName();
        textureUnit->setTextureName(name);
        window->invalidate();



        // Create background material
        MaterialPtr material = MaterialManager::getSingleton().create("Background", "General");
        material->getTechnique(0)->getPass(0)->createTextureUnitState(ogreTexturePtr->getName());
        //material->getTechnique(0)->getPass(0)->getTextureUnitState(0)->setName(ogreTexturePtr->getName());
        material->getTechnique(0)->getPass(0)->setDepthCheckEnabled(false);
        material->getTechnique(0)->getPass(0)->setDepthWriteEnabled(false);
        material->getTechnique(0)->getPass(0)->setLightingEnabled(false);
        material->getTechnique(0)->getPass(0)->setSceneBlending(Ogre::SBT_TRANSPARENT_ALPHA);
     
        // Create background rectangle covering the whole screen
        rect = new Rectangle2D(true);
        rect->setCorners(-0.5, 0.5, 0.5, -0.5, 0.0);
        rect->setMaterial("Background");
         
        // Render the background before everything else
        rect->setRenderQueueGroup(RENDER_QUEUE_MAX );
         
        // Use infinite AAB to always stay visible
        AxisAlignedBox aabInf;
        aabInf.setInfinite();
        rect->setBoundingBox(aabInf);
         
        // Attach background to the scene
        SceneNode* node = mSceneMgr->getRootSceneNode()->createChildSceneNode("Background");
        node->attachObject(rect);
         
        // Example of background scrolling
        material->getTechnique(0)->getPass(0)->getTextureUnitState(0)->setScrollAnimation(-0.25, 0.0);
    //    mogretexture = ogreTexture->getPointer();
   }

    void update()
    {
       if (mParent) {
           //mParent->setUsingAutoRenderingSurface(true);
           mParent->render();
       }
    }

};

RTTWindow* rttWindow = 0;
   
CEGUI::MouseButton convertButton(OIS::MouseButtonID buttonID)
{
    switch (buttonID)
    {
    case OIS::MB_Left:
        return CEGUI::LeftButton;

    case OIS::MB_Right:
        return CEGUI::RightButton;

    case OIS::MB_Middle:
        return CEGUI::MiddleButton;

    default:
        return CEGUI::LeftButton;
    }
}

class SimpleApplication
    : public Ogre::RenderQueueListener
    , public FrameListener
    , public WindowEventListener
    , public OIS::KeyListener
    , public OIS::MouseListener
{
public:

    SimpleApplication()
    : mContinue(true)
   {
       mRoot = new Ogre::Root();
       bool carryOn = mRoot->restoreConfig() || mRoot->showConfigDialog();
       // Load resource paths from config file
       ConfigFile cf;
       cf.load("resources.cfg");

       // Go through all sections & settings in the file
       ConfigFile::SectionIterator seci = cf.getSectionIterator();

       String secName, typeName, archName;
       while (seci.hasMoreElements())
       {
           secName = seci.peekNextKey();
           ConfigFile::SettingsMultiMap *settings = seci.getNext();
           ConfigFile::SettingsMultiMap::iterator i;
           for (i = settings->begin(); i != settings->end(); ++i)
           {
                typeName = i->first;
                archName = i->second;
                ResourceGroupManager::getSingleton().addResourceLocation(
                    archName, typeName, secName);
           }
       }
       mWindow = mRoot->initialise(true);

       mSceneMgr = mRoot->createSceneManager(Ogre::ST_GENERIC,"Test");
       mSceneMgr->setAmbientLight(Ogre::ColourValue(1.0, 1.0, 1.0));
      Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups();

       mCamera = mSceneMgr->createCamera("TestCam");
       mCamera->setPosition(Ogre::Vector3(0,0,500));
       // Look back along -Z
       mCamera->lookAt(Ogre::Vector3(0,0,-300));
       mCamera->setNearClipDistance(5);

       Ogre::Viewport* vp = mWindow->addViewport(mCamera);
       vp->setBackgroundColour(Ogre::ColourValue(0,0,0));
       mCamera->setAspectRatio(
            Real(vp->getActualWidth()) / Real(vp->getActualHeight()));



       SceneNode* headNode = mSceneMgr->getRootSceneNode()->createChildSceneNode();
       Entity* ent = mSceneMgr->createEntity("head", "ogrehead.mesh");
       headNode->attachObject(ent);
      mSceneMgr->setSkyDome(true, "Examples/CloudySky", 10, 8);


       mRenderer = &CEGUI::OgreRenderer::bootstrapSystem();
       CEGUI::Sizef size(static_cast<float>(1024), static_cast<float>(800));
       CEGUI::System& ceguiSystem = CEGUI::System::getSingleton();

       OgrerenderTextureTarget = ceguiSystem.getRenderer()->createTextureTarget();
       OgrerenderTextureTarget->declareRenderSize(size);
       CEGUI::GUIContext& ogc = ceguiSystem.createGUIContext(static_cast<CEGUI::RenderTarget&>(*OgrerenderTextureTarget) );
       OgrerenderGuiContext = &(ogc);

       CEGUI::ImageManager::getSingleton().setImagesetDefaultResourceGroup("Imagesets");
       CEGUI::Font::setDefaultResourceGroup("Fonts");
       CEGUI::Scheme::setDefaultResourceGroup("Schemes");
       CEGUI::WidgetLookManager::setDefaultResourceGroup("LookNFeel");
       CEGUI::WindowManager::setDefaultResourceGroup("Layouts");

        // setup schemes
        CEGUI::SchemeManager::getSingleton().createFromFile("WindowsLook.scheme");
        CEGUI::SchemeManager::getSingleton().createFromFile("TaharezLook.scheme");
        // setup default group for validation schemas
        CEGUI::XMLParser* parser = CEGUI::System::getSingleton().getXMLParser();
        if (parser->isPropertyPresent("SchemaDefaultResourceGroup"))
            parser->setProperty("SchemaDefaultResourceGroup", "schemas");

        CEGUI::System::getSingleton().getDefaultGUIContext().getMouseCursor().setDefaultImage("TaharezLook/MouseArrow");
        CEGUI::FontManager::getSingleton().createFreeTypeFont("DefaultFont",
            10/*pt*/, true, "DejaVuSans.ttf");
        //CEGUI::System::getSingleton().setDefaultFont("DefaultFont");

        loadGUI();

        // Input handling
      OIS::ParamList pl;
      size_t windowHnd = 0;
      std::ostringstream windowHndStr;
       mWindow->getCustomAttribute("WINDOW", &windowHnd);
       windowHndStr << windowHnd;
       pl.insert(std::make_pair(std::string("WINDOW"), windowHndStr.str()));

#if OGRE_PLATFORM == OGRE_PLATFORM_LINUX
        pl.insert(std::make_pair(std::string("x11_mouse_grab"), std::string("false")));
        pl.insert(std::make_pair(std::string("x11_mouse_hide"), std::string("false")));
        pl.insert(std::make_pair(std::string("x11_keyboard_grab"), std::string("false")));
        pl.insert(std::make_pair(std::string("XAutoRepeatOn"), std::string("true")));
#endif
       mInputManager = OIS::InputManager::createInputSystem( pl );

       mKeyboard = static_cast<OIS::Keyboard*>(mInputManager->createInputObject( OIS::OISKeyboard, true ));
       mMouse = static_cast<OIS::Mouse*>(mInputManager->createInputObject( OIS::OISMouse, true ));

       mMouse->setEventCallback(this);
       mKeyboard->setEventCallback(this);

      //Set window event listeners
      //windowResized(mWindow);
      //Register as a Window listener
      WindowEventUtilities::addWindowEventListener(mWindow, this);      

        // disable CEGUI's framelistener and update CEGUI in our renderqueue
        // listener to control randers  after/before overlays. Comment out the
        // following two lines to use default CEGUI framelistener
        mRenderer->setFrameControlExecutionEnabled(false);
        mCamera->getSceneManager()->addRenderQueueListener(this);

        // create our own framelistener
        mRoot->addFrameListener(this);
  } 

    void loadLayoutGUI()
    {
        CEGUI::Window *guiRoot = CEGUI::WindowManager::getSingleton().loadLayoutFromFile("TextDemo.layout");
        CEGUI::System::getSingleton().getDefaultGUIContext().setRootWindow(guiRoot);
    }

    void loadGUI()
    {
        // create root window
        CEGUI::WindowManager& winMgr = CEGUI::WindowManager::getSingleton();
        CEGUI::Window *sheet = winMgr.createWindow("DefaultWindow", "CEGUIDemo/Sheet");
        CEGUI::System::getSingleton().getDefaultGUIContext().setRootWindow(sheet);

        // create quit button
        CEGUI::Window *quit = winMgr.createWindow("TaharezLook/Button", "CEGUIDemo/QuitButton");
        quit->setText("Quit");
        quit->setSize(CEGUI::USize(CEGUI::UDim(0.15, 0),
                                    CEGUI::UDim(0.5, 0)));
        sheet->addChild(quit);


       CEGUI::Window* window = CEGUI::WindowManager::getSingleton()
            .loadLayoutFromFile((CEGUI::utf8*)"TextDemo.layout");
        //sheet->addChild(windowl);
        CEGUI::Window* st = window->getChild("TextDemo");
        //rttWindow = new RTTWindow(sheet, texture);
        rttWindow = new RTTWindow(st, mSceneMgr);

}

    //------------------------------------------------------------------------
    void renderQueueStarted(Ogre::uint8 queueGroupId, const Ogre::String& invocation, bool& skipThisQueue)
    {
        if (queueGroupId == Ogre::RENDER_QUEUE_MAX)
        {
            Ogre::Root* mRoot = Ogre::Root::getSingletonPtr();
        }
        if (queueGroupId == Ogre::RENDER_QUEUE_OVERLAY)
        {
            //CEGUI::System::getSingleton().renderAllGUIContexts();

           CEGUI::Renderer* gui_renderer(CEGUI::System::getSingleton().getRenderer());
           gui_renderer->beginRendering();
 
           OgrerenderTextureTarget->clear();
           OgrerenderGuiContext->draw();
 
           gui_renderer->endRendering();
           if (rttWindow)
           {
                rttWindow->update();
           }
           skipThisQueue=true;
        }
    }

    //------------------------------------------------------------------------
    void renderQueueEnded(uint8 queueGroupId, const String& invocation,
        bool& repeatThisInvocation)
    {
        if (queueGroupId == Ogre::RENDER_QUEUE_OVERLAY)
        {
        }
        if (queueGroupId == Ogre::RENDER_QUEUE_MAX )
        {
        }
    }

    //------------------------------------------------------------------------
   bool frameRenderingQueued(const FrameEvent& evt)
   {
      mKeyboard->capture();
      mMouse->capture();
        if( mKeyboard->isKeyDown(OIS::KC_ESCAPE) )
        {
            mContinue = false;
            return false;
        }
      if(mWindow->isClosed())   return false;
        CEGUI::System::getSingleton().injectTimePulse(static_cast<float>(evt.timeSinceLastFrame));
        return true;
    }

    //------------------------------------------------------------------------
    bool mouseMoved(const OIS::MouseEvent &arg)
    {
        if (CEGUI::System::getSingletonPtr())
            CEGUI::System::getSingleton().getDefaultGUIContext().injectMousePosition(arg.state.X.abs, arg.state.Y.abs);
        return true;
    }

    //------------------------------------------------------------------------
    bool mousePressed(const OIS::MouseEvent &arg, OIS::MouseButtonID id)
    {
        if (CEGUI::System::getSingletonPtr())
            CEGUI::System::getSingleton().getDefaultGUIContext().injectMouseButtonDown(convertButton(id));
        return true;
    }

    //------------------------------------------------------------------------
    bool mouseReleased(const OIS::MouseEvent &arg, OIS::MouseButtonID id)
    {
        if (CEGUI::System::getSingletonPtr())
            CEGUI::System::getSingleton().getDefaultGUIContext().injectMouseButtonUp(convertButton(id));
        return true;
    }

    //------------------------------------------------------------------------
    bool keyPressed(const OIS::KeyEvent &arg)
    {
        if (CEGUI::System::getSingletonPtr()) {
            CEGUI::System::getSingleton().getDefaultGUIContext().injectKeyDown(static_cast<CEGUI::Key::Scan>(arg.key));
            CEGUI::System::getSingleton().getDefaultGUIContext().injectChar(arg.text);
        }

        return true;
    }

    //------------------------------------------------------------------------
    bool keyReleased(const OIS::KeyEvent &arg)
    {
        if (CEGUI::System::getSingletonPtr())
            CEGUI::System::getSingleton().getDefaultGUIContext().injectKeyUp(static_cast<CEGUI::Key::Scan>(arg.key));
        return true;
    }

    //------------------------------------------------------------------------
   ~SimpleApplication()
   {
      WindowEventUtilities::removeWindowEventListener(mWindow, this);      
        mRoot->removeFrameListener(this);
        mCamera->getSceneManager()->removeRenderQueueListener(this);
        CEGUI::OgreRenderer::destroy(*mRenderer);
        mRenderer = 0;
        delete mRoot;
   }

    //------------------------------------------------------------------------
   void windowResized(RenderWindow* rw)
   {
      unsigned int width, height, depth;
      int left, top;
      rw->getMetrics(width, height, depth, left, top);

       const OIS::MouseState &ms = mMouse->getMouseState();
       ms.width = width;
       ms.height = height;

        CEGUI::System::getSingleton().notifyDisplaySizeChanged(CEGUI::Size<float>(float(width), float(height)) );
   }

    //------------------------------------------------------------------------
   void windowClosed(RenderWindow* rw)
   {

      //Only close for window that created OIS (the main window in these demos)
      if( rw == mWindow )
      {
         if( mInputManager )
         {
            mInputManager->destroyInputObject( mMouse );
            mInputManager->destroyInputObject( mKeyboard );

            OIS::InputManager::destroyInputSystem(mInputManager);
            mInputManager = 0;
         }
      }
    }

    //------------------------------------------------------------------------
    void loop()
    {
        while (!mWindow->isClosed() && mContinue)
        {
            Ogre::WindowEventUtilities::messagePump();
            mRoot->renderOneFrame();
       }
      delete mRoot;

    }
 
protected:
    Root *mRoot;
    Camera* mCamera;
    SceneManager* mSceneMgr;
    RenderWindow* mWindow;
    CEGUI::OgreRenderer *mRenderer;
    Ogre::FrameListener* mFrameListener;
    Ogre::RenderTexture *mRenderTexture;


   //OIS Input devices
   OIS::InputManager* mInputManager;
   OIS::Mouse*    mMouse;
   OIS::Keyboard* mKeyboard;
    bool mContinue;

    CEGUI::MultiColumnList *mListBox;

};

#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
#define WIN32_LEAN_AND_MEAN
#include "windows.h"


INT WINAPI WinMain(HINSTANCE hInst, HINSTANCE, LPSTR strCmdLine, INT)
#else
int main(int argc, char **argv)
#endif
{
    // Create application object
    //CEGUIDemoApplication app;
    SimpleApplication app;
    try {
        app.loop();
        //app.go();
    } catch(Exception& e) {
#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
        MessageBoxA(NULL, e.getFullDescription().c_str(), "An exception has occurred!",
            MB_OK | MB_ICONERROR | MB_TASKMODAL);
#else
        fprintf(stderr, "An exception has occurred: %s\n",
            e.getFullDescription().c_str());
#endif
    }

    return 0;
}

TheSHEEEP
Not too shy to talk
Not too shy to talk
Posts: 33
Joined: Mon Aug 12, 2013 09:59

Re: Rendering to Ogre texture, nothing shows up

Postby TheSHEEEP » Wed Mar 18, 2015 10:57

Sorry for coming back on this so late.

I actually did a lot of testing and trial and error. But I ended up with something that seems to be working.
It is a mixture of my original approach with the GuiContext one.

Code: Select all

// Load the layout
    _layoutWindow = CEGUI::WindowManager::getSingleton().loadLayoutFromFile(p_assetPath.c_str());
    _layoutWindow->setUsingAutoRenderingSurface( true );
   
    // Create and assign the gui context
    CEGUI::System& ceguiSystem = CEGUI::System::getSingleton();
    CEGUI::OgreRenderer* ogreRenderer = static_cast<CEGUI::OgreRenderer *>(ceguiSystem.getRenderer());
    CEGUI::Sizef size(static_cast<float>(_width), static_cast<float>(_height));
    CEGUI::TextureTarget* renderTextureTarget = ogreRenderer->createTextureTarget();
    renderTextureTarget->declareRenderSize(size);
    _renderGuiContext = &ceguiSystem.createGUIContext(static_cast<CEGUI::RenderTarget&>(*renderTextureTarget) );
    _layoutWindow->setRenderingSurface(static_cast<CEGUI::RenderingSurface*>(_renderGuiContext));
 
    // Get the Ogre texture
    CEGUI::Texture& renderTargetTexture = renderTextureTarget->getTexture();
    Ogre::TexturePtr ogreTexture = static_cast<CEGUI::OgreTexture&>(renderTargetTexture).getOgreTexture();

    // Find the material
    Ogre::MaterialPtr matPtr = Ogre::MaterialManager::getSingleton().getByName("FullscreenOverlay");
    // Find the technique
    Ogre::Technique* technique = matPtr->getTechnique("Tech");
    // Find the pass
    Ogre::Pass* pass = technique->getPass("Pass");
    // Find the texture unit, get its original texture and replace the texture
    Ogre::TextureUnitState* textureUnit = pass->getTextureUnitState("Texture");
    Ogre::String name = ogreTexture->getName();
    textureUnit->setTextureName(name);


My first error was indeed not calling window->render(). But I also had to create a new GuiContext (after noticing it was also a RenderSurface) and assign that to the loaded window.
With that, I can now call render() whenever I want, it seems. Which is very useful as there will be GUI elements that won't need to be updated regularly.

I would honestly suggest updating the RTT wiki entry with an example of how to use it with a loaded layout. It really took me hours to figure it out.
Or at least add a hint that a GuiContext is also a RendererSurface which can be assigned to a window.

That GuiContext->draw() from the wiki entry however I do not use. It is probably called by window->render() indirectly.

User avatar
Ident
CEGUI Team
Posts: 1998
Joined: Sat Oct 31, 2009 13:57
Location: Austria

Re: Rendering to Ogre texture, nothing shows up

Postby Ident » Wed Mar 18, 2015 11:07

TheSHEEEP wrote:I would honestly suggest updating the RTT wiki entry with an example of how to use it with a loaded layout. It really took me hours to figure it out.
Or at least add a hint that a GuiContext is also a RendererSurface which can be assigned to a window.


Do it
CrazyEddie: "I don't like GUIs"

TheSHEEEP
Not too shy to talk
Not too shy to talk
Posts: 33
Joined: Mon Aug 12, 2013 09:59

Re: Rendering to Ogre texture, nothing shows up

Postby TheSHEEEP » Wed Mar 18, 2015 12:08

That's your job :P

But I did it anyway ;)

I will test my implementation a bit more before I set this to SOLVED.

User avatar
Ident
CEGUI Team
Posts: 1998
Joined: Sat Oct 31, 2009 13:57
Location: Austria

Re: Rendering to Ogre texture, nothing shows up

Postby Ident » Wed Mar 18, 2015 12:21

TheSHEEEP wrote:That's your job :P

What made you think so?

Did anything give you the impression this was not a community wiki? If yes, what would you suggest to change at the wiki to make it instantly be perceived as a community wiki by users?

TheSHEEEP wrote:I will test my implementation a bit more before I set this to SOLVED.

That's generally always a good idea ;)
CrazyEddie: "I don't like GUIs"

TheSHEEEP
Not too shy to talk
Not too shy to talk
Posts: 33
Joined: Mon Aug 12, 2013 09:59

Re: Rendering to Ogre texture, nothing shows up

Postby TheSHEEEP » Wed Mar 18, 2015 16:21

Well, it works almost.

The first problem is that there is no transparency outside of the rendered GUI. Everything is black.
The alpha value is 1 everywhere.

That is very strange, since the same layout rendered normally (directly to the Ogre window) works just fine.
Only if rendered the way I described above, CEGUI applies wrong transparency somehow.

The second problem is that the displayed layout has a wrong position. I am loading the console.layout from the sample, so it should display in the center bottom of the screen.
It is, however, in the upper left.

Here is a screenshot:
Link
Last edited by TheSHEEEP on Wed Mar 18, 2015 16:33, edited 2 times in total.

User avatar
Ident
CEGUI Team
Posts: 1998
Joined: Sat Oct 31, 2009 13:57
Location: Austria

Re: Rendering to Ogre texture, nothing shows up

Postby Ident » Wed Mar 18, 2015 16:28

TheSHEEEP wrote:Well, it works almost.

The problem is that there is no transparency outside of the rendered GUI. Everything is black.
The alpha value is 1 everywhere.

That is very strange, since the same layout rendered normally (directly to the Ogre window) works just fine.
Only if rendered the way I described above, CEGUI applies wrong transparency somehow.


Screenshot please.

Also could you please answer regarding the Wiki? There is relatively few people editing the Wiki and your statement hints toward that there might be a misunderstanding about what the Wiki is.
CrazyEddie: "I don't like GUIs"

TheSHEEEP
Not too shy to talk
Not too shy to talk
Posts: 33
Joined: Mon Aug 12, 2013 09:59

Re: Rendering to Ogre texture, nothing shows up

Postby TheSHEEEP » Wed Mar 18, 2015 16:35

I added a screenshot to my last post.

About the wiki:
Well, my comment was more aimed at the fact that someone should put up an example who knows what he is doing. I don't really, I am just trying to understand things ;)
And it seems that what I do is still somehow wrong. Or at least missing something.
Last edited by TheSHEEEP on Wed Mar 18, 2015 16:39, edited 1 time in total.

User avatar
Ident
CEGUI Team
Posts: 1998
Joined: Sat Oct 31, 2009 13:57
Location: Austria

Re: Rendering to Ogre texture, nothing shows up

Postby Ident » Wed Mar 18, 2015 16:39

TheSHEEEP wrote:Well, my comment was more aimed at the fact that someone should put up an example who knows what he is doing. I don't really, I am just trying to understand things ;)
And it seems that what I do is still somehow wrong.

I didnt to what you are doing with this stuff, therefore you have more knowledge right now about this than I do. The info I put there seemed sufficient for everything I did. I didnt run into the issues you did but also i didnt use Ogre for this, so I cant write anything about it there...


Regarding the screenshot: What did you expect? I need an image for comparison to understand what is even wrong. Also post your layout's code.
CrazyEddie: "I don't like GUIs"

TheSHEEEP
Not too shy to talk
Not too shy to talk
Posts: 33
Joined: Mon Aug 12, 2013 09:59

Re: Rendering to Ogre texture, nothing shows up

Postby TheSHEEEP » Wed Mar 18, 2015 16:42

Oh, yes, I probably should have said that :lol:
There is an actual 3D scene behind the GUI ;)

Which is clearly visible before I assign the Ogre texture CEGUI created to the texture_unit of the material that serves as the gui target.
It is a material used by a full screen compositor, actually.
The standard texture (which is replaced by the Ogre texture CEGUI produces) in that material is a transparent image, so transparency definitely works on that material.

The layout's code is really just the console.layout from the samples:

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>

<GUILayout version="4" >
    <Window type="TaharezLook/FrameWindow" name="Frame" >
        <Property name="Area" value="{{0.208832,-24},{0.650387,0},{0.80736,0},{0.998062,0}}" />
        <Property name="Text" value="Console Test" />
        <Property name="MaxSize" value="{{1,0},{1,0}}" />
        <Window type="TaharezLook/MultiLineEditbox" name="ConsoleText" >
            <Property name="Area" value="{{0.019238,0},{0.030633,0},{0.973721,0},{0.769186,0}}" />
            <Property name="Text" >
</Property>
            <Property name="MaxSize" value="{{1,0},{1,0}}" />
            <Property name="ReadOnly" value="true" />
        </Window>
        <Window type="TaharezLook/Editbox" name="Input" >
            <Property name="Area" value="{{0.019238,0},{0.772141,0},{0.973721,0},{0.980658,0}}" />
            <Property name="MaxSize" value="{{1,0},{1,0}}" />
        </Window>
    </Window>
</GUILayout>
Last edited by TheSHEEEP on Wed Mar 18, 2015 16:47, edited 1 time in total.

User avatar
Ident
CEGUI Team
Posts: 1998
Joined: Sat Oct 31, 2009 13:57
Location: Austria

Re: Rendering to Ogre texture, nothing shows up

Postby Ident » Wed Mar 18, 2015 16:46

In your code you never set the GUIContexts root to be the loaded layout. This is also the case in the wiki. You have to do that for the GUIContext youcreate for the RTT.

I just saw you set the GUIContext as rendertarget of the layout. Where did you get that idea from? You are supposed to set the guicontext's rendertarget and not the other way around. Also you are supposd to call the guicontexts draw function for drawing.

The wiki article doesnt cover how GUIContexts work becasue it is assumed that the user already knows this. So to clear that up:

1. create GuiContext using a RenderTarget such as a Texture (shown in the wiki article)
2. set the guicontexts root by setting the root window (remember, the root window should be a 1,1 rel sized (fully covering) DefaultWindiw, everything else can be attached to that). This is basically where your layout is added.
3. Render the GUIContext with the GUIContext-specific draw functions which will automatically render to the Texture.

For more info check out the SampleBrowser code. This is a vey specific use-case which is however a bit similar to yours so you might find some useful code. The difference is that we dont render into an Ogre Texture there. Instead we render in a way so that the resulting texture can be reused inside CEGUI again.
CrazyEddie: "I don't like GUIs"

TheSHEEEP
Not too shy to talk
Not too shy to talk
Posts: 33
Joined: Mon Aug 12, 2013 09:59

Re: Rendering to Ogre texture, nothing shows up

Postby TheSHEEEP » Wed Mar 18, 2015 16:51

I'll answer your question first, then try out your suggestions ;)

Ident wrote:I just saw you set the GUIContext as rendertarget of the layout. Where did you get that idea from? You are supposed to set the guicontext's rendertarget and not the other way around. Also you are supposd to call the guicontexts draw function for drawing.

Well, it seems to make sense, doesn't it?
The window has a RenderSurface it renders to (at least that is what I would expect a RenderSurface is for). GuiContext is a RenderSurface.
Hence, window should be able to render into a GuiContext. For someone who is new, I think that sounds logical :)

User avatar
Ident
CEGUI Team
Posts: 1998
Joined: Sat Oct 31, 2009 13:57
Location: Austria

Re: Rendering to Ogre texture, nothing shows up

Postby Ident » Wed Mar 18, 2015 17:00

TheSHEEEP wrote:
Ident wrote:I just saw you set the GUIContext as rendertarget of the layout. Where did you get that idea from? You are supposed to set the guicontext's rendertarget and not the other way around. Also you are supposd to call the guicontexts draw function for drawing.

Well, it seems to make sense, doesn't it?
The window has a RenderSurface it renders to (at least that is what I would expect a RenderSurface is for). GuiContext is a RenderSurface.
Hence, window should be able to render into a GuiContext. For someone who is new, I think that sounds logical :)

And how do you interact with a RenderSurface? Where do the inputs go? Into the widget? It sounds logical only for the rendering part, but not for everything else. I give you that though: it sounds like it works fine for rendering. Also basically it should or could work the way you are doing it but in the end it is kind of hack-ish and afaik we do not suggest to do this this way anywhere in the docu.

If you want the full functionality you are supposed to use a GUIContext which allows RTT. What you are doing is that you use the auto-rendering-surface functionality to draw into a texture.It is indirect and could lead to issues. The auto-rendering-surface functionality is mostly meant to be used for caching of complex but barely changing window hierarchies, in most cases it is totally useless. It is also required for rotational animations I think, but this is due to sampling stuff. I guess this info could all be added to the wiki article.

So overall your approach "might work" but this is not how it should generally be done, and since we dont really anticipatesuch usage there could be issues.

Lets let you change over to GUIContexts first though. I assume you want the full pakage of interaction etc in your RTT GUI Texture, dont you? So you will definitely need a GUIContext.
CrazyEddie: "I don't like GUIs"


Return to “Help”

Who is online

Users browsing this forum: No registered users and 11 guests