|
楼主 |
发表于 2011-2-25 17:22:14
|
显示全部楼层
本帖最后由 sakiel 于 2011-2-25 17:24 编辑
我把我的代码重新贴一下吧,请各位大侠给指点一下。
按照array说的去实现了一下:- // screen size
- unsigned int w = 960;
- unsigned int h = 640;
-
- // camera
- osg::ref_ptr<osg::Camera> hudCamera = new osg::Camera;
- hudCamera->setProjectionMatrix(osg::Matrix::ortho2D(0,w,0,h));
- hudCamera->setReferenceFrame(osg::Transform::ABSOLUTE_RF);
- hudCamera->setViewMatrix(osg::Matrix::identity());
- hudCamera->setClearMask(GL_DEPTH_BUFFER_BIT);
- hudCamera->setRenderOrder(osg::Camera::POST_RENDER);
-
- // texture <<============================
- osg::Geometry * rectBG = new osg::Geometry;
- osg::Vec3Array* vertices = new osg::Vec3Array(4);
- (*vertices)[0].set(0.f, 0.f, (float)h);
- (*vertices)[1].set(0.f, 0.f, 0.f);
- (*vertices)[2].set((float)w, 0.f, 0.f);
- (*vertices)[3].set((float)w, 0.f, (float)h);
- rectBG->setVertexArray(vertices);
-
- osg::Vec2Array* texcoords = new osg::Vec2Array(4);
- (*texcoords)[0].set(0.0f, 1.0f);
- (*texcoords)[1].set(0.0f, 0.0f);
- (*texcoords)[2].set(1.0f, 0.0f);
- (*texcoords)[3].set(1.0f, 1.0f);
- rectBG->setTexCoordArray(0,texcoords);
-
- osg::Vec3Array* normals = new osg::Vec3Array(1);
- (*normals)[0].set(0.0f,1.0f,0.0f);
- rectBG->setNormalArray(normals);
- rectBG->setNormalBinding(osg::Geometry::BIND_OVERALL);
- rectBG->addPrimitiveSet(new osg::DrawArrays(GL_QUADS,0,4));
- osg::Geode* BG_geode = new osg::Geode;
- BG_geode->addDrawable(rectBG);
-
- // set up the texture state.
- osg::ref_ptr<osg::Texture2D> BG_texture = new osg::Texture2D;
- BG_texture->setDataVariance(osg::Object::DYNAMIC); // protect from being optimized away as static state.
- BG_texture->setImage(osgDB::readImageFile("curVideoFrame.png"));
- osg::StateSet* stateset = rectBG->getOrCreateStateSet();
- stateset->setTextureAttributeAndModes(0,BG_texture,osg::StateAttribute::ON);
-
- // ====================================>>
- // root
- osg::ref_ptr<osg::Group> MARRoot = new osg::Group;
-
- // turn off lighting
- MARRoot->getOrCreateStateSet()->setMode(GL_LIGHTING,osg::StateAttribute::OFF);
-
- hudCamera->addChild(BG_geode);
- MARRoot->addChild(hudCamera);
-
- // viewer
- osg::ref_ptr<osgViewer::Viewer> MARViewer = new osgViewer::Viewer();
- MARViewer->setSceneData(MARRoot.get());
- MARViewer->setCameraManipulator(new osgGA::MultiTouchTrackballManipulator);
- MARViewer->realize();
复制代码 很郁闷,这么一写,Viewer里面竟然什么都没有了。
请看看这么做有问题么?材质部分的代码能保证图像填充整个viewer么? |
|