查看: 3889|回复: 5

求助:OSG在QT里面改变窗口大小后,出现窗口变黑的情况

[复制链接]

该用户从未签到

发表于 2011-4-1 11:49:12 | 显示全部楼层 |阅读模式
本帖最后由 fosky 于 2011-4-1 11:52 编辑
  1. osgViewer::View *grViewQtWindow::init( int x, int y, int w, int h, const std::string& name/*=""*/, bool windowDecoration/*=false*/ )
  2.         {
  3.                 osg::DisplaySettings* ds = osg::DisplaySettings::instance().get();
  4.                 osg::ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits;
  5.                 traits->windowName = name;
  6.                 traits->windowDecoration = windowDecoration;
  7.                 traits->x = x;
  8.                 traits->y = y;
  9.                 traits->width = w;
  10.                 traits->height = h;
  11.                 traits->doubleBuffer = true;
  12.                 traits->alpha = ds->getMinimumNumAlphaBits();
  13.                 traits->stencil = ds->getMinimumNumStencilBits();
  14.                 traits->sampleBuffers = ds->getMultiSamples();
  15.                 traits->samples = ds->getNumMultiSamples();
  16.                
  17.                 osgViewer::View* view = new osgViewer::View;
  18.                 osg::ref_ptr<osg::Camera> camera = view->getCamera();
  19.                 view->getCamera()->setGraphicsContext( new osgQt::GraphicsWindowQt(traits.get()) );
  20.                 view->getCamera()->setViewport( new osg::Viewport(x, y, w, h) );
  21.                 double fovy, z1, z2, aspectRatio;
  22.                 view->getCamera()->getProjectionMatrixAsPerspective(fovy,aspectRatio,z1,z2);
  23.                 view->getCamera()->setProjectionMatrixAsPerspective(fovy, static_cast<double>(w)/static_cast<double>(h), z1, z2);
  24.        

  25.                 //view->setCamera( camera );

  26.                 osgQt::GraphicsWindowQt* gw = dynamic_cast<osgQt::GraphicsWindowQt*>( camera->getGraphicsContext() );
  27.                 m_gridLayout->addWidget( gw->getGraphWidget() );

  28.                 return view;
  29.         }
复制代码
这是创建View的代码,可以正常显示一个背景,但是,在改变窗口大小后,就会出现
QGLContext::makeCurrent() : wglMakeCurrent failed: ???????????????С?
这个错误,此时还能正常显示.
这样改变大小几次后,窗口就会变黑,什么也看不到了.
然后出现一堆这样的文字:
Warning: detected OpenGL error 'invalid operation' after applying attribute Text
ure2D 02D047E8
Warning: detected OpenGL error 'invalid operation' at end of State::apply(StateS
et*)
Warning: detected OpenGL error 'invalid operation' at start of State::apply()
Warning: detected OpenGL error 'invalid operation' after applying GLMode 0xb44
Warning: detected OpenGL error 'invalid operation' after applying attribute Mate
rial 02C99D90
Warning: detected OpenGL error 'invalid operation' after applying GLMode 0xde1
Warning: detected OpenGL error 'invalid operation' after applying attribute Text
ure2D 02D04A98
Warning: detected OpenGL error 'invalid operation' at end of State::apply()
Warning: detected OpenGL error 'invalid operation' at after RenderBin::draw(..)
Warning: detected OpenGL error 'invalid operation' at start of State::apply()
Warning: detected OpenGL error 'invalid operation' after applying GLMode 0xb50
Warning: detected OpenGL error 'invalid operation' after applying GLMode 0xb71
Warning: detected OpenGL error 'invalid operation' after applying GLMode 0x4000
Warning: detected OpenGL error 'invalid operation' after applying attribute Mate
rial 02C64158
Warning: detected OpenGL error 'invalid operation' after applying attribute Ligh
tModel 02D0C6C0
Warning: detected OpenGL error 'invalid operation' after applying attribute Blen
dFunc 00DB0028
Warning: detected OpenGL error 'invalid operation' after applying attribute Colo
rMask 02CFD298
Warning: detected OpenGL error 'invalid operation' after applying attribute View
port 00DD60B0
Warning: detected OpenGL error 'invalid operation' after applying attribute TexE
nv 02D0C758
Warning: detected OpenGL error 'invalid operation' at end of State::apply()
Warning: detected OpenGL error 'invalid operation' at end of SceneView::draw()

希望知道这个错误的人,指点下迷津!!!

该用户从未签到

 楼主| 发表于 2011-4-1 12:02:08 | 显示全部楼层
此程序用的是一个独立的线程进行渲染操作

该用户从未签到

 楼主| 发表于 2011-4-1 12:04:13 | 显示全部楼层
换成了用定时器去渲染,竟然没问题了.看来QT的多线程渲染还是有问题!!

该用户从未签到

 楼主| 发表于 2011-4-1 12:08:48 | 显示全部楼层

竟然是自问自答

该用户从未签到

发表于 2011-4-1 12:55:17 | 显示全部楼层
Qt的OpenGL操作封装的不太合理,容易出问题,楼主如果有研究收获的话不妨分享一下~~

该用户从未签到

发表于 2011-4-10 19:31:21 | 显示全部楼层
学习。。。。。。。。。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

OSG中国官方论坛-有您OSG在中国才更好

网站简介:osgChina是国内首个三维相关技术开源社区,旨在为国内更多的技术开发人员提供最前沿的技术资讯,为更多的三维从业者提供一个学习、交流的技术平台。

联系我们

  • 工作时间:09:00--18:00
  • 反馈邮箱:1315785073@qq.com
快速回复 返回顶部 返回列表