Hi Natasha, I'm not familiar with GTK so can't help with this directly. As a general comment I'd suggest doing the port in parts. So move the loading and rendering across to an osgViewer::Viewer based app using osgViewer's native windowing support, this will allow you to get something up on the screen and a bit of exposure with the basics of the viewer. Then once you are happy port across the using GTK by either using the window inhertiance or subclassing from GraphicsWindow to provide a GraphicsWindowGTK. Window inheritance is the route most similar to Producer's means of adapting to other windowing toolkits.
Robert. On Tue, Sep 15, 2009 at 6:19 PM, Natasha Westland <[email protected]>wrote: > The osgviewerGTK example does work but that embeds the viewer in its own > application. I have tried modifying the OSGGTKDrawingArea class so that it > would work given my scenario but to no avail (for example, I can't just open > a gtk dialog when instantiating an OSGGTKDrawingArea object. I tried > modifying the appropriate methods so instead of creating a new window, it > embeds itself using the code in my below example but I get the same > behavior). The viewer is created, embedded in the GTK application and then > is never seen again. > > The reason for the upgrade from OSG 1.0 to 2.8.2 was due to the upgrade of > our OS (from FC 5 to CentOS). The underlying libraries were newer and > mandated the upgrade. Thanks for the response. > > Natasha > > jp wrote: > > > Hi, > > > > does the osgviewerGTK example work? > > > > jp > > Natasha Westland wrote: > > > Hello,>> I am having difficulties upgrading from OSG 1.0 to 2.8.2 (on > CentOS) and> was hoping to tap into this wealth of knowledge> after failing > miserably poking around the source code and attempting to> retrofit the > example applications into my own.>> Using OSG 1.0, I have an application > which used an osgProducer to embed> a viewer in another (GTK+ based) > application. Using the below approach,> I am able to successfully render > images in the external application. In> my attempt to port to OSG 2.8.2,> I > am able to embed the viewer in the external application but I can't> seem to > render any images. (I've tried simply changing the> background color and > that doesn't work either.) Based on observations> in the debugger, it > appears that my viewer may not be> integrated properly with the gtk redrawing > thread of the external> application due to the fact that the visible (black) > view is> overdrawn by the external application at random times, and it is > never> seen again. Any pointers would be greatly appreciated. Thanks!>> > Natasha> [email protected]>> _**** Initialization of osgProducer viewer > using OSG 1.0: ****_>> osgProducer::Viewer viewer (BuildConfig());> > viewer.setUpViewer (osgProducer::Viewer::SKY_LIGHT_SOURCE |>> > osgProducer::Viewer::HEAD_LIGHT_SOURCE |>> > osgProducer::Viewer::STATE_MANIPULATOR |>> > osgProducer::Viewer::STATS_MANIPULATOR |>> > osgProducer::Viewer::VIEWER_MANIPULATOR );> gtk_init (&argc, &argv);>> > // set the xid of the GtkSocket and connect the GtkPlug> guint32 xid > = wGtkPlug; // gtksocket of external application> GtkWidget *plug = > gtk_plug_new(xid);> gtk_signal_connect(GTK_OBJECT(plug), > "destroy-event",> GTK_SIGNAL_FUNC(destroy_event), &viewer);>> // set the > viewer to display in the plug>> > viewer.getCamera(0)->getRenderSurface()->setWindow(gtk_plug_get_id(GTK_PLUG(plug)));>>> > // create a new thread to handle GTK events> > pthread_create(>k_thread, NULL, gtk_thread_loop, NULL);>> // create the > windows and run the threads.> viewer.realize();>> while( !viewer.done() > ) {> viewer.sync();> viewer.update();> // fire off > the cull and draw traversals of the scene.> viewer.frame();> > usleep(500000);> }>> Producer::CameraConfig*> BuildConfig(void) {> > Producer::RenderSurface *rs1 = new Producer::RenderSurface;> > rs1->setScreenNum(0);> rs1->setWindowName("external-app");> > rs1->setWindowRectangle (0,0,640,480);> Producer::Camera *camera1 = > new Producer::Camera;> camera1->setRenderSurface(rs1);> > camera1->setOffset( 0.0, 0.0 );> rs1->setInputRectangle> > (Producer::RenderSurface::InputRectangle(0.0,1.0,0.0,1.0));> > Producer::InputArea *ia = new Producer::InputArea;> > ia->addRenderSurface(rs1);> Producer::CameraConfig *cfg = new > Producer::CameraConfig;> cfg->addCamera("Camera 1",camera1);> > cfg->setInputArea(ia);> return cfg;> }>> void > *gtk_thread_loop(void *arg) {> gtk_main();> return NULL;> }>>> > _**** Rendering the images in OSG 1.0 is implemented as follows (same> for > OSG 2.8.2): ****_>> _loadedModel = osgDB::readNodeFile(sName);> if > (!_loadedModel) {> viewer.setClearColor( osg::Vec4( 0.9f, 0.9f, 0.9f, > 1.0) );> return 1;> }> viewer.setClearColor( osg::Vec4( 0.701961f, > 0.862745f, 0.949020f,> 1.0) );>> // optimize the scene graph, remove > rendundent nodes and state etc.> osgUtil::Optimizer optimizer;> > optimizer.optimize(_loadedModel.get());> //add the model to the > transform.> _modelTransform.get()->addChild(_loadedModel.get());>> // > set the scene to render> viewer.setSceneData(_rootNode.get());>> _**** > Initialization in OSG 2.8.2 is below: HELP - what am I doing> wrong? ****_>> > osgViewer::Viewer viewer;>> osg::ref_ptr<osg::GraphicsContext::Traits> > traits = new> osg::GraphicsContext::Traits;> traits->screenNum = 0;> > traits->x = 0;> traits->y = 0;> traits->width = 640;> traits->height > = 480;> traits->red = 8;> traits->blue = 8;> traits->green = 8;> > traits->alpha = 0;> traits->windowDecoration = false;> traits->pbuffer > = false;> traits->doubleBuffer = true;> traits->sharedContext = 0;> > traits->windowName = "external-app";>> gtk_init (&argc, &argv);>> > // set the xid of the GtkSocket and connect the GtkPlug> guint32 xid = > wGtkPlug;> GtkWidget *plug = gtk_plug_new(xid);> > gtk_signal_connect(GTK_OBJECT(plug), "destroy-event",> > GTK_SIGNAL_FUNC(destroy_event), &viewer);>> // Hike logging up> > osg::setNotifyLevel (osg::NOTICE);>> // set the viewer to display in the > plug> traits->inheritedWindowData = new> > osgViewer::GraphicsWindowX11::WindowData(gtk_plug_get_id(GTK_PLUG(plug)));> > viewer.getCamera()->setGraphicsContext> > (osg::GraphicsContext::createGraphicsContext(traits.get()));> > viewer.getCamera()->setViewport (new> osg::Viewport(0,0,traits->width, > traits->height));> viewer.setCameraManipulator (new > osgGA::TrackballManipulator());>> pthread_create(>k_thread, NULL, > gtk_thread_loop, NULL);> // create the windows and run the threads.> > viewer.realize();> while( !viewer.done() ) {> > viewer.frame();> usleep (50000);> }>> > _______________________________________________> osg-users mailing list> > [email protected]> > http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org> > > > > _______________________________________________ > osg-users mailing list > [email protected] > http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org > >
_______________________________________________ osg-users mailing list [email protected] http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

