|
e:\main.bmp请问各位高手,我建立一个对话框应用程序,在对话框上放置一个静态文本控件,我想在这个静态文本里显示一个osg图像“cow.osg”
静态文本的ID号为IDC_STATICDISPLAY;在对话框初始化的时候加载initosg();我用下面的代码它的
图像不显示在指定的静态文本里,而是单独的开了一个窗口显示这只可爱的蒙牛!为什么?
我是仿照《OSG 窗口与网页浏览器的嵌合》 本文作者:array 校对整理:FlySky写的,不知道那儿仿错了
请高手帮我分析分析并,在下感激不尽!编译环境VS2005 sp1 Chs ,osg2.4
static void RenderThread(void* ptr);
void CCNC3DMonitorDlg::initosg(void)
{
CRect rc;
GetDlgItem(IDC_STATICDISPLAY)->GetClientRect(&rc);
CWnd *wnd=GetDlgItem(IDC_STATICDISPLAY);
m_Viewer=new osgViewer::Viewer;
osg::ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits;
osg::ref_ptr<osg::Referenced> windata = new osgViewer::GraphicsWindowWin32::WindowData(wnd->m_hWnd);
traits->x = 0;
traits->y = 0;
traits->width = rc.right - rc.left;
traits->height = rc.bottom - rc.top ;
traits->windowDecoration = false;
traits->doubleBuffer = true;
traits->sharedContext = 0;
traits->inheritedWindowData = windata;
osg::ref_ptr<osg::GraphicsContext> gc=osg::GraphicsContext::createGraphicsContext(traits.get());
osg::ref_ptr<osg::Camera> camera=new osg::Camera;
camera->setGraphicsContext(gc.get());
camera->setViewport(new osg::Viewport(traits->x,traits->y,traits->width,traits->height));
camera->setProjectionMatrixAsPerspective( 30.0f,
(double)traits->width/(double)traits->height, 1.0f, 10000.0f );
//camera->setDrawBuffer(GL_BACK);
//camera->setReadBuffer(GL_BACK);
m_Viewer->setThreadingModel(osgViewer::Viewer::SingleThreaded);
m_Viewer->setCameraManipulator(new osgGA::TrackballManipulator);
m_Root = new osg::Group;
//m_Viewer->getCamera()->setClearColor(osg::Vec4(0.8,0.8,0.8,1));
//m_Viewer->addSlave(camera.get());
m_Viewer->setSceneData(osgDB::readNodeFile("cow.osg"));
m_Viewer->realize();
_beginthread(&RenderThread,0,m_Viewer);
}
void RenderThread(void* ptr)
{
osgViewer::Viewer* viewer = (osgViewer::Viewer*)ptr;
while( !viewer->done() )
{
viewer->frame();
}
_endthread();
}
void CCNC3DMonitorDlg::OnDestroy()
{
m_Viewer->setDone(true);
Sleep(200);
m_Viewer->stopThreading();
delete m_Viewer;
CDialog::OnDestroy();
} |
|