hi everyone,

I'm new to this mailing list, although I have been using OpenSceneGraph 
for a couple of monthes.

I'm using the OsgViewer from OSG 2.0 and I would like to have it use a 
.NET form for display (using managed C++, not C#). I followed  the 
advice given by Glenn Waldron in his reply to Romain Blanchais on the 
20th of November, where he gave the following sample code :

HWND hwnd = (HWND)control->Handle.ToPointer();

osg::ref_ptr<osg::GraphicsContext::Traits> traits =
        new osg::GraphicsContext::Traits();

traits->inheritedWindowData = new
osgViewer::GraphicsWindowWin32::WindowData( hwnd );
traits->setInheritedWindowPixelFormat = true;
traits->doubleBuffer = true;
traits->windowDecoration = false;
traits->sharedContext = 0;
traits->supportsResize = true;

RECT rect;
GetWindowRect( hwnd, &rect );
traits->x = 0;
traits->y = 0;
traits->width = rect.right - rect.left;
traits->height = rect.bottom - rect.top;

osg::ref_ptr<osg::GraphicsContext> gc =
osg::GraphicsContext::createGraphicsContext(
        traits.get() );

viewer = new osgViewer::Viewer();

osg::ref_ptr<osg::Camera> cam = new osg::Camera();
cam->setGraphicsContext( gc.get() );
cam->setViewport( new osg::Viewport( traits->x, traits->y,
traits->width, traits->height ) );
viewer->addSlave( cam.get() );

I have succeeded in obtaining a rendering of the OsgViewer in my form,
but I have the following issues :

1) it seems that the aspect ratio used for the rendering is based on the 
ratio of the form size.
This is troublesome as I would expect to be able to set the aspect ratio 
according to the screen, and not according to the form size. the problem 
is even more obvious when my form is created with a width >> height or 
height >> width.
In those case, the rendering is squeezed. I tried to override the 
projection matrix of the camera used. I also tried to call windowResize 
on the EventQueue of the Viewer to ensure that it is kept informed of 
the size, but it didn't resolve the aspect ratio problem.

I tried to figure out from the source code of the OsgViewer how it was 
dealing with the FOV settings of the camera, but it seemed a bit 
confusing because I couldn't see the point where the camera actually 
receive a proper projection matrix (I used AddSlave, like in the given 
sample, to add the camera to the viewer, and this mean identity matrices 
are passed as projection matrix and as view matrix, so it must be 
overriden at some point, but I don't know where).

What is the proper way of using OsgViewer in an external window and have
it set the camera parameters properly, or providing it proper camera
parameters ?


2) when closing the form, the OsgViewer is informed of the closing of 
the windows, but can't do the things to shut down properly. I get the 
following errors :

Windows Error #6: [Screen #0]
GraphicsWindowWin32::releaseContextImplementation() - Unable to release 
current OpenGL rendering context. Reason: The handle is invalid.

Windows Error #1400: [Screen #0]
GraphicsWindowWin32::unregisterWindowProcedure() - Unable to unregister 
window procedure. Reason: Invalid window handle.

what is the proper way of disposing of the OsgViewer and the form, so 
that it can close without errors ?


Thanks for any assistance

C.L


_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to