Hi!

Im very new to osg, im trying to compile and run a very simple code that use 
osg (basicgeon.cpp is attached)

when its gets to the last 3 lines, its crush on the third one

                   ...
                   osgViewer::Viewer viewer;
           viewer.setSceneData( root );
->         return viewer.run();

the project compile properly and crush on runtime,
i set the include and lib directories as needed, and the used lib in 
release(osg.lib, osgViewer.lib)

i set the output directory and workdir to \osg\bin so it will find the dll's

im using visual studio 9.0 on VISTA ... (i suspect something with it  [Crying 
or Very sad] )

i download all the binaries from 
http://www.openscenegraph.org/downloads/stable_releases/OpenSceneGraph-2.8/binaries/Windows/VisualStudio9
(extracted the debug files then the release files with 7zip)

i tried in debug too ,still crush(added the d for the required lib files..)

i tried to run the created exe from outside the visual,still crush..

the crush looks like this:
[Image: http://images.upload2world.com/get-4-2009-upload2world_com_lmjodx.jpg ] 
(http://www.upload2world.com) 


im really dont know what else to do and kinda stuck

thanks alot for any help!

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=10364#10364



// basicgeom.cpp : Defines the entry point for the console application.
//

//#include "stdafx.h"   //StdAfx.h
#include <osg/Node>
#include <osg/Group>
#include <osg/Geode>
#include <osg/Geometry>
#include <osg/Texture2D>
#include <osgDB/ReadFile>
#include <osgViewer/Viewer>
#include <osg/PositionAttitudeTransform>

//int _tmain(int argc, _TCHAR* argv[])
int main()
{
           osg::Group* root = new osg::Group();
           osg::Geode* pyramidGeode = new osg::Geode();
           osg::Geometry* 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
        
           // Associate this set of vertices with the geometry associated with 
the
           // geode we added to the scene.
           pyramidGeometry->setVertexArray( pyramidVertices );
//         crossGeometry->setVertexArray (crossVertices);
           
           // 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.
           osg::PositionAttitudeTransform* 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
           osg::Vec3 pyramidTwoPosition(15,0,0);
           pyramidTwoXForm->setPosition( pyramidTwoPosition );
        
           // The final step is to set up and enter a simulation loop.
           osgViewer::Viewer viewer;
        
           viewer.setSceneData( root );
           return viewer.run();
          /* */
        return 0;
}

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

Reply via email to