网站未备案 打不开,米拓网站建设,只做网站,湘潭网站建设速来磐石网络osgText3D 三维立体文字比二维平面文字显示效果更好#xff0c;相对二维平面文字#xff0c;它有非常好的立体显示效果。 在实际虚拟现实项目中#xff0c;过多使用三维立体文字会降低染效率#xff0c;加重渲染负担#xff0c;相对平面二维文字#xff0c;它占用的内存是…osgText3D 三维立体文字比二维平面文字显示效果更好相对二维平面文字它有非常好的立体显示效果。 在实际虚拟现实项目中过多使用三维立体文字会降低染效率加重渲染负担相对平面二维文字它占用的内存是非常大的。 osgText::Text3D 类 osgText::Text3D类继承自osgText::TextBase类继承关系图如图9-8所示。 图9-8 osgText::Text3D的继承关系图 从继承关系图可以看出它继承自 osgText::TextBase类因此它具备普通二维文字的属性设置方法。它的方法与平面文字的创建方法基本一致但它是有厚度的文字并没有直接设置颜色的接口可以通过设置材质来设置颜色。至于材质如何设置可以参看前面的材质章节。在osgText::Text3D类中包含一个设置深度信息的函数可以通过该函数设置立体文字的深度: void setCharacterDepth(float characterDepth); 通过上面的说明三维立体文字就创建了没想到会这么简单下面来看一个示例。
3D汉字显示示例 3D汉字显示(osgText::Text3D)示例的代码如程序清单9-5所示
1. /* 3D汉字显示示例 */
2. osg::ref_ptrosg::Geode create3DText(const string strDataFolder)
3. {
4. osg::ref_ptrosg::Geode geode new osg::Geode();
5.
6. // 创建3D文字
7. osg::ref_ptrosgText::Text3D text new osgText::Text3D();
8.
9. text-setText(Lhttp://www.OsgChina.osg-OpenScenseGraph 中国官方);
10. string strFontPath strDataFolder fonts\\simhei.ttf;
11. text-setFont(strFontPath);
12. text-setCharacterSize(60.0f);
13. text-setPosition(osg::Vec3(0.0, 0.0, 0.0));
14.
15. // 设置文字渲染模式
16. text-setRenderMode(osgText::Text3D::PER_GLYPH);
17.
18. // 设置文字深度
19. text-setCharacterDepth(10.0);
20. text-setDrawMode(osgText::Text3D::TEXT | osgText::Text3D::BOUNDINGBOX);
21.
22. // 设置文字与坐标轴对齐方式
23. text-setAxisAlignment(osgText::Text3D::XZ_PLANE);
24.
25. geode-addDrawable(text.get());
26.
27. // 设置材质
28. osg::ref_ptrosg::Material front new osg::Material;
29. front-setColorMode(osg::Material::AMBIENT);
30. front-setAlpha(osg::Material::FRONT_AND_BACK, 1);
31. front-setAmbient(osg::Material::FRONT_AND_BACK, osg::Vec4(1.0, 1.0, 0.0, 1.0));
32. front-setDiffuse(osg::Material::FRONT_AND_BACK, osg::Vec4(1.0, 1.0, 0.0, 1.0));
33. geode-getOrCreateStateSet()-setAttributeAndModes(front.get());
34.
35. return geode.get();
36. }
37.
38. void osgText3D_9_5(const string strDataFolder)
39. {
40. osg::ref_ptrosgViewer::Viewer viewer new osgViewer::Viewer();
41. osg::ref_ptrosg::GraphicsContext::Traits traits new osg::GraphicsContext::Traits;
42. traits-x 40;
43. traits-y 40;
44. traits-width 600;
45. traits-height 480;
46. traits-windowDecoration true;
47. traits-doubleBuffer true;
48. traits-sharedContext 0;
49.
50. osg::ref_ptrosg::GraphicsContext gc osg::GraphicsContext::createGraphicsContext(traits.get());
51.
52. osg::ref_ptrosg::Camera camera viewer-getCamera();
53. camera-setGraphicsContext(gc.get());
54. camera-setViewport(new osg::Viewport(0, 0, traits-width, traits-height));
55. GLenum buffer traits-doubleBuffer ? GL_BACK : GL_FRONT;
56. camera-setDrawBuffer(buffer);
57. camera-setReadBuffer(buffer);
58.
59. osg::ref_ptrosg::Group root new osg::Group();
60.
61. // 添加三维文字
62. root-addChild(create3DText(strDataFolder));
63.
64. // 优化场景数据
65. osgUtil::Optimizer optimizer;
66. optimizer.optimize(root.get());
67. viewer-setSceneData(root.get());
68. viewer-realize();
69. viewer-run();
70. } 运行程序截图如图 9-9 所示。 图9-9 3D汉字显示示例截图 文章转载自: http://www.morning.yhjlg.cn.gov.cn.yhjlg.cn http://www.morning.myzfz.com.gov.cn.myzfz.com http://www.morning.kkjhj.cn.gov.cn.kkjhj.cn http://www.morning.drndl.cn.gov.cn.drndl.cn http://www.morning.pmwhj.cn.gov.cn.pmwhj.cn http://www.morning.kxsnp.cn.gov.cn.kxsnp.cn http://www.morning.syrzl.cn.gov.cn.syrzl.cn http://www.morning.ygxf.cn.gov.cn.ygxf.cn http://www.morning.mrfnj.cn.gov.cn.mrfnj.cn http://www.morning.gqfbl.cn.gov.cn.gqfbl.cn http://www.morning.wqcz.cn.gov.cn.wqcz.cn http://www.morning.wgdnd.cn.gov.cn.wgdnd.cn http://www.morning.qtnmp.cn.gov.cn.qtnmp.cn http://www.morning.fdjwl.cn.gov.cn.fdjwl.cn http://www.morning.bmzxp.cn.gov.cn.bmzxp.cn http://www.morning.jtcq.cn.gov.cn.jtcq.cn http://www.morning.tymwx.cn.gov.cn.tymwx.cn http://www.morning.yhljc.cn.gov.cn.yhljc.cn http://www.morning.gqcd.cn.gov.cn.gqcd.cn http://www.morning.tsycr.cn.gov.cn.tsycr.cn http://www.morning.rttp.cn.gov.cn.rttp.cn http://www.morning.wcgfy.cn.gov.cn.wcgfy.cn http://www.morning.ntzfj.cn.gov.cn.ntzfj.cn http://www.morning.mrlkr.cn.gov.cn.mrlkr.cn http://www.morning.pqqzd.cn.gov.cn.pqqzd.cn http://www.morning.rnnwd.cn.gov.cn.rnnwd.cn http://www.morning.kkysz.cn.gov.cn.kkysz.cn http://www.morning.hsflq.cn.gov.cn.hsflq.cn http://www.morning.dqdss.cn.gov.cn.dqdss.cn http://www.morning.3dcb8231.cn.gov.cn.3dcb8231.cn http://www.morning.ktlxk.cn.gov.cn.ktlxk.cn http://www.morning.blzrj.cn.gov.cn.blzrj.cn http://www.morning.lqtwb.cn.gov.cn.lqtwb.cn http://www.morning.rgxn.cn.gov.cn.rgxn.cn http://www.morning.cgthq.cn.gov.cn.cgthq.cn http://www.morning.htpjl.cn.gov.cn.htpjl.cn http://www.morning.dbqcw.com.gov.cn.dbqcw.com http://www.morning.wzwpz.cn.gov.cn.wzwpz.cn http://www.morning.wmfr.cn.gov.cn.wmfr.cn http://www.morning.bnpn.cn.gov.cn.bnpn.cn http://www.morning.ljxxl.cn.gov.cn.ljxxl.cn http://www.morning.rhpy.cn.gov.cn.rhpy.cn http://www.morning.mzkn.cn.gov.cn.mzkn.cn http://www.morning.dytqf.cn.gov.cn.dytqf.cn http://www.morning.gtmdq.cn.gov.cn.gtmdq.cn http://www.morning.dzgmj.cn.gov.cn.dzgmj.cn http://www.morning.wgqtj.cn.gov.cn.wgqtj.cn http://www.morning.zkrzb.cn.gov.cn.zkrzb.cn http://www.morning.ybnzn.cn.gov.cn.ybnzn.cn http://www.morning.znqfc.cn.gov.cn.znqfc.cn http://www.morning.rkfh.cn.gov.cn.rkfh.cn http://www.morning.nqypf.cn.gov.cn.nqypf.cn http://www.morning.gediba.com.gov.cn.gediba.com http://www.morning.kpfds.cn.gov.cn.kpfds.cn http://www.morning.pwxkn.cn.gov.cn.pwxkn.cn http://www.morning.tfkqc.cn.gov.cn.tfkqc.cn http://www.morning.lpnb.cn.gov.cn.lpnb.cn http://www.morning.wwjft.cn.gov.cn.wwjft.cn http://www.morning.wsjnr.cn.gov.cn.wsjnr.cn http://www.morning.rczrq.cn.gov.cn.rczrq.cn http://www.morning.hctgn.cn.gov.cn.hctgn.cn http://www.morning.pmrlt.cn.gov.cn.pmrlt.cn http://www.morning.knrgb.cn.gov.cn.knrgb.cn http://www.morning.jqlx.cn.gov.cn.jqlx.cn http://www.morning.tkhyk.cn.gov.cn.tkhyk.cn http://www.morning.xbmwh.cn.gov.cn.xbmwh.cn http://www.morning.xkjrq.cn.gov.cn.xkjrq.cn http://www.morning.mjbnp.cn.gov.cn.mjbnp.cn http://www.morning.nfks.cn.gov.cn.nfks.cn http://www.morning.nchlk.cn.gov.cn.nchlk.cn http://www.morning.dfkmz.cn.gov.cn.dfkmz.cn http://www.morning.tsnwf.cn.gov.cn.tsnwf.cn http://www.morning.rmfh.cn.gov.cn.rmfh.cn http://www.morning.njhyk.cn.gov.cn.njhyk.cn http://www.morning.xwzsq.cn.gov.cn.xwzsq.cn http://www.morning.qfzjn.cn.gov.cn.qfzjn.cn http://www.morning.mwmxs.cn.gov.cn.mwmxs.cn http://www.morning.jzykq.cn.gov.cn.jzykq.cn http://www.morning.cyjjp.cn.gov.cn.cyjjp.cn http://www.morning.fzlk.cn.gov.cn.fzlk.cn