i did get a runtime error at "_localStateSet->setAttribute(getViewport());" 
when calling SceneView->draw if not calling SceneView->cull first.  dont have 
the log file here right now, and i am in the middle of some other coding stuff, 
just thought you should know.

From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Robert Osfield
Sent: 10. april 2008 18:08
To: OpenSceneGraph Users
Subject: Re: [osg-users] SceneView error

Hi Erf???

Can't make any sense of your email, and not about to go trying to sieve through 
your example code trying to work out what you might mean.

Please try and be specific, tell us what error you get, a compile, and link 
error, a runtime error????

Also try telling us which version of the OSG you are talking about?  2.x 
doesn't have any SceneView examples for instance...

Robert.
On Tue, Apr 8, 2008 at 12:50 PM, <[EMAIL PROTECTED]<mailto:[EMAIL PROTECTED]>> 
wrote:

I try to use OpenSceneGraph and SceneView as shown in example when using an 
existing renderer, but get an error when calling "SceneView->draw()" or more 
spesific in



"_localStateSet->setAttribute(getViewport());"



The example code I use is as following:



int CMapRenderThread::InitOpenSceneGraph()

{

      root              = new osg::Group;

      pyramidGeode      = new osg::Geode;

      pyramidGeometry = new osg::Geometry;



      // Associate the pyramid geometry with the pyramid geode

      // Add the pyramid geode to the root node of the scene graph.

      pyramidGeode->addDrawable(pyramidGeometry);

      root->addChild(pyramidGeode);



      // Declare an array of vertices.

      osg::Vec3Array* pyramidVertices = new osg::Vec3Array;

      pyramidVertices->push_back( osg::Vec3( 0, 0, 0) ); // front left

      pyramidVertices->push_back( osg::Vec3(10, 0, 0) ); // front right

      pyramidVertices->push_back( osg::Vec3(10,10, 0) ); // back right

      pyramidVertices->push_back( osg::Vec3( 0,10, 0) ); // back left

      pyramidVertices->push_back( osg::Vec3( 5, 5,10) ); // peak

      pyramidGeometry->setVertexArray( pyramidVertices );



      // Create a primitive set and add it to the pyramid geometry.

      osg::DrawElementsUInt* pyramidBase = new 
osg::DrawElementsUInt(osg::PrimitiveSet::QUADS, 0);

      pyramidBase->push_back(3);

      pyramidBase->push_back(2);

      pyramidBase->push_back(1);

      pyramidBase->push_back(0);

      pyramidGeometry->addPrimitiveSet(pyramidBase);



      // Repeat the same for each of the four sides. Again, vertices are

      // specified in counter-clockwise order.

      osg::DrawElementsUInt* pyramidFaceOne = new 
osg::DrawElementsUInt(osg::PrimitiveSet::TRIANGLES, 0);

      pyramidFaceOne->push_back(0);

      pyramidFaceOne->push_back(1);

      pyramidFaceOne->push_back(4);

      pyramidGeometry->addPrimitiveSet(pyramidFaceOne);



      osg::DrawElementsUInt* pyramidFaceTwo = new 
osg::DrawElementsUInt(osg::PrimitiveSet::TRIANGLES, 0);

      pyramidFaceTwo->push_back(1);

      pyramidFaceTwo->push_back(2);

      pyramidFaceTwo->push_back(4);

      pyramidGeometry->addPrimitiveSet(pyramidFaceTwo);



      osg::DrawElementsUInt* pyramidFaceThree = new 
osg::DrawElementsUInt(osg::PrimitiveSet::TRIANGLES, 0);

      pyramidFaceThree->push_back(2);

      pyramidFaceThree->push_back(3);

      pyramidFaceThree->push_back(4);

      pyramidGeometry->addPrimitiveSet(pyramidFaceThree);



      osg::DrawElementsUInt* pyramidFaceFour = new 
osg::DrawElementsUInt(osg::PrimitiveSet::TRIANGLES, 0);

      pyramidFaceFour->push_back(3);

      pyramidFaceFour->push_back(0);

      pyramidFaceFour->push_back(4);

      pyramidGeometry->addPrimitiveSet(pyramidFaceFour);



      // Declare and load an array of Vec4 elements to store colors.

      osg::Vec4Array* colors = new osg::Vec4Array;

      colors->push_back(osg::Vec4(1.0f, 0.0f, 0.0f, 1.0f) ); //index 0 red

      colors->push_back(osg::Vec4(0.0f, 1.0f, 0.0f, 1.0f) ); //index 1 green

      colors->push_back(osg::Vec4(0.0f, 0.0f, 1.0f, 1.0f) ); //index 2 blue

      colors->push_back(osg::Vec4(1.0f, 1.0f, 1.0f, 1.0f) ); //index 3 white



      // Declare the variable that will match vertex array elements to color

      // array elements.

      osg::TemplateIndexArray<unsigned int, osg::Array::UIntArrayType,4,4> 
*colorIndexArray;

      colorIndexArray = new osg::TemplateIndexArray<unsigned int, 
osg::Array::UIntArrayType,4,4>;

      colorIndexArray->push_back(0); // vertex 0 assigned color array element 0

      colorIndexArray->push_back(1); // vertex 1 assigned color array element 1

      colorIndexArray->push_back(2); // vertex 2 assigned color array element 2

      colorIndexArray->push_back(3); // vertex 3 assigned color array element 3

      colorIndexArray->push_back(0); // vertex 4 assigned color array element 0



      // The next step is to associate the array of colors with the geometry,

      // assign the color indices created above to the geometry and set the

      // binding mode to BIND_PER_VERTEX.

      pyramidGeometry->setColorArray(colors);

      pyramidGeometry->setColorIndices(colorIndexArray);

      pyramidGeometry->setColorBinding(osg::Geometry::BIND_PER_VERTEX);



      // Declare and initialize a transform node.

      pyramidTwoXForm = new osg::PositionAttitudeTransform;



      // Use the 'addChild' method of the osg::Group class to

      // add the transform as a child of the root node and the

      // pyramid node as a child of the transform.

      root->addChild(pyramidTwoXForm);

      pyramidTwoXForm->addChild(pyramidGeode);



      // Declare and initialize a Vec3 instance to change the

      // position of the model in the scene



      //m_pRenderer->



      //double x,y,z;

      //LatLonAltToXYZ(61.0, 10.0, 500.0, &x, &y, &z, this);

      //osg::Vec3 pyramidTwoPosition(x,y,z);

      //pyramidTwoXForm->setPosition( pyramidTwoPosition );



      pyramidTwoXForm->setScale(osg::Vec3d(100,100,100));



      // The final step is to set up and enter a simulation loop.

      /*

      osgViewer::Viewer viewer;

      viewer.setSceneData( root );

      viewer.setCameraManipulator(new osgGA::TrackballManipulator);

      viewer.realize();



      while( !viewer.done() )

      {

            viewer.frame();

      }

      */



      //visitor = new 
osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ACTIVE_CHILDREN);

      //visitor = new osg::NodeVisitor;



      sceneViewer = new osgUtil::SceneView();



      sceneViewer->setDefaults();

      sceneViewer->setComputeNearFarMode( 
osgUtil::CullVisitor::DO_NOT_COMPUTE_NEAR_FAR );

      sceneViewer->setSceneData(root);



      return 0;

}



