Hi,

I wan't to show QT controls inside my OSG scene.
I introduced with the examples "osghud" and "osgQTWidgets" from the osg project.
First i create a sample project to solve my issue.
The problem is, that the QT- controls are never been displayed on my scene. 
I suppose the problem is the WidgetImage or the ImageHandler that i use, but i 
have no idea.

Any help is welcome.. :D


Thank you!

Cheers,
Tobias


Code:


TextView::TextView()
{
        _HUDCamera = new osg::Camera;
    _HUDCamera->setProjectionMatrix(osg::Matrix::ortho2D(0,640,0,480));
    _HUDCamera->setReferenceFrame(osg::Transform::ABSOLUTE_RF);
    _HUDCamera->setViewMatrix(osg::Matrix::identity());
    _HUDCamera->setClearMask(GL_DEPTH_BUFFER_BIT);
    _HUDCamera->setRenderOrder(osg::Camera::POST_RENDER);
    _HUDCamera->setAllowEventFocus(false);
    _HUDCamera->getOrCreateStateSet()->setMode( GL_LIGHTING, 
osg::StateAttribute::OFF );
    _HUDCamera->getOrCreateStateSet()->setMode( GL_BLEND, 
osg::StateAttribute::ON );
}


TextView::~TextView(void)
{
}

osg::Camera* TextView::creation()
{
        osg::ref_ptr<osgQt::QWidgetImage> widgetImage = new 
osgQt::QWidgetImage( createDemoWidget() );
        osg::ref_ptr<osg::Texture2D> texture = new osg::Texture2D;
    texture->setImage( widgetImage.get() );
    osg::ref_ptr<osgViewer::InteractiveImageHandler> handler = new 
osgViewer::InteractiveImageHandler( widgetImage.get(),texture,_HUDCamera);
    
    osg::ref_ptr<osg::Geometry> quad = 
osg::createTexturedQuadGeometry(osg::Vec3(), osg::X_AXIS, osg::Z_AXIS);
    quad->setEventCallback( handler.get() );
    quad->setCullCallback( handler.get() );

        osg::ref_ptr<osg::MatrixTransform> part = new osg::MatrixTransform;
        osg::ref_ptr<osg::Geode> geode = new osg::Geode;
    geode->addDrawable( quad.get() );
    geode->getOrCreateStateSet()->setTextureAttributeAndModes( 0, texture.get() 
);
    geode->getOrCreateStateSet()->setMode(GL_LIGHTING, 
osg::StateAttribute::OFF);
    
geode->getOrCreateStateSet()->setRenderingHint(osg::StateSet::TRANSPARENT_BIN);
    
        part->getOrCreateStateSet()->setTextureAttributeAndModes( 0, 
texture.get() );
    part->getOrCreateStateSet()->setRenderingHint( 
osg::StateSet::TRANSPARENT_BIN );
    part->addChild( geode.get() );

        /*osg::Node* n = osgDB::readNodeFile("C:\\cow.osg");*/

        _HUDCamera->addChild(part);
        
        return _HUDCamera;
}

QWidget* TextView::createDemoWidget( )
{
    QLabel* label = new QLabel;
    QPushButton* playBtn = new QPushButton("Play");
    QPushButton* stopBtn = new QPushButton("Stop");
    
    QWidget* demo = new QWidget;
    demo->setGeometry( 0, 0, 800, 600 );
    demo->setLayout( new QVBoxLayout );
    demo->layout()->addWidget( label );
    demo->layout()->addWidget( playBtn );
    demo->layout()->addWidget( stopBtn );
    
    return demo;
}

int main( int argc, char** argv )
{
    QApplication app( argc, argv );
        osgViewer::Viewer viewer;
        TextView* text = new TextView();
        
    osg::ref_ptr<osg::Group> root = new osg::Group;
        osg::Node* n = osgDB::readNodeFile("C:\\cow.osg");
        
        root->addChild(text->creation());   
    viewer.setSceneData( root.get() );
    viewer.setCameraManipulator( new osgGA::TrackballManipulator );
    viewer.addEventHandler( new osgViewer::StatsHandler );
    viewer.setUpViewOnSingleScreen();

    while ( !viewer.done() )
    {
        QCoreApplication::processEvents( QEventLoop::AllEvents, 100 );
        viewer.frame();
    }
    return 0;
}





 :D  :D

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=50475#50475





_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to