查看: 1045|回复: 4

Examples osgviewerMFC 窗口显示无法满屏

[复制链接]

该用户从未签到

发表于 2015-12-9 21:52:03 | 显示全部楼层 |阅读模式
Examples osgviewerMFC 例子中的渲染窗口无法满屏,谁帮忙解决一下?

无法满屏

无法满屏

该用户从未签到

发表于 2015-12-15 10:23:49 | 显示全部楼层
这个我调试过了,osg::GraphicsContext::createGraphicsContext(traits.get());函数内部把traits的值给改变了,把camera->setViewport(new osg::Viewport(traits->x, traits->y, traits->width, traits->height));中的viewoort的前两个参数改为0就可以了

该用户从未签到

 楼主| 发表于 2015-12-12 12:00:21 | 显示全部楼层
是不是这个函数有问题呢?

void cOSG::InitCameraConfig(void)
{
    // Local Variable to hold window size data
    RECT rect;

    // Create the viewer for this window
    mViewer = new osgViewer::Viewer();

    // Add a Stats Handler to the viewer
    mViewer->addEventHandler(new osgViewer::StatsHandler);

    // Get the current window size
    ::GetWindowRect(m_hWnd, &rect);

    // 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::ref_ptr<osg::Referenced> windata = new osgViewer::GraphicsWindowWin32::WindowData(m_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::GraphicsContext* gc = osg::GraphicsContext::createGraphicsContext(traits.get());

    // Init Master Camera for this View
    osg::ref_ptr<osg::Camera> camera = mViewer->getCamera();

    // Assign Graphics Context to the Camera
    camera->setGraphicsContext(gc);

    // Set the viewport for the Camera
    camera->setViewport(new osg::Viewport(traits->x, traits->y, traits->width, traits->height));

    // Set projection matrix and 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 the Camera to the Viewer
    //mViewer->addSlave(camera.get());
    mViewer->setCamera(camera.get());

    // Add the Camera Manipulator to the Viewer
    mViewer->setCameraManipulator(keyswitchManipulator.get());

    // Set the Scene Data
    mViewer->setSceneData(mRoot.get());

    // Realize the Viewer
    mViewer->realize();

}

该用户从未签到

 楼主| 发表于 2015-12-15 20:49:56 | 显示全部楼层
garyliyong 发表于 2015-12-15 10:23
这个我调试过了,osg::GraphicsContext::createGraphicsContext(traits.get());函数内部把traits的值给改变 ...

问题已经解决,灰常感谢!

该用户从未签到

发表于 2017-5-17 12:11:45 | 显示全部楼层
garyliyong 发表于 2015-12-15 10:23
这个我调试过了,osg::GraphicsContext::createGraphicsContext(traits.get());函数内部把traits的值给改变 ...

问题解决啦。多谢多谢!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

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

联系我们

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