<div dir="ltr"><div><span style="font-size:12.8px">Hi Jay,</span></div><div><span style="font-size:12.8px">My guess is that your drawable gets culled, as you don't disable culling for it.</span></div><div><span style="font-size:12.8px">Laurens.</span></div><div><span style="font-size:12.8px"><br></span></div><span style="font-size:12.8px">geode->setCullingActive(false)</span><wbr style="font-size:12.8px"><span style="font-size:12.8px">;</span><br style="font-size:12.8px"><span style="font-size:12.8px">geode->addDrawable( new ClientCEGUIDrawable );</span><br style="font-size:12.8px"></div><div class="gmail_extra"><br><div class="gmail_quote">On Sun, Jan 21, 2018 at 1:27 AM, Jay Carson <span dir="ltr"><<a href="mailto:james.carson.direct@gmail.com" target="_blank">james.carson.direct@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi,<br>
Version Information:<br>
OSG: 3.4.0<br>
CEGUI: 0.8.7<br>
<br>
Problem: I am unable to get the osg::Drawable for CEGUI to draw. The drawImplementation method never even gets called.<br>
<br>
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" rel="noreferrer" target="_blank">http://static.cegui.org.uk/<wbr>docs/0.8.7/porting7to8.html</a>).<br>
<br>
Here is my code, please let me know why you think the drawable isn't being called.<br>
<br>
<br>
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>
<br>
Code:<br>
osg::Camera* ClientMaster::create_hud_<wbr>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()-<wbr>>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(<wbr>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)<wbr>;<br>
    geode->addDrawable( new ClientCEGUIDrawable );<br>
    geode->getOrCreateStateSet()-><wbr>setAttributeAndModes( new osg::BlendFunc );<br>
    geode->getOrCreateStateSet()-><wbr>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.<wbr>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>
}<br>
<br>
<br>
<br>
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>
<br>
Code:<br>
#include "../headers/client_cegui_<wbr>drawable.hpp"<br>
<br>
ClientCEGUIDrawable::<wbr>ClientCEGUIDrawable() : _lastSimulationTime(0.0), _activeContextID(0), _initialized(false) {<br>
    cout << "ClientCEGUIDrawable: Initializing" << endl;<br>
    setSupportsDisplayList( false );<br>
    setDataVariance( osg::Object::DYNAMIC );<br>
    getOrCreateStateSet()-><wbr>setMode( GL_LIGHTING, osg::StateAttribute::OFF );<br>
    getOrCreateStateSet()-><wbr>setMode( GL_DEPTH_TEST, osg::StateAttribute::OFF );<br>
<br>
    cout << "ClientCEGUIDrawable: Initialized" << endl;<br>
}<br>
<br>
ClientCEGUIDrawable::<wbr>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::<wbr>initialize_resource_provider( void ){<br>
    cout << "ClientCEGUIDrawable: Resource Provider: Initializing" << endl;<br>
    CEGUI::<wbr>DefaultResourceProvider* resource_provider =<br>
        static_cast<CEGUI::<wbr>DefaultResourceProvider*>( CEGUI::System::getSingleton().<wbr>getResourceProvider() );<br>
    resource_provider-><wbr>setResourceGroupDirectory( "schemes",     "./datafiles/gui/schemes/"     );<br>
    resource_provider-><wbr>setResourceGroupDirectory( "imagesets",   "./datafiles/gui/imagesets/"   );<br>
    resource_provider-><wbr>setResourceGroupDirectory( "fonts",       "./datafiles/gui/fonts/"       );<br>
    resource_provider-><wbr>setResourceGroupDirectory( "layouts",     "./datafiles/gui/layouts/"     );<br>
    resource_provider-><wbr>setResourceGroupDirectory( "looknfeel",   "./datafiles/gui/looknfeel/"   );<br>
    resource_provider-><wbr>setResourceGroupDirectory( "lua_scripts", "./datafiles/gui/lua_scripts/" );<br>
<br>
    CEGUI::ImageManager::<wbr>setImagesetDefaultResourceGrou<wbr>p( "imagesets"   );<br>
    CEGUI::Font::<wbr>setDefaultResourceGroup(                 "fonts"       );<br>
    CEGUI::Scheme::<wbr>setDefaultResourceGroup(               "schemes"     );<br>
    CEGUI::WidgetLookManager::<wbr>setDefaultResourceGroup(    "looknfeel"   );<br>
    CEGUI::WindowManager::<wbr>setDefaultResourceGroup(        "layouts"     );<br>
    CEGUI::ScriptModule::<wbr>setDefaultResourceGroup(         "lua_scripts" );<br>
<br>
    cout << "ClientCEGUIDrawable: Resource Provider: Initialized" << endl;<br>
}<br>
<br>
void ClientCEGUIDrawable::<wbr>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::<wbr>bootstrapSystem();<br>
<br>
        if ( !CEGUI::System::<wbr>getSingletonPtr() ) return;<br>
