Hi,
This is an MFC program of single document.
The composite viewer sits in the MFC::app, and the program instantiates a 
separate osgViewer::View for each MFC::View. Each osgViewer::View have its own 
GraphicsContext and the contextID is increased 


Code:
  void CompositeFk::AddView(const HWND& hwnd, const RECT& rect, 
osgViewer::View* view)
  {
    // Init the GraphicsContext Traits
    osg::ref_ptr<osg::GraphicsContext::Traits> traits 
      = new osg::GraphicsContext::Traits;

    // Init the Windata Variable that holds the handle 
    // for the Window to display OSG in.
    osg::Referenced* windata 
      = new osgViewer::GraphicsWindowWin32::WindowData(hwnd);

    // Setup the traits parameters
    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->setInheritedWindowPixelFormat = true;
    traits->inheritedWindowData = windata;

    // Create the Graphics Context
    osg::ref_ptr<osg::GraphicsContext> gc 
      = osg::GraphicsContext::createGraphicsContext(traits);

    // Init a new Camera (Master for this View)
    osg::Camera* camera = new osg::Camera;

    // Assign Graphics Context to the Camera
    camera->setGraphicsContext(gc);
        gc->getState()->setContextID(++m_nContextID);
    //set clear color as deep blue 
    camera->setClearColor(osg::Vec4f(0,0,0/*0.2f, 0.2f, 0.4f*/, 1.0f));

    // Set the viewport for the Camera
    camera->setViewport(new osg::Viewport(traits->x, 
      traits->y, traits->width, traits->height));
    camera->setProjectionMatrixAsPerspective( 30.0f, 
      (double)traits->width/(double)traits->height, 1.0f, 10000.0f );

    // Add the Camera to the mainView
    view->setCamera(camera);
        mv->addView(view);
  }



HWND comes from the MFC::View::GetSafeHwnd()
All of the osgViewer::View points to the same osg::Group node. 
The texture is correctly copied over all the osgViewer::View.

However the program will crash after opening multiple views, and close any one 
of them. (Open single view and close it is OK)

Code:
void C***_View::OnDestroy()
{
        // it informs the composite viewer to do removeView(view)
        theApp.DeleteView(m_view.get()); 
        CView::OnDestroy();
}



The program will crush on exit of OnDestroy() (not immediately after removeView)

System Configuration:
1. Single NVidia graphics card (8 years old)
2. Windows XP
3. VS 2008 SP1
4. OSG 3.0.1

... 

Thank you!

Cheers,
Suyang

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=46525#46525





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

Reply via email to