Hello,
I wanted to connected osgViewer::Viewer to a preexisting MFC-window:
What i did:
.... Code beeing in a CWnd .... Snip...
// creating viewer
m_viewer = new osgViewer::Viewer( );
// creating windowData
osg::ref_ptr<osgViewer::GraphicsWindowWin32::WindowData> wData = new
osgViewer::GraphicsWindowWin32::WindowData(GetSafeHwnd());
// creating Traits
osg::ref_ptr<osg::GraphicsContext::Traits> traits = new
osg::GraphicsContext::Traits;
traits->x = 0;
traits->y = 0;
traits->width = lpCreateStruct->cx;
traits->height = lpCreateStruct->cy;
traits->windowDecoration = false;
traits->doubleBuffer = true;
traits->sharedContext = 0;
traits->supportsResize = true;
// setting window data ....
traits->inheritedWindowData = wData.get();
// creating context
osg::ref_ptr<osg::GraphicsContext> gc =
osg::GraphicsContext::createGraphicsContext(traits.get());
.... Snip....
While debugging i got for gc a null pointer --> there was no output in the
MFC-window but the scene was drawn on the whole screen. It's the same result
as if I don't set traits->inheritedWindowData.
After debugging i found a possible bug in GraphicsWindowWin32::setWindow(
HWND handle )
--> _hglrc = ::wglCreateContext(_hdc);
This returns 0 Pointer because Pixelformat is not correctly set.
Possible Solution:
Remove following lines in GraphicsWindowWin32::setWindow( HWND handle ):
....
_hglrc = ::wglCreateContext(_hdc);
if (_hglrc==0)
{
reportErrorForScreen("GraphicsWindowWin32::setWindow() - Unable to
create OpenGL rendering context", _traits->screenNum, ::GetLastError());
::ReleaseDC(_hwnd, _hdc);
_hdc = 0;
_hwnd = 0;
return false;
}
....
And replace with:
....
if (!setPixelFormat())
{
::ReleaseDC(_hwnd, _hdc);
_hdc = 0;
return false;
}
.....
With this I could easily connect a MFC window to the osgViewer::Viewer.
Question: Is this the correct way, or was this not intended to be the way
and the user should set the PixelFormat externaly?
Best Regards
Björn
_______________________________________________
osg-users mailing list
[email protected]
http://openscenegraph.net/mailman/listinfo/osg-users
http://www.openscenegraph.org/