<br>
        this->initialize_resource_<wbr>provider();<br>
<br>
        const_cast<<wbr>ClientCEGUIDrawable*>(this)-><wbr>initializeControls();<br>
        _activeContextID = contextID;<br>
        _initialized = true;<br>
    }<br>
    else if ( contextID==_activeContextID )<br>
    {<br>
        osg::State* state = renderInfo.getState();<br>
        state->disableAllVertexArrays(<wbr>);<br>
        state->disableTexCoordPointer( 0 );<br>
<br>
        glPushMatrix();<br>
        glPushAttrib( GL_ALL_ATTRIB_BITS );<br>
<br>
        CEGUI::OpenGLRenderer* renderer = static_cast<CEGUI::<wbr>OpenGLRenderer*>(<br>
        //CEGUI::OpenGL3Renderer* renderer = static_cast<CEGUI::<wbr>OpenGL3Renderer*>(<br>
            CEGUI::System::getSingleton().<wbr>getRenderer() );<br>
        osg::Viewport* viewport = renderInfo.getCurrentCamera()-<wbr>>getViewport();<br>
        if ( renderer && viewport )<br>
        {<br>
            //const CEGUI::Size& size = renderer->getDisplaySize();<br>
            //if ( size.d_width!=viewport->width(<wbr>) || size.d_height!=viewport-><wbr>height() )<br>
            //{<br>
            //    CEGUI::System::getSingleton().<wbr>notifyDisplaySizeChanged(<br>
            //        CEGUI::Size(viewport->width(), viewport->height()) );<br>
            //}<br>
        }<br>
<br>
        double currentTime = (state->getFrameStamp() ? state->getFrameStamp()-><wbr>getSimulationTime() : 0.0);<br>
        CEGUI::System::getSingleton().<wbr>injectTimePulse( (currentTime - _lastSimulationTime)/1000.0 );<br>
        CEGUI::System::getSingleton().<wbr>renderAllGUIContexts();<br>
        _lastSimulationTime = currentTime;<br>
<br>
        glPopAttrib();<br>
        glPopMatrix();<br>
    }<br>
    cout << "ClientCEGUIDrawable: drawImplementation: Completed" << endl;<br>
}<br>
<br>
void ClientCEGUIDrawable::<wbr>initializeControls(){<br>
    cout << "ClientCEGUIDrawable: Controls: Initializing" << endl;<br>
    CEGUI::SchemeManager::<wbr>getSingleton().createFromFile( "TaharezLook.scheme" );<br>
    CEGUI::FontManager::<wbr>getSingleton().createFromFile( "DejaVuSans-10.font" );<br>
<br>
    CEGUI::System::getSingleton().<wbr>getDefaultGUIContext().<wbr>getMouseCursor().<wbr>setDefaultImage( "TaharezLook/MouseArrow" );<br>
<br>
    // For Tooltips when I'm ready<br>
    // CEGUI::System::getSingleton().<wbr>getDefaultGUIContext().<wbr>setDefaultTooltipType( "TaharezLook/Tooltip" );<br>
<br>
    CEGUI::System::getSingleton().<wbr>getDefaultGUIContext().<wbr>setDefaultFont( "DejaVuSans-10" );<br>
<br>
    // CEGUI::System::getSingleton().<wbr>getDefaultFont()-><wbr>setAutoScaled( false );<br>
<br>
    CEGUI::WindowManager& wmgr = CEGUI::WindowManager::<wbr>getSingleton();<br>
    CEGUI::Window* root_window = wmgr.createWindow( "DefaultWindow", "root" );<br>
    CEGUI::System::getSingleton().<wbr>getDefaultGUIContext().<wbr>setRootWindow( root_window );<br>
<br>
    CEGUI::FrameWindow* frame_window = static_cast<CEGUI::<wbr>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(<wbr>0.1f), cegui_reldim(0.1f)) );<br>
    frame_window->setText( "Example Dialog" );<br>
