Hi Christoffer, Here is a simple control that uses TAO to display an OSG window that I've used for testing.
Thanks! Jason On 9/18/07, Christoffer Markusson <[EMAIL PROTECTED]> wrote: > > I'm using OSG together with C# in Visual Studio 2005 using the osgDotNet > wrappers. > > Is there an easy way to integrate and display an OSG window in a Windows > Form? Does anyone have example code? > > Christoffer > > _______________________________________________ > osg-users mailing list > osg-users@lists.openscenegraph.org > http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org > >
using System; using System.Collections.Generic; using System.ComponentModel; using System.Drawing; using System.Data; using System.Text; using System.Windows.Forms; using Tao.Platform.Windows; using OsgViewer; using OsgGA; namespace OSGTesting { public partial class OSGControl : SimpleOpenGlControl { public OSGControl() { InitializeComponent(); InitializeContexts(); _gw = _viewer.setUpViewerAsEmbeddedInWindow(0, 0, Width, Height); _viewer.setCameraManipulator(new TrackballManipulator()); _viewer.realize(); } public Viewer Viewer { get {return _viewer;} } protected override void OnMouseMove(MouseEventArgs e) { if (!DesignMode) { _gw.getEventQueue().mouseMotion(e.X, e.Y); } base.OnMouseMove(e); } protected override void OnKeyPress(KeyPressEventArgs e) { if (!DesignMode) { _gw.getEventQueue().keyPress((int)e.KeyChar); } base.OnKeyPress(e); } protected override void OnMouseDown(MouseEventArgs e) { _gw.getEventQueue().mouseButtonPress(e.X, e.Y, ConvertMouse(e.Button)); base.OnMouseDown(e); } protected override void OnMouseUp(MouseEventArgs e) { _gw.getEventQueue().mouseButtonRelease(e.X, e.Y, ConvertMouse(e.Button)); base.OnMouseUp(e); } protected override void OnResize(EventArgs e) { if (!DesignMode && _gw != null) { _gw.getEventQueue().windowResize(0, 0, ClientSize.Width, ClientSize.Height); _gw.resized(0, 0, Width, Height); } base.OnResize(e); } private void OSGControl_Paint(object sender, PaintEventArgs e) { if (!DesignMode) { _viewer.frame(_timer.time_s()); } } private static uint ConvertMouse(MouseButtons button) { uint result = 0; switch (button) { case MouseButtons.Left: result = 1; break; case MouseButtons.Middle: result = 2; break; case MouseButtons.Right: result = 3; break; } return result; } private Osg.Timer _timer = new Osg.Timer(); private GraphicsWindow _gw; private Viewer _viewer = new Viewer(); } }
_______________________________________________ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org