【OSG】运行OSG示例出现的奶牛不完整问题

发现一个很奇怪的问题:我用笔记本运行OSG里面的示例,出现的图案总是不完整显示的,以经典的奶牛图案为例,如图。



图一是我电脑上的情况,正常情况应该是图二。不知道这是什么原因,难道是我电脑显卡的原因吗?有谁碰到了类似的问题吗?有谁能解释一下吗?

=========================================分割线=========================================

经过漫长的探索,终于有一种不换电脑能够解决的办法了。

办法就是:不全屏显示。

在原来的程序main函数中,加上代码,如下:

osgViewer::Viewer viewer;
viewer->addEventHandler(new osgViewer::WindowSizeHandler);

或许还需要添加include。#include <osgViewer\ViewerEventHandlers>。

运行之后,按F键,即可小屏显示。

全屏效果:


小屏效果:


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
使用 OpenSceneGraph (OSG) 运行 OCC 模型的代码示例如下: ```cpp #include <osgViewer/Viewer> #include <osg/Geode> #include <osg/ShapeDrawable> #include <osgGA/TrackballManipulator> #include <osg/MatrixTransform> #include <osgDB/ReadFile> #include <BRepPrimAPI_MakeSphere.hxx> #include <TopoDS.hxx> #include <TopoDS_Shape.hxx> #include <BRep_Builder.hxx> #include <BRepTools.hxx> #include <BRepTools_WireExplorer.hxx> #include <BRepBuilderAPI_MakeWire.hxx> #include <BRepBuilderAPI_MakeFace.hxx> #include <BRepBuilderAPI_MakePolygon.hxx> #include <Poly_Triangulation.hxx> #include <Poly_Connect.hxx> #include <Poly_Polygon3D.hxx> #include <TopExp_Explorer.hxx> #include <TopLoc_Location.hxx> #include <Poly_Array1OfTriangle.hxx> #include <BRep_Tool.hxx> #include <Poly.hxx> osg::Node* createSphereNode() { TopoDS_Shape shape; BRep_Builder builder; BRepPrimAPI_MakeSphere sphere(gp_Pnt(0., 0., 0.), 1.); shape = sphere.Shape(); osg::ref_ptr<osg::Geode> geode = new osg::Geode(); TopExp_Explorer explorer(shape, TopAbs_FACE); while (explorer.More()) { TopoDS_Face face = TopoDS::Face(explorer.Current()); Handle(Poly_Triangulation) polyTri = BRep_Tool::Triangulation(face, TopLoc_Location()); if (!polyTri.IsNull()) { const TColgp_Array1OfPnt& nodes = polyTri->Nodes(); const Poly_Array1OfTriangle& triangles = polyTri->Triangles(); osg::ref_ptr<osg::Vec3Array> vertices = new osg::Vec3Array(); osg::ref_ptr<osg::DrawElementsUInt> indices = new osg::DrawElementsUInt(osg::PrimitiveSet::TRIANGLES, 0); for (Standard_Integer j = triangles.Lower(); j <= triangles.Upper(); j++) { Standard_Integer n1, n2, n3; triangles(j).Get(n1, n2, n3); gp_Pnt node1 = nodes(n1); gp_Pnt node2 = nodes(n2); gp_Pnt node3 = nodes(n3); vertices->push_back(osg::Vec3(node1.X(), node1.Y(), node1.Z())); vertices->push_back(osg::Vec3(node2.X(), node2.Y(), node2.Z())); vertices->push_back(osg::Vec3(node3.X(), node3.Y(), node3.Z())); indices->push_back(vertices->size() - 3); indices->push_back(vertices->size() - 2); indices->push_back(vertices->size() - 1); } osg::ref_ptr<osg::Geometry> geometry = new osg::Geometry(); geometry->setVertexArray(vertices); geometry->addPrimitiveSet(indices); geode->addDrawable(geometry); } explorer.Next(); } return geode.release(); } int main(int argc, char** argv) { osg::ref_ptr<osg::Node> model = createSphereNode(); osgViewer::Viewer viewer; viewer.setSceneData(model); viewer.setCameraManipulator(new osgGA::TrackballManipulator()); return viewer.run(); } ``` 在这个示例中,我们创建了一个简单的球体,然后将其转换为 OSG 中的节点,最后将其添加到场景中。我们使用 OCC 库提供的函数来获取球体的三角网格,然后使用 OSG 中的几何体来渲染这个三角网格。最后,我们启动 OSG 视图器并显示场景。 请注意,这只是一个简单的示例,如果要使用 OCC 库加载更复杂的模型,您需要编写更多的代码来处理模型的各个部分。
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值