|
楼主 |
发表于 2010-1-13 14:03:23
|
显示全部楼层
本帖最后由 小行星 于 2010-1-13 14:05 编辑
您能帮我看一下这些代码吗?
CreateGeometry_1和CreateGeometry_2几乎完全一样,唯一不同的就是在CreateGeometry_1多了那三句话:
- pGeometry->setDataVariance( osg::Object::DYNAMIC );
- pGeometry->setUseDisplayList( false );
- pGeometry->setUseVertexBufferObjects( true );
复制代码
并且如果把CreateGeometry_2中n的值从8改到7,这段程序就不会崩掉,实在是没头绪……
- #include <osg/Geode>
- #include <osg/Geometry>
- #include <osgViewer/Viewer>
- osg::Geometry* CreateGeometry_1()
- {
- osg::Geometry* pGeometry = new osg::Geometry;
- double space_ = 10;
- double left_ = -100;
- double right_ = 100;
- double n = 8;
- osg::Vec3Array* pVertices = new osg::Vec3Array;
- for( int i = -n; i <= n; ++i )
- {
- pVertices->push_back( osg::Vec3( left_, i * space_, 0 ) );
- pVertices->push_back( osg::Vec3( right_, i * space_, 0 ) );
- }
- osg::Vec3Array::size_type s = pVertices->size();
- pGeometry->setVertexArray( pVertices );
- pGeometry->addPrimitiveSet( new osg:rawArrays( osg:rimitiveSet:INES, 0, s ) );
- pGeometry->setDataVariance( osg::Object:YNAMIC );
- pGeometry->setUseDisplayList( false );
- pGeometry->setUseVertexBufferObjects( true );
- return pGeometry;
- }
- osg::Geometry* CreateGeometry_2()
- {
- osg::Geometry* pGeometry = new osg::Geometry;
- double space_ = 10;
- double bottom_ = -100;
- double top_ = 100;
- // 这里改成7就没事
- double n = 8;
- osg::Vec3Array* pVertices = new osg::Vec3Array;
- for( int i = -n; i <= n; ++i )
- {
- pVertices->push_back( osg::Vec3( i * space_, bottom_, 0 ) );
- pVertices->push_back( osg::Vec3( i * space_, top_, 0 ) );
- }
- osg::Vec3Array::size_type s = pVertices->size();
- pGeometry->setVertexArray( pVertices );
- pGeometry->addPrimitiveSet( new osg:rawArrays( osg:rimitiveSet:INES, 0, s ) );
- return pGeometry;
- }
- int main( int argc, char** argv )
- {
- osg::Geode* pGeode = new osg::Geode;
- pGeode->addDrawable( CreateGeometry_1() );
- pGeode->addDrawable( CreateGeometry_2() );
- osgViewer::Viewer viewer;
- viewer.setUpViewInWindow( 50, 50, 800, 600 );
- viewer.setSceneData( pGeode );
- viewer.run();
- return 0;
- }
复制代码 |
|