|
各位大侠好,我刚接触osg
想请教1个问题,用OSG实现了1个OCX控件,在MFC程序里调用,现在想实现抓图功能,用户通过在MFC的界面上点Button,定义1个jpg文件名,然后抓图保存在这个文件里。
我在网上搜到的例子都是在控制台程序,通过回调函数捕捉键盘输入实现的,现在没有思路,请问这方面有了解的吗?
我的代码如下:保存的图形是黑的
osg::Camera* camera = new osg::Camera;
// set up the background color and clear mask.
camera->setClearColor(osg::Vec4(0.1f,0.1f,0.3f,1.0f));
camera->setClearMask(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// set up projection.
camera->setProjectionMatrix(viewer.getCamera()->getProjectionMatrix());
// set view
camera->setReferenceFrame(osg::Transform::ABSOLUTE_RF);
camera->setViewMatrix(viewer.getCamera()->getViewMatrix());
// set viewport
int w = 1280; // viewer.getCamera()->getViewport()->width();
int h = 1024; // viewer.getCamera()->getViewport()->height();
camera->setViewport(0,0,w,h);
// set the camera to render before the main camera.
camera->setRenderOrder(osg::Camera:RE_RENDER);
osg::Image* imageSave = new osg::Image;
imageSave->readPixels(0,0,w,h,GL_RGB,GL_UNSIGNED_BYTE);
camera->attach(osg::Camera::COLOR_BUFFER, imageSave);
camera->addChild(viewer.getSceneData());
osgDB::writeImageFile(*imageSave,"c:\\test.jpg"); |
|