Hi Björn,

>> 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?

The original intent (I wrote the code) was for the application code to
create the window *and* set its pixel format. However, looking back at the
number of people who have stumbled on this recently, it would perhaps be
better to have a new flag in the osg::GraphicsContext::Traits structure that
would specify if the pixel format has to be set by the GraphicsWindowWin32
class (traits->setInheritedWindowPixelFormat=true) or left as is
(traits->setInheritedWindowPixelFormat=false; the default selected not to
break existing apps).

The change you did is valid, but may go against the preference of other
applications (those providing a fully prepared window with the pixel format
already set).

I'll take a look at adding this feature later this week.

Thanks for the feedback,

André

-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Björn Hein
Sent: May-09-07 4:04 PM
To: [email protected]
Subject: [osg-users] MFC + GraphicsWindowWin32 - Question or possible bug
and if it is a bug having a solution :-)

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/

_______________________________________________
osg-users mailing list
[email protected]
http://openscenegraph.net/mailman/listinfo/osg-users
http://www.openscenegraph.org/

Reply via email to