I should have said that I was drawing the viewer in a pixel buffer in
my other question [1], that now leads to this one...
I'm streaming the pixel buffer data and displaying/manipulating the
scene in/from a webpage.
The offscreen viewer obviously hasn't any window, nor associated event queue.
I would like to forward the keyboard/mouse inputs emitted by the
JavaScript code in my webpage, so that I can leverage upon the OSG
manipulators (namely, trackball).
At the moment, I'm doing the following:
viewer.getEventQueue()->setGraphicsContext(pbuffer);
viewer.getEventQueue()->syncWindowRectangleWithGraphcisContext();
These operations are normally performed when initializing a
GraphicsWindow, e.g. in GraphicsWindowWin32::init() and are thus
missing when initializing a pbuffer, in e.g. PixelBufferWin32::init().
The syncWindowRectangleWithGraphcisContext (ever noticed the
misspelling?) was the missing thing for me in [1]. Thus, the
GUIEventAdapter created when processing an event in the EventQueue had
its _Xmin, _Xmax, _Ymin, _Ymax, _windowWidth and _windowHeight had
their default values.
So, am I adding correctly an event queue to an offscreen viewer/view this way?
Émeric
[1] http://lists.openscenegraph.org/htdig.cgi/osg-users-openscenegraph.org/2015-February/269273.html
_______________________________________________
osg-users mailing list
osg-...@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
> Thanks for spotting to typo. I hadn't noticed this before, and it hadn't
> been reported either. I am fixing this and will get it checked in once my
> clean build has completed.
My first major contribution to the OSG community ;-)
> As for implementing an off screen viewer functionality using a pbuffer. I
> haven't ever tried this on contemplated it. It should be possible to mimic
> traditional window events by injecting them into the EventQueue, and you've
> spotted passing on the appropriate window size will be required. I can't
> provide any specific advice though as you are already further down the road
> of trying something I haven't done yet :-)
OK, thanks for feedback.
For completeness, you'll also had to override
ViewerBase::checkEvents() if you want to leverage on viewer's
on-demand run scheme. Indeed, the Viewer and CompositeViewer
implementations only check for events from devices and windows. With
an off-screen viewer, you won't get any window, only views for which
you need to take care of setting a graphics contexts as I proposed
previously.
For a CompositeViewer-inherited off-screen viewer, checkEvents() looks like:
bool OffscreenViewer::checkEvents()
{
if (CompositeViewer::checkEvents())
return true;
Views views;
getViews(views);
// Check events from any views
for (Views::iterator vitr = views.begin();
vitr != views.end();
++vitr)
{
if ((*vitr)->getEventQueue() && !((*vitr)->getEventQueue()->empty()))
return true;
}
return false;
}
Hope this helps,
Émeric