You know what would be great? If you submitted a very basic example of this
to the osg-submissions mailing list, for inclusion in the osg examples
directory. Even if it is a Windows-only example, this might be helpful for
a lot of folks. Maybe someone else could extend it to work on Linux too.




2014-11-12 13:51 GMT+01:00 Chris Hidden <[email protected]>:

> Just wanted to update this thread and provide information on how I
> achieved what I was looking for.
>
> We managed to make a transparent application that you can click through
> with OSG.  This means that you can display models on the screen and have
> them move around with regards to input and at the same time.  The window is
> always on top thus whatever your scene graph contains will always be
> visible over top of any other application or window you have running at a
> given time.  Haven't tested all case scenarios but for any basic program
> such as chrome or MS word etc.. this works.  You can never focus the OSG
> window so make sure you have a way of exiting the program.  For development
> we just use ESC at the moment.
>
> To do this you'll need to edit the GraphicsWindowWin32.cpp file in your
> source.
>
> A few important parts are needed.  In bool
> GraphicsWindowWin32::createWindow()
>
> You will need to set the correct Windows and Windows Extended Styles:
>
>
> Code:
>
>
> //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
> windowStyle             = WS_VISIBLE | WS_POPUP ;
>                                                       ///
> extendedStyle = WS_EX_LAYERED | WS_EX_TOPMOST | WS_EX_TRANSPARENT |
> WS_EX_NOACTIVATE    ///
>
> /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
>
>
>
>
> Extended Styles are key here.... topmost, layered and transparent.  Also
> no activate should disallow the user from being able to focus the window.
>
> The next part allows the window to be transparent using BlurBehindWindows
> funcitonality.  As far as I know this only works in windows 7 and above.
>
>
> Code:
>
>                 DWM_BLURBEHIND bb = { 0 };
>                 HRGN hRgn = CreateRectRgn(0, 0, -1, -1);
>                 bb.dwFlags = DWM_BB_ENABLE | DWM_BB_BLURREGION;
>                 bb.hRgnBlur = hRgn;
>                 bb.fEnable = TRUE;
>                 bb.fTransitionOnMaximized = 0;
>                 DwmEnableBlurBehindWindow(_hwnd, &bb);
>
>
>
>
> Create the DWM_BLURBEHIND windows object.  Set the area and flags and then
> use the EnableBlur method to attach it to your window.
>
> Next we need to define the color key for what colors to omit so before the
> end of the createWindow() method add:
>
>
> Code:
>
> SetLayeredWindowAttributes(_hwnd, RGB(0, 0, 0), 0, LWA_COLORKEY);
>
>
>
>
> Then we need to do some work to disallow the window to be controlled if
> this is what you want.  So in  bool
> GraphicsWindowWin32::realizeImplementation()
>
> We need to edit the if(!::SetWindowPos) conditional:
>
>
>
> Code:
>
> if (!::SetWindowPos(_hwnd,
>                                 HWND_TOP,
>                                 _windowOriginXToRealize,
>                                 _windowOriginYToRealize,
>                                 _windowWidthToRealize,
>                                 _windowHeightToRealize,
>                                 SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE))
>                         {
>
> reportErrorForScreen("GraphicsWindowWin32::realizeImplementation() - Unable
> to show window", _traits->screenNum, ::GetLastError());
>                                 return false;
>                         }
>
>
>
>
> Here adding SWP_NOACTIVATE is important.  I believe the nosize and nomove
> help as well but I haven't been able to determine if they actually have an
> affect.
>
> Finally then in your scene youll need to set up your camera and viewer a
> little differently.
>
>
> Code:
>
>         osg::ref_ptr<osgViewer::Viewer> viewer = new osgViewer::Viewer();
>         // Set up your view however you want here.
>         osg::ref_ptr<osg::GraphicsContext::Traits> traits = new
> osg::GraphicsContext::Traits(*viewer->getCamera()->getGraphicsContext()->getTraits());
>         traits->alpha                           = true;
>         traits->doubleBuffer                    = true;
>         traits->blue                            = 8;
>         traits->red                                     = 8;
>         traits->green                           = 8;
>         traits->depth                           = 24;
>         traits->windowDecoration        = false;
>         osg::ref_ptr<osg::Camera> camera = new
> osg::Camera(*viewer->getCamera());
>         osg::ref_ptr<osg::GraphicsContext> graphicsContext =
> osg::GraphicsContext::createGraphicsContext(traits.get());
>         camera->setGraphicsContext(graphicsContext);
>         camera->setClearColor(osg::Vec4(.0,.0,.0,.0));
>         camera->setClearMask(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
>         viewer->setCamera(camera.get());
>         viewer->realize();
>
>
>         // Add your scene
>         viewer->setSceneData(root);
>
>         while (!viewer->done())
>         {
>                 viewer->frame();
>         }
>
>
>
>
> When setting up the traits, and camera we need to get them from the
> existing window.  So use the viewer object to obtain them.  Make sure you
> set the clear color and your GL Clear masks. Also don't forget to set the
> camera object to your viewer object.
>
> Thats it!  Hope this helps and I haven't missed to much.
>
> ------------------
> Read this topic online here:
> http://forum.openscenegraph.org/viewtopic.php?p=61586#61586
>
>
>
>
>
> _______________________________________________
> 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

Reply via email to