|
本帖最后由 hup 于 2016-1-15 11:00 编辑
学长毕业了,留的程序该我改了,以前接触OSG不深,所以遇到问题了,代码如下:
- m_hWndParent = hWnd;
- first_load=true;
- Title_text = new osgText::Text;
- Title_AirPort_Name=new osgText::Text;
- Title_energy_type=new osgText::Text;
- //osg::DisplaySettings::instance()->setNumMultiSamples(8);
- m_osgRoot = new osg::Group(); //场景模型 根 的初始化
- m_osgViewer = new osgViewer::Viewer(); //视口 初始化
-
- osgViewer::Viewer& viewer1 = *m_osgViewer;
- osg::GraphicsContext::WindowingSystemInterface* wsi = osg::GraphicsContext::getWindowingSystemInterface();
- if (!wsi)
- {
- osg::notify(osg::NOTICE)
- <<"Error, no WindowSystemInterface available, cannot create windows."<<std::endl;
- return 1;
- }
- unsigned int width, height;
- wsi->getScreenResolution(osg::GraphicsContext::ScreenIdentifier(0), width, height);
- osg::ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits;
- osg::ref_ptr<osg::Referenced> windata = new osgViewer::GraphicsWindowWin32::WindowData(hWnd);
- RECT rt;
- GetWindowRect(hWnd,&rt);
- int wnd_w = rt.right-rt.left;
- int wnd_h = rt.bottom-rt.top;
- int maxlen= wnd_w<wnd_h ? wnd_w : wnd_h;
- traits->x = 0;
- traits->y = 0;
- traits->sharedContext = 0;
- traits->setInheritedWindowPixelFormat = true;
- traits->inheritedWindowData = windata;
- traits->red = traits->green = traits->blue = 8;
- traits->depth = 24;
- //traits->alpha = 8;
- //traits->stencil = 8;
- traits->doubleBuffer = true;
- traits->mipMapGeneration = true;
- traits->sampleBuffers = 0;
- traits->samples = msp;
-
- if (bShowMax)
- {
- traits->x = 0;
- traits->y = 0;
- traits->width = width;
- traits->height = height;
- traits->windowDecoration = false;
- }
- else
- {
- traits->width = width/2;
- traits->height = height/2;
- traits->windowDecoration = true;
- }
- m_gc = osg::GraphicsContext::createGraphicsContext(traits.get());//[color=Red]这块出的问题[/color]
- if (m_gc.valid())
- {
- osg::notify(osg::INFO)<<" GraphicsWindow has been created successfully."<<std::endl;
- m_gc->setClearColor(osg::Vec4f(0.2f,0.2f,0.6f,1.0f));
- m_gc->setClearMask(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- }
- else
- {
- osg::notify(osg::NOTICE)<<" GraphicsWindow has not been created successfully."<<std::endl;
- return false;
- }
复制代码
上面创建OSG窗口代码每次运行到createGraphicsContext(traits.get())会报错“Unhandled exception at 0x7681c42d in AirportEnergy.exe: Microsoft C++ exception: std::__non_rtti_object at memory location 0x0a04f69c..”,可能是空指针或野指针问题,我在调试过程中发现windowName(定义:std::string windowName)属性中出现了Bad Ptr问题,但不知如何解决,因此在此求助,谢谢了 |
-
windowName
-
其他属性
|