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<osg::Referenced> windata = new
osgViewer::GraphicsWindowWin32::WindowData(mHwnd);
        osg::ref_ptr<osg::GraphicsContext::Traits> 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<osg::GraphicsContext> 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 <[email protected]>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
> [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