<br>
    CEGUI::PushButton* demoButtonOK = static_cast<CEGUI::PushButton*<wbr>>(<br>
        CEGUI::WindowManager::<wbr>getSingleton().createWindow("<wbr>TaharezLook/Button", "DemoButtonOK") );<br>
    demoButtonOK->setPosition( CEGUI::UVector2(cegui_reldim(<wbr>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::<wbr>EventCloseClicked,<br>
        CEGUI::Event::Subscriber(&<wbr>ClientCEGUIDrawable::<wbr>handleClose, this) );<br>
    root_window->addChild( demoButtonOK );<br>
    root_window->addChild( frame_window );<br>
    cout << "ClientCEGUIDrawable: Controls: Initialized" << endl;<br>
}<br>
<br>
bool ClientCEGUIDrawable::<wbr>handleClose( const CEGUI::EventArgs& e ){<br>
    cout << "ClientCEGUIDrawable: handleClose: starting" << endl;<br>
    //CEGUI::WindowManager::<wbr>getSingleton().getWindow("<wbr>DemoWindow")->setVisible( false );<br>
    CEGUI::System::destroy();<br>
    //CEGUI::OpenGL3Renderer::<wbr>destroy(<br>
    CEGUI::OpenGLRenderer::<wbr>destroy(<br>
        static_cast<CEGUI::<wbr>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(<wbr>).getRenderer())<br>
        )<br>
    );<br>
    cout << "ClientCEGUIDrawable: handleClose: Completed" << endl;<br>
    return true;<br>
}<br>
<br>
<br>
<br>
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>
<br>
Code:<br>
#include "../headers/event_handler_<wbr>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()==<wbr>osgGA::GUIEventAdapter::Y_<wbr>INCREASING_UPWARDS )<br>
        cout << "    EventHandlerCEGUI: Handle: Y Increasing Upwards?" << endl;<br>
        y = ea.getWindowHeight() - y;<br>
    if ( !CEGUI::System::<wbr>getSingletonPtr() )<br>
        cout << "    EventHandlerCEGUI: Handle: No CEGUI Singleton" << endl;<br>
        return false;<br>
<br>
    CEGUI::GUIContext& context = CEGUI::System::getSingleton().<wbr>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.<wbr>getButton()) );<br>
        break;<br>
    case osgGA::GUIEventAdapter::<wbr>RELEASE:<br>
        cout << "    EventHandlerCEGUI: Handle: RELEASE" << endl;<br>
        context.injectMousePosition( x, y );<br>
        context.injectMouseButtonUp( convertMouseButton(ea.<wbr>getButton()) );<br>
        break;<br>
    case osgGA::GUIEventAdapter::<wbr>SCROLL:<br>
        cout << "    EventHandlerCEGUI: Handle: SCROLL" << endl;<br>
        if ( ea.getScrollingMotion()==<wbr>osgGA::GUIEventAdapter::<wbr>SCROLL_DOWN )<br>
            context.<wbr>injectMouseWheelChange( -1 );<br>
        else if ( ea.getScrollingMotion()==<wbr>osgGA::GUIEventAdapter::<wbr>SCROLL_UP )<br>
            context.<wbr>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::<wbr>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().<wbr>getGUISheet();<br>
    if ( rootWindow )<br>
    {<br>
        CEGUI::Window* anyWindow = rootWindow-><wbr>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::<wbr>convertMouseButton( int button ){<br>
    cout << "EventHandlerCEGUI: Convert Mouse: Converting" << endl;<br>
    switch ( button )<br>
    {<br>
    case osgGA::GUIEventAdapter::LEFT_<wbr>MOUSE_BUTTON:<br>
        return CEGUI::LeftButton;<br>
    case osgGA::GUIEventAdapter::<wbr>MIDDLE_MOUSE_BUTTON:<br>
        return CEGUI::MiddleButton;<br>
    case osgGA::GUIEventAdapter::RIGHT_<wbr>MOUSE_BUTTON:<br>
        return CEGUI::RightButton;<br>
    default: break;<br>
    }<br>
    cout << "EventHandlerCEGUI: Convert Mouse: Converted" << endl;<br>
    return static_cast<CEGUI::<wbr>MouseButton>(button);<br>
}<br>
<br>
<br>
<br>
Thank you in advance for your assistance,<br>
Jay<br>
<br>
------------------<br>
Read this topic online here:<br>
<a href="http://forum.openscenegraph.org/viewtopic.php?p=72815#72815" rel="noreferrer" target="_blank">http://forum.openscenegraph.<wbr>org/viewtopic.php?p=72815#<wbr>72815</a><br>
<br>
<br>
<br>
<br>
<br>
______________________________<wbr>_________________<br>
osg-users mailing list<br>
<a href="mailto:osg-users@lists.openscenegraph.org">osg-users@lists.<wbr>openscenegraph.org</a><br>
<a href="http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org" rel="noreferrer" target="_blank">http://lists.openscenegraph.<wbr>org/listinfo.cgi/osg-users-<wbr>openscenegraph.org</a><br>
</blockquote></div><br></div>