|
本帖最后由 木子匕 于 2012-12-14 17:48 编辑
保存前
保存后打开
线的位置没有什么问题!text往右偏移了很多求解!- //线
- osg::Geode* geode = new osg::Geode;
- osg::Geometry* geom = new osg::Geometry;
- osg::StateSet* stateset = new osg::StateSet;
- osg::LineWidth* linewidth = new osg::LineWidth();
- //线的宽度
- linewidth->setWidth(2.0f);
- stateset->setAttributeAndModes(linewidth,osg::StateAttribute::ON);
- stateset->setMode(GL_LIGHTING,osg::StateAttribute::OFF);
- //让这些点总是画在最上面
- stateset->setMode(GL_DEPTH_TEST,osg::StateAttribute::OFF);
- stateset->setMode(GL_LIGHTING, osg::StateAttribute::OFF|osg::StateAttribute::PROTECTED );
- //设置渲染优先级
- stateset->setRenderBinDetails(101, "RenderBin");
- geom->setStateSet(stateset);
- osg::Vec3dArray* vertexs = new osg::Vec3dArray;
- geom->setVertexArray(vertexs);
- osg::Vec4dArray* colors = new osg::Vec4dArray;
- osg::Vec4d color(1,1,1,1);
- geom->setColorArray(colors);
- geom->setColorBinding(osg::Geometry::BIND_PER_VERTEX);
- {
- vertexs->push_back(star);
- vertexs->push_back(end);
- colors->push_back(color);
-
- }
- geom->addPrimitiveSet(new osg::DrawArrays(osg::DrawArrays::LINES,0,2));
- geode->addDrawable(geom);
- //////////////////////////////////////////////////////////////////////////
- //文字
- osgText::Text *text = new osgText::Text;
- osgText::Font *font = osgText::readFontFile("fonts\\simhei.ttf");
- //设置字体文件
- text->setFont(font);
- //设置文字信息
- text->setText(wtext.c_str());
- //设置字体大小
- text->setCharacterSize(1.0f);
- text->setAutoRotateToScreen(true);
- //设置字体颜色
- text->setColor(osg::Vec4(1,1,1,1));
- //设置显示位置
- text->setPosition(end);
- //设置对齐方式
- text->setAlignment(osgText::Text::CENTER_TOP);
- //设置旋转方式
- text->setAxisAlignment(osgText::Text::SCREEN);
- geode->setStateSet(stateset);
- geode->addDrawable(text);
复制代码 |
|