Jason, here's the basic code. "hwnd" is the handle of the .NET control (Control::Handle property) in which to embed the viewer.
osgViewer::Viewer* viewer = new osgViewer::Viewer(); osg::ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits(); traits->inheritedWindowData = new osgViewer::GraphicsWindowWin32::WindowData( (HWND)hwnd ); traits->setInheritedWindowPixelFormat = true; traits->doubleBuffer = true; traits->windowDecoration = true; traits->sharedContext = NULL; traits->supportsResize = true; RECT rect; ::GetWindowRect( (HWND)hwnd, &rect ); traits->x = 0; traits->y = 0; traits->width = rect.right - rect.left; traits->height = rect.bottom - rect.top; osg::ref_ptr<osg::GraphicsContext> gc = osg::GraphicsContext::createGraphicsContext( traits.get() ); viewer->getCamera()->setGraphicsContext( gc.get() ); viewer->getCamera()->setViewport( new osg::Viewport( 0, 0, traits->width, traits->height ) ); HTH. Glenn On Wed, May 28, 2008 at 2:02 PM, Jason Beverage <[EMAIL PROTECTED]> wrote: > Hi Glenn, > > Are you still embedding your .NET control in a Window Form Control? If so, > how are you accomplishing this? > > In the Producer days, one could just call viewer.setWindow with the > window handle to the control, but I can't find an equivalent using the new > osgViewer classes. The slave camera approach that Hesicong posted was the > closest I could find. > > Thanks! > > Jason > > > On Wed, May 28, 2008 at 1:25 PM, Glenn Waldron <[EMAIL PROTECTED]> wrote: > >> Jason, >> >> Afraid not. My theory was that either the master or slave camera >> projection matrix was not being updated when the window was resized... but I >> never could confirm this. >> >> In my case I skirted the issue by doing away with the use of a slave >> camera in my application. I was using the slave to do an embedded viewer >> tied to a .NET control, but that approach is no longer necessary. >> >> Glenn >> >> >> >> On Wed, May 28, 2008 at 12:48 PM, Jason Beverage <[EMAIL PROTECTED]> >> wrote: >> >>> Hi Glenn, >>> >>> Did you ever find a fix for this issue? I believe I might be running >>> into the same problem. >>> >>> Thanks, >>> >>> Jason >>> >>> >>> On Tue, Mar 25, 2008 at 8:24 AM, Glenn Waldron <[EMAIL PROTECTED]> >>> wrote: >>> >>>> Yes, I think you are right, it's something in that vein. I can trick it >>>> into returning the correct result by scaling the input (normalized) >>>> coordinates to compensate for the change in the viewport aspect ratio. So >>>> that implies that somewhere, old values are still lurking around. >>>> >>>> Thanks again for your thoughts on this - I will revisit the issue when >>>> time allows :) >>>> Glenn >>>> >>>> >>>> On Tue, Mar 25, 2008 at 12:56 AM, Guy <[EMAIL PROTECTED]> wrote: >>>> >>>>> Hello, >>>>> I'm not sure about the problem you are talking about, but just give a >>>>> suggestion that might help. >>>>> Maybe the slave camera cache its size, the cache does not update with >>>>> the >>>>> Viewport change, and then the intersection takes the data from the >>>>> cache? >>>>> You could try to clear the cache and see if the problem continues. >>>>> And of course maybe it has nothing to do with it, and then I apologize >>>>> for wasting your time. >>>>> >>>>> Guy. >>>>> >>>>> >>>>> -----Original Message----- >>>>> From: [EMAIL PROTECTED] >>>>> [mailto:[EMAIL PROTECTED] On Behalf Of >>>>> Jean-S?bastien Guay >>>>> Sent: Monday, March 24, 2008 10:03 PM >>>>> To: OpenSceneGraph Users >>>>> Subject: Re: [osg-users] osgViewer::View::getCameraContainingPosition() >>>>> returns weird results when using slave cameras >>>>> >>>>> Hi Glenn, >>>>> >>>>> > In a nutshell, I am using a single slave camera (in order to embed my >>>>> > OSG surface in a .NET control). If I resize the viewport after >>>>> creation, >>>>> > computeIntersections() no longer returns correct results -- the Y >>>>> value >>>>> > is incorrectly scaled. It only works correctly if I resize the window >>>>> > back to its original aspect ratio. >>>>> >>>>> Yes, that sounds like a different problem. In my case, I was not >>>>> getting >>>>> >>>>> correct results from computeIntersections() whenever CompositeViewer >>>>> was >>>>> >>>>> using a single view with slave cameras - no resizing at all involved, >>>>> just using setUpViewAcrossAllScreens(). >>>>> >>>>> You'll have to dig further. I suggest you try starting with a >>>>> breakpoint >>>>> >>>>> in Viewer/CompositeViewer::eventTraversal() (depending on the viewer >>>>> type you use) and compare the behavior before and after resizing the >>>>> viewport. >>>>> >>>>> Good luck, >>>>> >>>>> J-S >>>>> -- >>>>> ______________________________________________________ >>>>> Jean-Sebastien Guay [EMAIL PROTECTED] >>>>> http://www.cm-labs.com/ >>>>> http://whitestar02.webhop.org/ >>>>> _______________________________________________ >>>>> osg-users mailing list >>>>> [email protected] >>>>> >>>>> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.or >>>>> g<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 >>>>> >>>> >>>> >>>> >>>> -- >>>> Glenn Waldron : Pelican Mapping : http://pelicanmapping.com : >>>> 703-652-4791 >>>> >>>> _______________________________________________ >>>> 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 >>> >>> >> >> >> -- >> Glenn Waldron : Pelican Mapping : http://pelicanmapping.com : >> 703-652-4791 >> >> _______________________________________________ >> 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 > > -- Glenn Waldron : Pelican Mapping : http://pelicanmapping.com : 703-652-4791
_______________________________________________ osg-users mailing list [email protected] http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

