I notice that there is a major difference between osgViewer::Viewer and
osgViewer::CompositeViewer:

The following code:

osgViewer::CompositeViewer viewer;

 osg::ref_ptr<osg::GraphicsContext::Traits> traits = new
osg::GraphicsContext::Traits;
    traits->x = 100;
    traits->y = 100;
    traits->width = 1000;
    traits->height = 800;
    traits->windowDecoration = true;
    traits->doubleBuffer = true;
    traits->sharedContext = 0;

    osg::ref_ptr<osg::GraphicsContext> gc =
osg::GraphicsContext::createGraphicsContext(traits.get());

   osgViewer::View* view = new osgViewer::View;
    view->setName("View one");
    viewer.addView(view);

    view->setSceneData(scene.get());
    view->getCamera()->setViewport(new osg::Viewport(0, 0, traits->width /
2, traits->height / 2));
    view->getCamera()->setGraphicsContext(gc.get());

    viewer.realize(); // Context already created. No call to
GraphicsWIndowWIn32::GraphicsWIndowWin32 will be called



If I replace osgViewerCompositeViewer with a osgViewer::Viewer and remove
the creation of View, I get:

    viewer.realize(); // A new context is created. A new call to
GraphicsWIndowWIn32::GraphicsWIndowWin32 will be called


So it seems that osgViewer::Viewer does not respect? the previously created
GraphicsCOntext?

/Anders



On Thu, Nov 12, 2015 at 2:24 PM, Anders Backman <ande...@cs.umu.se> wrote:

> That is quite explicit. I was thinking about some method for intercepting
> events.
> I tried fiddling with creating a custom GraphicsWindowWin32 class, but it
> turns out that this is explicitly created internally in:
>
> osg::GraphicsContext* Win32WindowingSystem::createGraphicsContext(
> osg::GraphicsContext::Traits* traits )
> {
> ...
>         osg::ref_ptr<osgViewer::GraphicsWindowWin32> window = new
> GraphicsWindowWin32(traits);
>
> }
>
> So this does not seem to be the way to catch windows messages.
> My idea was that I could register my instance of the GraphicsWindowWin32
> to implement the virtual method:
>
> LRESULT GraphicsWindowWin32::handleNativeWindowingEvent( HWND hwnd, UINT
> uMsg, WPARAM wParam, LPARAM lParam )
>
>
> Where I could catch all windows events.
>
>
> Turns out that I do not have enough understanding when and where context
> etc is created.
>
> It seems that a GraphicsWindowWIn32 is first created at the call to:
>
>     osg::ref_ptr<osg::GraphicsContext> gc =
> osg::GraphicsContext::createGraphicsContext(traits.get());
>
>
> And then at the call to:
>
> viewer->realize();
>
> will also result in a call
> to GraphicsContext::createGraphicsContext(Traits* traits), which in turn
> will create yet another GraphicsWindowWin32.
>
> So there lies my problem, my call to viewer->realize() will override my
> first call to GraphicsContext::createGraphicsContext(traits.get());
>
>
> Not sure how to get around this though. Ideas?
>
> /Anders
>
>
> On Wed, Nov 11, 2015 at 5:05 PM, Trajce Nikolov NICK <
> trajce.nikolov.n...@gmail.com> wrote:
>
>> Hi Anders,
>>
>> here is what I do for this on Windows
>>
>>     while (!viewer->done())
>>     {
>>
>> #if defined(_WIN32)
>>         MSG msg;
>>         if (::PeekMessage(&msg,NULL,0,0,PM_NOREMOVE))
>>         {
>>             ::GetMessage(&msg, NULL, 0, 0);
>>
>>             if (wins.size())
>>             {
>>                 osgViewer::GraphicsHandleWin32 *hdl =
>> dynamic_cast<osgViewer::GraphicsHandleWin32*>(wins.at(0));
>>                 if(hdl)
>>                 {
>>                     WNDPROC fWndProc =
>> (WNDPROC)::GetWindowLongPtr(hdl->getHWND(), GWLP_WNDPROC);
>>                     if (fWndProc && hdl->getHWND())
>> {
>> ::CallWindowProc(fWndProc,hdl->getHWND(),msg.message, msg.wParam,
>> msg.lParam);
>> }
>>                 }
>>             }
>>         }
>> #endif
>>
>> On Wed, Nov 11, 2015 at 4:21 PM, Anders Backman <ande...@cs.umu.se>
>> wrote:
>>
>>> Hi.
>>>
>>> Trying the 3DConnexion SpaceNavigator with OSG. However I would like to
>>> stay away from VRPN and such dependencies...
>>>
>>> I was wondering how to best intercept Windows messages from the
>>> GraphicsWindowWin32 class.
>>>
>>> This class has a virtual method handleNativeWindowingEvent which I would
>>> like to override to catch custom messages from my device.
>>>
>>> Would it be possible to implement a derived class and have that
>>> instantiated instead of the standard osgViewer::GraphicsWindowWin32 one?
>>>
>>> Or is there a different method to listen to the  messages:
>>>
>>> ( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
>>>
>>> Thanks,
>>> Anders
>>>
>>>
>>>
>>> --
>>> __________________________________________
>>> Anders Backman, HPC2N
>>> 90187 Umeå University, Sweden
>>> and...@cs.umu.se http://www.hpc2n.umu.se
>>> Cell: +46-70-392 64 67
>>>
>>> _______________________________________________
>>> osg-users mailing list
>>> osg-users@lists.openscenegraph.org
>>> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>>>
>>>
>>
>>
>> --
>> trajce nikolov nick
>>
>> _______________________________________________
>> osg-users mailing list
>> osg-users@lists.openscenegraph.org
>> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>>
>>
>
>
> --
> __________________________________________
> Anders Backman, HPC2N
> 90187 Umeå University, Sweden
> and...@cs.umu.se http://www.hpc2n.umu.se
> Cell: +46-70-392 64 67
>



-- 
__________________________________________
Anders Backman, HPC2N
90187 Umeå University, Sweden
and...@cs.umu.se http://www.hpc2n.umu.se
Cell: +46-70-392 64 67
_______________________________________________
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to