c++ - How to embed OpenGL rendering context in MFC Application -
i want embed opengl applicaiton, namely openscenegraph library, in mfc mdi application. i've created mfc application tabbed mdi document derives mainform , childform cview class, swapping windows handles of control , opengl rendering context(with initialization) enough have scene displayed in control. want opengl scene inside of child form.
the problem above scenario is, firstly don't know whether correct derive mdi cview class or different classes more suitable purpose. secondly code below m_hwnd returns 0 contexts can not initialized.
cchildframe::cchildframe() { // todo: add member initialization code here osgviewer::viewer viewer; //osg::ref_ptr<osg::graphicscontext::traits> traits = new osg::graphicscontext::traits; rect rect; hwnd hw; hw = m_hwnd; ::getwindowrect(m_hwnd, &rect); osg::ref_ptr<osg::graphicscontext::traits> traits = new osg::graphicscontext::traits; // init windata variable holds handle window display osg in. osg::ref_ptr<osg::referenced> windata = new osgviewer::graphicswindowwin32::windowdata(m_hwnd); // setup 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 graphics context osg::graphicscontext* gc = osg::graphicscontext::creategraphicscontext(traits.get()); // init new camera (master view) osg::ref_ptr<osg::camera> camera = new osg::camera; // assign graphics context camera camera->setgraphicscontext(gc); // set viewport camera camera->setviewport(new osg::viewport(traits->x, traits->y, traits->width, traits->height)); // set projection matrix , camera attribtues camera->setclearmask(gl_depth_buffer_bit | gl_color_buffer_bit); camera->setclearcolor(osg::vec4f(0.2f, 0.2f, 0.4f, 1.0f)); camera->setprojectionmatrixasperspective( 30.0f, static_cast<double>(traits->width) / static_cast<double>(traits->height), 1.0, 1000.0); // add camera viewer //mviewer->addslave(camera.get()); viewer.setcamera(camera.get()); // add camera manipulator viewer viewer.setcameramanipulator(new osgga::orbitmanipulator()); osg::ref_ptr<osg::group> root = new osg::group; osg::ref_ptr<osg::geode> geode = new osg::geode; geode->adddrawable(new osg::shapedrawable(new osg::box(osg::vec3(0.0f, 0.0f, -0.5f), 100.0f, 100.0f, 1.0f))); root->addchild(geode.get()); viewer.setscenedata(root.get()); viewer.realize(); }
Comments
Post a Comment