int CMapRenderThread::DrawOpenSceneGraph()

{

      // init

      GLint viewParams[4];

      glGetIntegerv( GL_VIEWPORT, viewParams );

      sceneViewer->setViewport(viewParams[0], viewParams[1], viewParams[2], 
viewParams[3]);



      GLfloat glMat[16];

      osg::Matrix osgMat;



      glGetFloatv( GL_PROJECTION_MATRIX, glMat );

      osgMat.set( glMat );

      sceneViewer->setProjectionMatrix(osgMat);



      glGetFloatv( GL_MODELVIEW_MATRIX, glMat );

      osgMat.set( glMat );

      sceneViewer->setViewMatrix(osgMat);





      // reset all

      glPushAttrib(GL_ALL_ATTRIB_BITS );

      glMatrixMode(GL_PROJECTION);

      glPushMatrix();

      glMatrixMode(GL_TEXTURE);

      glPushMatrix();

      glMatrixMode(GL_MODELVIEW);

      glPushMatrix();





      // draw objects in scenegraph

      sceneViewer->draw();





      // set back

      glMatrixMode(GL_TEXTURE);

      glPopMatrix();

      glMatrixMode(GL_PROJECTION);

      glPopMatrix();

      glMatrixMode(GL_MODELVIEW);

      glPopMatrix();

      glPopAttrib();



      return 0;

}



_______________________________________________
osg-users mailing list
[email protected]<mailto:[email protected]>
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to