<div dir="ltr"><div><div><div><div><div><div><div><div><div>Version Information:<br></div>OSG: 3.4.0<br></div>CEGUI: 0.8.7<br><br></div>Problem: I am unable to get the osg::Drawable for CEGUI to draw. The drawImplementation method never even gets called.<br><br></div>What was my starting point: I've been using the two by Rui Wang and Xuelei Qian to learn osg. I attempted to run through their example on integrating CEGUI, but it is for version 0.7.5. There are considerable differences between 0.7.5 and 0.8.7, but I believe that I was able to update the example using CEGUI porting tips on their website (<a href="http://static.cegui.org.uk/docs/0.8.7/porting7to8.html">http://static.cegui.org.uk/docs/0.8.7/porting7to8.html</a>).<br><br></div>Here is my code, please let me know why you think the drawable isn't being called.<br><br><br><div>client_master.cpp: This is where I'm calling the code to create the drawable object and add it to the scene graph. This is pretty much ripped right out of the cookbook. Option 1 is right from the cookbook. Option 2 was from a forum post somewhere. Option 2 will paint a debugging cow while option 1 will not.<br></div><div style="margin-left:40px">osg::Camera* ClientMaster::create_hud_camera( double left, double right, double bottom, double top ){<br>    int option = 2;<br><br>    osg::ref_ptr<osg::Camera> camera = new osg::Camera;<br>    camera->setReferenceFrame( osg::Transform::ABSOLUTE_RF );<br>    camera->setClearMask( GL_DEPTH_BUFFER_BIT );<br>    camera->setRenderOrder( osg::Camera::POST_RENDER );<br>    camera->setAllowEventFocus( true );<br>    camera->getOrCreateStateSet()->setMode( GL_LIGHTING, osg::StateAttribute::OFF );<br>    <br>    if( option == 1 ){<br>        //This option is from the Cookbook. Not even the cow is shown using this.<br>        camera->setProjectionMatrix( osg::Matrix::ortho2D(left, right, bottom, top) );<br>    }<br>    else if( option == 2 ){<br>        //This option was found online. It shows the side of cow but not the gui.<br>        osg::Vec3d eye    = osg::Vec3d(0, -1,  0 );  // position of the camera<br>        osg::Vec3d center = osg::Vec3d(0,  0,  0 );  // where does the camera look.<br>        osg::Vec3d up     = osg::Vec3d(0,  0,  1 );  // the up vector of the camera<br>        camera->setViewMatrixAsLookAt(eye, center, up); <br>    }<br>    return camera.release();<br>}<br><br>void ClientMaster::initialize_HUD( void ){<br>    bool showing_cow = true;<br><br>    osg::ref_ptr<Geode> geode = new osg::Geode;<br>    geode->setCullingActive(false);<br>    geode->addDrawable( new ClientCEGUIDrawable );<br>    geode->getOrCreateStateSet()->setAttributeAndModes( new osg::BlendFunc );<br>    geode->getOrCreateStateSet()->setRenderingHint( osg::StateSet::TRANSPARENT_BIN );<br>    <br>    osg::ref_ptr<osg::Camera> hud_camera = this->create_hud_camera( 0, 800, 0, 600 );<br>    hud_camera->addChild( geode.get() );<br><br>    if( showing_cow ){<br>        //The cow is for debugging purposes. The cow displaying confirms that the<br>        //children of the hud are being painted to the screen.<br>        osg::ref_ptr<osg::Node> hud_model = osgDB::readNodeFile("./cow.osg");<br>        hud_camera->addChild( hud_model.get() );<br>    }<br><br>    this->_root_group->addChild( hud_camera.get() );<br>    this->_viewer.addEventHandler( new EventHandlerCEGUI( hud_camera.get() ) );<br>    this->_viewer.addEventHandler( new osgViewer::WindowSizeHandler );<br>    this->_viewer.addEventHandler( new osgViewer::StatsHandler );<br>}</div><br></div>client_cegui_drawable.cpp: This is taken from the cookbook and the syntax was updated from CEGUI 7 to 8. I also did a little refactoring ( nothing drastic though ). I haven't yet updated the window resizing part of the code, but that isn't yet an issue because it never gets called. I also put some debugging screen outputs into the code. ClientCEGUIDrawable is inheritted from osg::Drawable.<br><div style="margin-left:40px">#include "../headers/client_cegui_drawable.hpp"<br><br>ClientCEGUIDrawable::ClientCEGUIDrawable() : _lastSimulationTime(0.0), _activeContextID(0), _initialized(false) {<br>    cout << "ClientCEGUIDrawable: Initializing" << endl;<br>    setSupportsDisplayList( false );<br>    setDataVariance( osg::Object::DYNAMIC );<br>    getOrCreateStateSet()->setMode( GL_LIGHTING, osg::StateAttribute::OFF );<br>    getOrCreateStateSet()->setMode( GL_DEPTH_TEST, osg::StateAttribute::OFF );<br>    <br>    cout << "ClientCEGUIDrawable: Initialized" << endl;<br>}<br><br>ClientCEGUIDrawable::ClientCEGUIDrawable( const ClientCEGUIDrawable& copy,const osg::CopyOp& copyop ) : osg::Drawable(copy, copyop),<br>    _lastSimulationTime( copy._lastSimulationTime ),<br>    _activeContextID( copy._activeContextID ),<br>    _initialized( copy._initialized )<br>{}<br><br>void ClientCEGUIDrawable::initialize_resource_provider( void ){<br>    cout << "ClientCEGUIDrawable: Resource Provider: Initializing" << endl;<br>    CEGUI::DefaultResourceProvider* resource_provider =<br>        static_cast<CEGUI::DefaultResourceProvider*>( CEGUI::System::getSingleton().getResourceProvider() );<br>    resource_provider->setResourceGroupDirectory( "schemes",     "./datafiles/gui/schemes/"     );<br>    resource_provider->setResourceGroupDirectory( "imagesets",   "./datafiles/gui/imagesets/"   );<br>    resource_provider->setResourceGroupDirectory( "fonts",       "./datafiles/gui/fonts/"       );<br>    resource_provider->setResourceGroupDirectory( "layouts",     "./datafiles/gui/layouts/"     );<br>    resource_provider->setResourceGroupDirectory( "looknfeel",   "./datafiles/gui/looknfeel/"   );<br>    resource_provider->setResourceGroupDirectory( "lua_scripts", "./datafiles/gui/lua_scripts/" );<br><br>    CEGUI::ImageManager::setImagesetDefaultResourceGroup( "imagesets"   );<br>    CEGUI::Font::setDefaultResourceGroup(                 "fonts"       );<br>    CEGUI::Scheme::setDefaultResourceGroup(               "schemes"     );<br>    CEGUI::WidgetLookManager::setDefaultResourceGroup(    "looknfeel"   );<br>    CEGUI::WindowManager::setDefaultResourceGroup(        "layouts"     );<br>    CEGUI::ScriptModule::setDefaultResourceGroup(         "lua_scripts" );<br><br>    cout << "ClientCEGUIDrawable: Resource Provider: Initialized" << endl;<br>}<br><br>void ClientCEGUIDrawable::drawImplementation( osg::RenderInfo& renderInfo ){<br>    cout << "ClientCEGUIDrawable: drawImplementation: Started" << endl;<br>    unsigned int contextID = renderInfo.getContextID();<br>    if ( !_initialized )<br>    {<br>        CEGUI::OpenGLRenderer& myRenderer = CEGUI::OpenGLRenderer::bootstrapSystem();<br>        <br>        if ( !CEGUI::System::getSingletonPtr() ) return;<br><br>        this->initialize_resource_provider();<br><br>        const_cast<ClientCEGUIDrawable*>(this)->initializeControls();<br>        _activeContextID = contextID;<br>        _initialized = true;<br>    }<br>    else if ( contextID==_activeContextID )<br>    {<br>        osg::State* state = renderInfo.getState();<br>        state->disableAllVertexArrays();<br>        state->disableTexCoordPointer( 0 );<br><br>        glPushMatrix();<br>        glPushAttrib( GL_ALL_ATTRIB_BITS );<br><br>        CEGUI::OpenGLRenderer* renderer = static_cast<CEGUI::OpenGLRenderer*>(<br>        //CEGUI::OpenGL3Renderer* renderer = static_cast<CEGUI::OpenGL3Renderer*>(<br>            CEGUI::System::getSingleton().getRenderer() );<br>        osg::Viewport* viewport = renderInfo.getCurrentCamera()->getViewport();<br>        if ( renderer && viewport )<br>        {<br>            //const CEGUI::Size& size = renderer->getDisplaySize();<br>            //if ( size.d_width!=viewport->width() || size.d_height!=viewport->height() )<br>            //{<br>            //    CEGUI::System::getSingleton().notifyDisplaySizeChanged(<br>            //        CEGUI::Size(viewport->width(), viewport->height()) );<br>            //}<br>        }<br><br>        double currentTime = (state->getFrameStamp() ? state->getFrameStamp()->getSimulationTime() : 0.0);<br>        CEGUI::System::getSingleton().injectTimePulse( (currentTime - _lastSimulationTime)/1000.0 );<br>        CEGUI::System::getSingleton().renderAllGUIContexts();<br>        _lastSimulationTime = currentTime;<br><br>        glPopAttrib();<br>        glPopMatrix();<br>    }<br>    cout << "ClientCEGUIDrawable: drawImplementation: Completed" << endl;<br>}<br><br>void ClientCEGUIDrawable::initializeControls(){<br>    cout << "ClientCEGUIDrawable: Controls: Initializing" << endl;<br>    CEGUI::SchemeManager::getSingleton().createFromFile( "TaharezLook.scheme" );<br>    CEGUI::FontManager::getSingleton().createFromFile( "DejaVuSans-10.font" );<br><br>    CEGUI::System::getSingleton().getDefaultGUIContext().getMouseCursor().setDefaultImage( "TaharezLook/MouseArrow" );<br><br>    // For Tooltips when I'm ready<br>    // CEGUI::System::getSingleton().getDefaultGUIContext().setDefaultTooltipType( "TaharezLook/Tooltip" );<br><br>    CEGUI::System::getSingleton().getDefaultGUIContext().setDefaultFont( "DejaVuSans-10" );<br>    <br>    // CEGUI::System::getSingleton().getDefaultFont()->setAutoScaled( false );<br><br>    CEGUI::WindowManager& wmgr = CEGUI::WindowManager::getSingleton();<br>    CEGUI::Window* root_window = wmgr.createWindow( "DefaultWindow", "root" );<br>    CEGUI::System::getSingleton().getDefaultGUIContext().setRootWindow( root_window );<br><br>    CEGUI::FrameWindow* frame_window = static_cast<CEGUI::FrameWindow*>(<br>        wmgr.createWindow( "TaharezLook/FrameWindow", "testWindow" ));<br><br><br>    // position a quarter of the way in from the top-left of parent.<br>    frame_window->setPosition( CEGUI::UVector2( CEGUI::UDim( 0.25f, 0.0f ), CEGUI::UDim( 0.25f, 0.0f ) ) );<br>    // set size to be half the size of the parent<br>    frame_window->setSize( CEGUI::USize( CEGUI::UDim( 0.5f, 0.0f ), CEGUI::UDim( 0.5f, 0.0f ) ) );<br><br>    //demoWindow->setMinSize( CEGUI::UVector2(cegui_reldim(0.1f), cegui_reldim(0.1f)) );<br>    frame_window->setText( "Example Dialog" );<br><br>    CEGUI::PushButton* demoButtonOK = static_cast<CEGUI::PushButton*>(<br>        CEGUI::WindowManager::getSingleton().createWindow("TaharezLook/Button", "DemoButtonOK") );<br>    demoButtonOK->setPosition( CEGUI::UVector2(cegui_reldim(0.3f), cegui_reldim(0.75f)) );<br>    demoButtonOK->setSize( CEGUI::USize( CEGUI::UDim( 0.1f, 0.1f ), CEGUI::UDim( 0.2f, 0.2f ) ) );<br>    demoButtonOK->setText( "OK" );<br><br>    frame_window->subscribeEvent( CEGUI::FrameWindow::EventCloseClicked,<br>        CEGUI::Event::Subscriber(&ClientCEGUIDrawable::handleClose, this) );<br>    root_window->addChild( demoButtonOK );<br>    root_window->addChild( frame_window );<br>    cout << "ClientCEGUIDrawable: Controls: Initialized" << endl;<br>}<br><br>bool ClientCEGUIDrawable::handleClose( const CEGUI::EventArgs& e ){<br>    cout << "ClientCEGUIDrawable: handleClose: starting" << endl;<br>    //CEGUI::WindowManager::getSingleton().getWindow("DemoWindow")->setVisible( false );<br>    CEGUI::System::destroy();<br>    //CEGUI::OpenGL3Renderer::destroy(<br>    CEGUI::OpenGLRenderer::destroy(<br>        static_cast<CEGUI::OpenGLRenderer&>(<br>            //Commented out from CEGUI's online tutorial. I just figured it was talking<br>            //about the renderer.<br>            //*d_renderer<br>            *(CEGUI::System::getSingleton().getRenderer())<br>        )<br>    );<br>    cout << "ClientCEGUIDrawable: handleClose: Completed" << endl;<br>    return true;<br>}</div><br></div>event_handler_cegui.cpp: This was also taken from the cookbook and updated. I have one piece left, but the CEGUI code is deprecated as far as I can tell. If this is where my problem is, then I would be grateful for thoughts or insights on how to update it since I'm not really sure what it is even doing.<br><div style="margin-left:40px">#include "../headers/event_handler_cegui.hpp"<br><br>bool EventHandlerCEGUI::handle( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa ) {<br>    cout << "EventHandlerCEGUI: Handle: Handling" << endl;<br>    int x = ea.getX(), y = ea.getY(), width = ea.getWindowWidth(), height = ea.getWindowHeight();<br>    if ( ea.getMouseYOrientation()==osgGA::GUIEventAdapter::Y_INCREASING_UPWARDS )<br>        cout << "    EventHandlerCEGUI: Handle: Y Increasing Upwards?" << endl;<br>        y = ea.getWindowHeight() - y;<br>    if ( !CEGUI::System::getSingletonPtr() )<br>        cout << "    EventHandlerCEGUI: Handle: No CEGUI Singleton" << endl;<br>        return false;<br><br>    CEGUI::GUIContext& context = CEGUI::System::getSingleton().getDefaultGUIContext();<br><br>    switch ( ea.getEventType() )<br>    {<br>    case osgGA::GUIEventAdapter::PUSH:<br>        cout << "    EventHandlerCEGUI: Handle: PUSH" << endl;<br>        context.injectMousePosition( x, y );<br>        context.injectMouseButtonDown( convertMouseButton(ea.getButton()) );<br>        break;<br>    case osgGA::GUIEventAdapter::RELEASE:<br>        cout << "    EventHandlerCEGUI: Handle: RELEASE" << endl;<br>        context.injectMousePosition( x, y );<br>        context.injectMouseButtonUp( convertMouseButton(ea.getButton()) );<br>        break;<br>    case osgGA::GUIEventAdapter::SCROLL:<br>        cout << "    EventHandlerCEGUI: Handle: SCROLL" << endl;<br>        if ( ea.getScrollingMotion()==osgGA::GUIEventAdapter::SCROLL_DOWN )<br>            context.injectMouseWheelChange( -1 );<br>        else if ( ea.getScrollingMotion()==osgGA::GUIEventAdapter::SCROLL_UP )<br>            context.injectMouseWheelChange( +1 );<br>        break;<br>    case osgGA::GUIEventAdapter::DRAG:<br>        cout << "    EventHandlerCEGUI: Handle: DRAG" << endl;<br>    case osgGA::GUIEventAdapter::MOVE:<br>        cout << "    EventHandlerCEGUI: Handle: MOVE" << endl;<br>        context.injectMousePosition( x, y );<br>        break;<br>    case osgGA::GUIEventAdapter::RESIZE:<br>        cout << "    EventHandlerCEGUI: Handle: RESIZE" << endl;<br>        if ( _camera.valid() )<br>        {<br>            _camera->setProjectionMatrix( osg::Matrixd::ortho2D(0.0, width, 0.0, height) );<br>            _camera->setViewport( 0.0, 0.0, width, height );<br>        }<br>        break;<br>    default:<br>        return false;<br>    }<br><br>    /*<br>     * No idea what this would actually do for me.<br>     * The code for getting the window is deprecated though.<br>     * So, it would take some work.<br>     *<br>    CEGUI::Window* rootWindow = CEGUI::System::getSingleton().getGUISheet();<br>    if ( rootWindow )<br>    {<br>        CEGUI::Window* anyWindow = rootWindow->getChildAtPosition( CEGUI::Vector2(x, y) );<br>        if ( anyWindow ) return true;<br>    }*/<br>    cout << "EventHandlerCEGUI: Handle: Not Handled" << endl;<br>    return false;<br>}<br><br>CEGUI::MouseButton EventHandlerCEGUI::convertMouseButton( int button ){<br>    cout << "EventHandlerCEGUI: Convert Mouse: Converting" << endl;<br>    switch ( button )<br>    {<br>    case osgGA::GUIEventAdapter::LEFT_MOUSE_BUTTON:<br>        return CEGUI::LeftButton;<br>    case osgGA::GUIEventAdapter::MIDDLE_MOUSE_BUTTON:<br>        return CEGUI::MiddleButton;<br>    case osgGA::GUIEventAdapter::RIGHT_MOUSE_BUTTON:<br>        return CEGUI::RightButton;<br>    default: break;<br>    }<br>    cout << "EventHandlerCEGUI: Convert Mouse: Converted" << endl;<br>    return static_cast<CEGUI::MouseButton>(button);<br>}</div><br></div>Thank you in advance for your assistance,<br></div>Jay<br></div>