Re: [osg-users] OSG and WPF Questions
Hi, I am interested in WPF development as well. I have been playing around with the C++/CLI example to make a managed window. It seemed to work ok, except when I tried running it in Release mode, in which case it kept crashing, apparently with some memory corruption errors. I am using a relatively new snapshot from SVN for my OpenSceneGraph library. I have been using it in C++ for quite some time now with not too many problems (none that this great community has not helped with so far) :) I also started playing with OsgDotNet wrappers, but when I run it, it crashes trying to create the osgShadow wrapper. I noticed that it was made for OSG 2.0, so I downloaded that, but the download I had seems to be missing osgViewer in the include directories. I would love to know how you are able to get the DotNet stuff working, in one of these options. Thank you! Cheers, Rick -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=17729#17729 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] OSG and WPF Questions
Hello everyone, sorry for not writing so long, but I've been quite busy. I've tried some things to integrate OSG in .NET, but none of the solutions were satisfactory. As stated by Brian above, the WPF popup windows were flickering and I didn't manage to get the rendering to texture to work. Then I tried WinForms and there also at least the shadow of those windows were flickering. :( Now my boss said I should leave .NET aside and said I should try using the Fox-Toolkit. So everyone thank you for your help in .NET, but seems like I won't work on this topic any further. Cheers, Martin -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=15810#15810 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] OSG and WPF Questions
Hi Martin, I replied to your message earlier, but I thought I would post my experience here for the benefits of those reading this thread down the line: What I did was create a WinForms Control that hosts the OSG window. Look for examples (theres a good one on CodeProject I think) of integrating WPF and OpenGL. OSG will be the same. This is necessary because WPF uses HWNDs only for the top-level window - everything below is DirectX. But a WinForms control has an HWND, and WPF has an interoperability feature where it can host WinForms controls. There are limitations however - principally that transparent WPF popup windows (used for messages, menus, etc) do not show up properly over the OSG window under XP on most NVIDIA graphics cards (non-Quadro cards), according to NVIDIA. One possible workaround would be to have OSG render to a texture and then blit that to a WPF canvas. I have been intending to do this - but have not gotten around to it yet. Currently I just structured my menus to avoid the overlap. I should also mention that it is useful to crank up the OSG render loop during the initialization of the control - not at construction, IIRC. There are a few other hurdles, like having to use the dispatcher to update WPF UI widgets, when the update originates from OSG - but these type of threading issues are to be expected in this type of app anyway. A lot of my daily pain comes from having to drill a piece of information down through several layers of code (abstraction layers for threading and for the managed/native transition) to get from the UI to the OSG render loop, which is again, to be expected. I have found a couple of issues with events, such as WPF not passing drag events (that originated from outside the app) down to OSG - which I dealt with by handling the events at the WinForms level, and then drilling down the mouse drag info to my OSG render loop. Best of luck, Brian -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=15651#15651 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
[osg-users] OSG and WPF Questions
Hi Martin. >but the problem is that I want to integrate the window in the >WPF-application and not open another window :( take a closer look at OpenGLUserControl.h - it is a control with HWND for WPF. Regards Sergey ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] OSG and WPF Questions
Hi Again, Please check out osgActiveX. You'll see that viewer is capsulated as an MFC ActiveX control. Regards, Can 2009/7/29 Martin Fleck > Hello everyone, thank you for your replies :) > > @Sergey: Thank you but I've tried exactly that, but the problem is that I > want to integrate the window in the WPF-application and not open another > window :( > > @Andrew: If I'm not wrong WPF uses only one HWND for the whole application. > I guess that is where the problem lies, maybe I mix up my handlers. Anyway > thank you for the code, maybe another way is to create a winforms-control > and embed it into WPF (though it seems very strange OSG->Winforms->WPF). > > @Can: OK, I've never worked with ActiveX before so I'm not sure what you're > talking about, but I'll research it, thanks. > > Again, thank you all, it's great that there are people here willing to help > (and so fast :D) > > -- > Read this topic online here: > http://forum.openscenegraph.org/viewtopic.php?p=15602#15602 > > > > > > ___ > osg-users mailing list > osg-users@lists.openscenegraph.org > http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org > ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] OSG and WPF Questions
Martin - yes go for that if all else fails. Create a WinForms user control and embed it in WPF using the WindowsFormsHost class (from memory) Besides you're creating OSG in WPF so whats the problem about one WinForms class in WPF? Winforms (.NET2) is a subset of .NET3/3.5 so there will be no extra dependency. Besides I'm sure if you have good separation of view and logic (model view presenter style) your winforms user control can be very thin. On mine I just expose the osg::Viewer and that's it. BTW You may have a problem with opengl and WPF. Something about Z-order when rendering. I remember reading articles a while back that DirectX didn't integrate with WPF very well as the DX surface appeared at the highest in the Z-order, meaning things like context menus and text written by WPF wouldn't appear over the rendered area. Not sure if OpenGL will have the same problem or not. Anyway good luck, I'll be interested to see if this works. Please post your results! Andrew On Wed, Jul 29, 2009 at 2:43 PM, Martin Fleck wrote: > Hello everyone, thank you for your replies :) > > @Sergey: Thank you but I've tried exactly that, but the problem is that I > want to integrate the window in the WPF-application and not open another > window :( > > @Andrew: If I'm not wrong WPF uses only one HWND for the whole application. > I guess that is where the problem lies, maybe I mix up my handlers. Anyway > thank you for the code, maybe another way is to create a winforms-control > and embed it into WPF (though it seems very strange OSG->Winforms->WPF). > > @Can: OK, I've never worked with ActiveX before so I'm not sure what you're > talking about, but I'll research it, thanks. > > Again, thank you all, it's great that there are people here willing to help > (and so fast :D) > > -- > Read this topic online here: > http://forum.openscenegraph.org/viewtopic.php?p=15602#15602 > > > > > > ___ > osg-users mailing list > osg-users@lists.openscenegraph.org > http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org > ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] OSG and WPF Questions
Hello everyone, thank you for your replies :) @Sergey: Thank you but I've tried exactly that, but the problem is that I want to integrate the window in the WPF-application and not open another window :( @Andrew: If I'm not wrong WPF uses only one HWND for the whole application. I guess that is where the problem lies, maybe I mix up my handlers. Anyway thank you for the code, maybe another way is to create a winforms-control and embed it into WPF (though it seems very strange OSG->Winforms->WPF). @Can: OK, I've never worked with ActiveX before so I'm not sure what you're talking about, but I'll research it, thanks. Again, thank you all, it's great that there are people here willing to help (and so fast :D) -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=15602#15602 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] OSG and WPF Questions
Hi All. the following link might be of some help http://www.codeproject.com/KB/WPF/WPFOpenGL.aspx Regards Sergey ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] OSG and WPF Questions
Hi Martin, >From memory (I've worked with WPF before), each WPF control has at its root an HWND handle, which is what the osgDotNet demo uses to bind the open scene graph to the Windows forms control. So I think if you substitute the HWND handle with the WPF HWND the osgDotNet stuff should work. Here - I'm using this (but Windows Forms) to initialise an OpenSceneGraph on a WinForms user control (which is probably very similar to the osgDotNet demo) Try googling "WPF HWND Interop" and see what you come up with. Apologies if you have already tried this. Also I don't know how to stop the other window appearing - that sounds like an OSG problem and I'm no expert in OSG!! Cheers, Andrew / void RenderSurfaceView::InitOSG() { RECT rect; // Get the UserControl's Win32 handle HWND mHwnd=(HWND)this->Handle.ToInt32(); // Get the client area GetWindowRect(mHwnd, &rect); // Create a WindowData struct from the Win32 Handle // WindowData is used to pass in the Win32 window handle attached the GraphicsContext::Traits structure osg::ref_ptr windata = new osgViewer::GraphicsWindowWin32::WindowData(mHwnd); osg::ref_ptr traits = new osg::GraphicsContext::Traits; // Now setup the GraphicsContext::Traits by setting width, height, x position, y position etc... traits->x = 0; traits->y = 0; traits->width = rect.right - rect.left; traits->height = rect.bottom - rect.top; traits->windowDecoration = false; traits->doubleBuffer = true; traits->sharedContext = 0; traits->inheritedWindowData = windata; // We must set the pixelformat before we can create the OSG Rendering Surface PIXELFORMATDESCRIPTOR pixelFormat = { sizeof(PIXELFORMATDESCRIPTOR), 1, PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL|PFD_DOUBLEBUFFER, PFD_TYPE_RGBA, 32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 24, 0, 0, PFD_MAIN_PLANE, 0, 0, 0, 0 }; // Get the device context for the Win32 handle to the control HDC hdc = ::GetDC(mHwnd); if (hdc==0) { ::DestroyWindow(mHwnd); return ; } // Set the pixel format on the device context int pixelFormatIndex = ::ChoosePixelFormat(hdc, &pixelFormat); if (pixelFormatIndex==0) { ::ReleaseDC(mHwnd, hdc); ::DestroyWindow(mHwnd); return ; } if (!::SetPixelFormat(hdc, pixelFormatIndex, &pixelFormat)) { ::ReleaseDC(mHwnd, hdc); ::DestroyWindow(mHwnd); return ; } // Create an Open Scene Graph graphics context osg::ref_ptr gc = osg::GraphicsContext::createGraphicsContext(traits); // Create an Open Scene Graph camera this->camera = new osg::Camera; osg::CullSettings::CullingMode cullMode = osg::CullSettings::ENABLE_ALL_CULLING; // Force all culling on camera->setCullingMode(cullMode); // Set the graphics context on the camera and the viewport camera->setGraphicsContext(gc); camera->setViewport(new osg::Viewport(0,0,traits->width,traits->height)); camera->setDrawBuffer(GL_BACK); camera->setReadBuffer(GL_BACK); // Finally, create an osgViewer instance and add the camera to it this->osgViewer = new osgViewer::Viewer(); osgViewer->getCamera()->setClearColor(osg::Vec4(0.8,0.8,0.8,1)); osgViewer->addSlave(camera); // .. // Run the Open Scene Graph thread RunOSG(); // And set the Is Initialised flag this->osgInitialised = true; } / On Wed, Jul 29, 2009 at 1:50 PM, Martin Fleck wrote: > Hi, > > seems like the 5 posts above should be in a new topic ^^; > > Addition to my post: I got the osgNETDemo running, but still its > WindowsForms and not WPF, so I'd still be happy about any advise /help > someone could give me :) > > -- > Read this topic online here: > http://forum.openscenegraph.org/viewtopic.php?p=15594#15594 > > > > > > ___ > osg-users mailing list > osg-users@lists.openscenegraph.org > http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org > ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] OSG and WPF Questions
Hi Martin, You can capsulate the OSG-stuff in an ActiveX component also. Even though I don't like COM technology, it may be useful in some cases. Please be careful about singletons and module globals. Can 2009/7/29 Martin Fleck > Hello, > > I'm new to OSG and WPF (though I've read quite a view tutorials the past 2 > weeks) so I hope I don't ask too many stupid questions :) > > Task > I have to program something very similar to a CAD-program. The program > should be able to load files (stl-files) and you should be able to > manipulate the model in different ways, selecting triangles, points, > cutting, ... > For the visualisation of the models and functionality I chose OSG since it > seems to offer quite a lot and is pretty fast. (Also it has a reader for > stl-files ;) ) > The UI has to be made with WPF. So basically the "OSG-window" should be > controlled via menus, buttons, mouse and keyboard-input. > > What I found out > For the past view days I've researched this matter and found only a few > tutorials on msdn and codeproject. But if I got that right the way to do the > integration is: > - C++: create a class ("OpenGLHwnd") that inherits from HwndHost > - C++: create a window (or a dialog, but dialog didn't work for me) > - C++: attach the viewer with the window (code taken from this site "... > .NET-control ...") > - C++: compile the whole thing as managed dll (/clr) > - C#/WPF: use the dll and attach an instance of the class as child in a > placeholder > > In the OpenGLHwnd-class I have to override BuildWindowCore, > DestroyWindowCore, OnRenderSizeChanged and OnRender. > > Status > Well, I just set up the whole thing and tried to make the "OpenGL"-window > fit in the WPF-application. In this "OpenGL"-Window I just try to display > two pyramids using OSG. > > My Problem > If I use "normal" OpenGL-commands everything is displayed, but if I use the > viewer, somehow not only the WPF-window is opened, but also an additional > fullscreen window which shows the pyramids. I don't seem to get the window > out of the fullscreen mode and fit in the WPF-application. > > My Questions > Well, can anyone give me some advise to fix the problem? Or can someone > tell me if the way I want to integrate OSG in WPF is right, because it seems > pretty much like a bad "workaround" to me ^^; > Are there any tutorials on this matter? (I've looked at the osgDotNetDemo > from hesicong.net, but it doesn't work -> applicationcan't be initialized) > > I hope everything is understandable since english is not my mother tounge. > > Thank you in advance! > > Cheers, > Martin > > -- > Read this topic online here: > http://forum.openscenegraph.org/viewtopic.php?p=15581#15581 > > > > > > ___ > osg-users mailing list > osg-users@lists.openscenegraph.org > http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org > ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] OSG and WPF Questions
Hi, seems like the 5 posts above should be in a new topic ^^; Addition to my post: I got the osgNETDemo running, but still its WindowsForms and not WPF, so I'd still be happy about any advise /help someone could give me :) -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=15594#15594 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
[osg-users] OSG and WPF Questions
Hello, I'm new to OSG and WPF (though I've read quite a view tutorials the past 2 weeks) so I hope I don't ask too many stupid questions :) Task I have to program something very similar to a CAD-program. The program should be able to load files (stl-files) and you should be able to manipulate the model in different ways, selecting triangles, points, cutting, ... For the visualisation of the models and functionality I chose OSG since it seems to offer quite a lot and is pretty fast. (Also it has a reader for stl-files ;) ) The UI has to be made with WPF. So basically the "OSG-window" should be controlled via menus, buttons, mouse and keyboard-input. What I found out For the past view days I've researched this matter and found only a few tutorials on msdn and codeproject. But if I got that right the way to do the integration is: - C++: create a class ("OpenGLHwnd") that inherits from HwndHost - C++: create a window (or a dialog, but dialog didn't work for me) - C++: attach the viewer with the window (code taken from this site "... .NET-control ...") - C++: compile the whole thing as managed dll (/clr) - C#/WPF: use the dll and attach an instance of the class as child in a placeholder In the OpenGLHwnd-class I have to override BuildWindowCore, DestroyWindowCore, OnRenderSizeChanged and OnRender. Status Well, I just set up the whole thing and tried to make the "OpenGL"-window fit in the WPF-application. In this "OpenGL"-Window I just try to display two pyramids using OSG. My Problem If I use "normal" OpenGL-commands everything is displayed, but if I use the viewer, somehow not only the WPF-window is opened, but also an additional fullscreen window which shows the pyramids. I don't seem to get the window out of the fullscreen mode and fit in the WPF-application. My Questions Well, can anyone give me some advise to fix the problem? Or can someone tell me if the way I want to integrate OSG in WPF is right, because it seems pretty much like a bad "workaround" to me ^^; Are there any tutorials on this matter? (I've looked at the osgDotNetDemo from hesicong.net, but it doesn't work -> applicationcan't be initialized) I hope everything is understandable since english is not my mother tounge. Thank you in advance! Cheers, Martin -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=15581#15581 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org