本文整理汇总了C++中osg::GLUTWindowRefPtr::init方法的典型用法代码示例。如果您正苦于以下问题:C++ GLUTWindowRefPtr::init方法的具体用法?C++ GLUTWindowRefPtr::init怎么用?C++ GLUTWindowRefPtr::init使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类osg::GLUTWindowRefPtr
的用法示例。
在下文中一共展示了GLUTWindowRefPtr::init方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
// Initialize GLUT & OpenSG and set up the scene
int main(int argc, char **argv)
{
// OSG init
OSG::osgInit(argc,argv);
// GLUT init
int winid = setupGLUT(&argc, argv);
// the connection between GLUT and OpenSG
g_win= OSG::GLUTWindow::create();
g_win->setGlutId(winid);
g_win->init();
g_scene = createScene();
// create the SimpleSceneManager helper
g_mgr = OSG::SimpleSceneManager::create();
g_mgr->setUseTraversalAction(true);
// tell the manager what to manage
g_mgr->setWindow(g_win );
g_mgr->setRoot (g_scene);
// add LabelForeground!!!
g_labelForeground = OSG::LabelForeground::create();
g_mgr->addForeground(g_labelForeground);
// show the whole scene
g_mgr->showAll();
// GLUT main loop
glutMainLoop();
return 0;
}
示例2: main
int main(int argc, char **argv)
{
g_error1 = 0.01f;
g_error2 = g_error1;
processArgs( argc, argv );
OSG::osgInit(argc,argv);
// GLUT init
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE);
int winid = glutCreateWindow("OpenSG");
glutReshapeFunc(reshape);
glutDisplayFunc(display);
glutIdleFunc(display);
glutMouseFunc(mouse);
glutMotionFunc(motion);
glutKeyboardFunc(keyboard);
{
OSG::GLUTWindowRefPtr gwin = OSG::GLUTWindow::create();
gwin->setGlutId(winid);
gwin->init();
// create the scene
OSG::NodeRefPtr scene;
scene = makeScene( );
if ( scene == NULL )
{
std::cerr<<"makeScene returned NullFC, exiting..."<<std::endl;
return -1;
}
// create the SimpleSceneManager helper
mgr = new OSG::SimpleSceneManager;
// create the window and initial camera/viewport
mgr->setWindow( gwin );
// tell the manager what to manage
mgr->setRoot ( scene );
// show the whole scene
mgr->showAll();
mgr->redraw();
OSG::SolidBackgroundRefPtr bgr = OSG::SolidBackground::create();
bgr->setColor( OSG::Color3f( 0.7f, 0.7f, 0.7f ));
mgr->getWindow()->getPort(0)->setBackground( bgr );
}
// GLUT main loop
glutMainLoop();
return 0;
}
示例3: main
// Initialize GLUT & OpenSG and set up the scene
int main(int argc, char **argv)
{
//sortNumbers function
int numberArray[] = {2, 13, 56, 8, 22, 16, 24, 89, 11, 90};
sortNumbers(numberArray,10);
// OSG init
OSG::osgInit(argc,argv);
// GLUT init
int winid = setupGLUT(&argc, argv);
// open a new scope, because the pointers gwin and scene below should
// go out of scope before entering glutMainLoop.
// Otherwise OpenSG will complain about objects being alive after shutdown.
{
// the connection between GLUT and OpenSG
OSG::GLUTWindowRefPtr gwin = OSG::GLUTWindow::create();
gwin->setGlutId(winid);
gwin->init();
// create the scene
OSG::NodeRefPtr scene = OSG::makeBox(1,1,1,2,2,2);
OSG::commitChanges();
// create the SimpleSceneManager helper
mgr = OSG::SimpleSceneManager::create();
// tell the manager what to manage
mgr->setWindow(gwin );
mgr->setRoot (scene);
// show the whole scene
mgr->showAll();
}
// GLUT main loop
glutMainLoop();
return 0;
}
示例4: main
int main(int argc, char* argv[])
{
std::cerr << argv[0] << ". Press 'h' for keys" << std::endl;
// Init OSG and glut.
OSG::osgInit(argc,argv);
{
int winid = setupGLUT(&argc, argv);
OSG::GLUTWindowRefPtr gwin = OSG::GLUTWindow::create();
gwin->setGlutId(winid);
gwin->init();
printFontFamilies();
// load the scene
OSG::NodeRefPtr scene = OSG::Node::create();
scene->setCore(OSG::Group::create());
// Setup text sample
gTextStuff = new TextStuff();
gTextStuff->initialize();
gTextStuff->updateFace();
gTextStuff->updateScene();
scene->addChild(gTextStuff->mRootNode);
mgr = new OSG::SimpleSceneManager;
// Tell the manager about the window and scene
mgr->setWindow(gwin );
mgr->setRoot(scene);
// Start it up
mgr->showAll();
}
glutMainLoop();
return 0;
}
示例5: main
// Initialize GLUT & OpenSG and set up the scene
int main(int argc, char **argv)
{
// OSG init
OSG::osgInit(argc,argv);
// GLUT init
int winid = setupGLUT(&argc, argv);
// open a new scope, because the pointers below should go out of scope
// before entering glutMainLoop.
// Otherwise OpenSG will complain about objects being alive after shutdown.
{
// the connection between GLUT and OpenSG
OSG::GLUTWindowRefPtr gwin = OSG::GLUTWindow::create();
gwin->setGlutId(winid);
gwin->init();
// create the scene
// create a pretty simple graph: a Group with two Transforms as children,
// each of which carries a single Geometry.
// The scene group
OSG::NodeRefPtr scene = OSG::Node::create();
OSG::GroupRefPtr g = OSG::Group::create();
scene->setCore(g);
// The cylinder and its transformation
OSG::NodeRefPtr cyl = OSG::makeCylinder( 1.4f, .3f, 8, true, true, true );
cyltrans = OSG::Transform::create();
OSG::NodeRefPtr cyltransnode = OSG::Node::create();
cyltransnode->setCore (cyltrans);
cyltransnode->addChild(cyl );
// add it to the scene
scene->addChild(cyltransnode);
// The torus and its transformation
OSG::NodeRefPtr torus = OSG::makeTorus( .2f, 1, 8, 12 );
tortrans = OSG::Transform::create();
OSG::NodeRefPtr tortransnode = OSG::Node::create();
tortransnode->setCore (tortrans);
tortransnode->addChild(torus );
// add it to the scene
scene->addChild(tortransnode);
// now traverse the scene
/*
There are four variants of the traverse() function.
It can either be called for a single node or for a vector nodes. And
they can either call a function just when entering the node, or in
addition when leaving the node. The signatures of the functions are:
enter functions:
Action::ResultE enter(Node *node);
leave functions:
Action::ResultE leave(Node *node, Action::ResultE res);
The functions that are called are wrapped in functors. A functor is an
object that contains a function or method, which can be called through
the functor. OpenSG uses boost::function for this purpose and
provides appriopriate typedefs for enter and leave functors as
TraverseEnterFunctor and TraverseLeaveFunctor (see OSGAction.h).
In order to call member functions through a functor an object of
the correct type has to be available (there has to an object to
take the role of this for the member function). To store an
instance of an object in a functor use boost::bind to bind the
first argument of the member function functor to the object (see
below for examples).
*/
SLOG << "Variant 1: just print every encountered node" << OSG::endLog;
traverse(scene, enter);
SLOG << OSG::endLog
<< "Variant 2: just print every encountered node, using a"
<< " vector of nodes" << OSG::endLog;
std::vector<OSG::Node *> nodevec;
nodevec.push_back(tortransnode);
nodevec.push_back(cyltransnode);
traverse(nodevec, enter);
SLOG << OSG::endLog
<< "Variant 3: just print every encountered node on entering"
//.........这里部分代码省略.........
示例6: main
// Initialize GLUT & OpenSG and set up the scene
int main(int argc, char **argv)
{
// OSG init
OSG::osgInit(argc,argv);
// GLUT init
int winid = setupGLUT(&argc, argv);
/*
open a new scope, because the pointers below should go out of scope
before entering glutMainLoop.
Otherwise OpenSG will complain about objects being alive after shutdown.
*/
{
// the connection between GLUT and OpenSG
OSG::GLUTWindowRefPtr gwin = OSG::GLUTWindow::create();
gwin->setGlutId(winid);
gwin->init();
/*
create the scene
In the previous example, the colors and positions used the same
indices. That might not always be the preferred way, and it might not
make sense for other properties, e.g. normals.
It is possible to assign a different index for every property. See the
indices section below for details.
The initial setup is the same as in 06indexgeometry
*/
OSG::GeoUInt8PropertyRefPtr type = OSG::GeoUInt8Property::create();
type->addValue(GL_POLYGON );
type->addValue(GL_TRIANGLES);
type->addValue(GL_QUADS );
OSG::GeoUInt32PropertyRefPtr lens = OSG::GeoUInt32Property::create();
lens->addValue(4);
lens->addValue(6);
lens->addValue(8);
// positions
OSG::GeoPnt3fPropertyRefPtr pnts = OSG::GeoPnt3fProperty::create();
// the base
pnts->addValue(OSG::Pnt3f(-1, -1, -1));
pnts->addValue(OSG::Pnt3f(-1, -1, 1));
pnts->addValue(OSG::Pnt3f( 1, -1, 1));
pnts->addValue(OSG::Pnt3f( 1, -1, -1));
// the roof base
pnts->addValue(OSG::Pnt3f(-1, 0, -1));
pnts->addValue(OSG::Pnt3f(-1, 0, 1));
pnts->addValue(OSG::Pnt3f( 1, 0, 1));
pnts->addValue(OSG::Pnt3f( 1, 0, -1));
// the gable
pnts->addValue(OSG::Pnt3f( 0, 1, -1));
pnts->addValue(OSG::Pnt3f( 0, 1, 1));
// colors
OSG::GeoVec3fPropertyRefPtr colors = OSG::GeoVec3fProperty::create();
colors->push_back(OSG::Color3f(1, 1, 0));
colors->push_back(OSG::Color3f(1, 0, 0));
colors->push_back(OSG::Color3f(1, 0, 0));
colors->push_back(OSG::Color3f(1, 1, 0));
colors->push_back(OSG::Color3f(0, 1, 1));
colors->push_back(OSG::Color3f(1, 0, 1));
/*
A new property: normals.
They are used for lighting calculations and have to point away from the
surface. Normals are standard vectors.
*/
OSG::GeoVec3fPropertyRefPtr norms = OSG::GeoVec3fProperty::create();
norms->push_back(OSG::Vec3f(-1, 0, 0));
norms->push_back(OSG::Vec3f( 1, 0, 0));
norms->push_back(OSG::Vec3f( 0, -1, 0));
norms->push_back(OSG::Vec3f( 0, 1, 0));
norms->push_back(OSG::Vec3f( 0, 0, -1));
norms->push_back(OSG::Vec3f( 0, 0, 1));
/*
To use more than one index for a geometry, create multiple
GeoUInt32Property (or GeoUInt8Property or GeoUInt16Property) objects
and add them as index for the corresponding property you want to
index.
*/
OSG::GeoUInt32PropertyRefPtr ind1 = OSG::GeoUInt32Property::create();
OSG::GeoUInt32PropertyRefPtr ind2 = OSG::GeoUInt32Property::create();
// fill first index (will be used for positions)
ind1->push_back(0); // polygon
ind1->push_back(1);
ind1->push_back(2);
//.........这里部分代码省略.........
示例7: main
// Initialize GLUT & OpenSG and set up the scene
int main(int argc, char **argv)
{
// OSG init
OSG::osgInit(argc,argv);
// GLUT init
int winid = setupGLUT(&argc, argv);
// open a new scope, because the pointers below should go out of scope
// before entering glutMainLoop.
// Otherwise OpenSG will complain about objects being alive after shutdown.
{
// the connection between GLUT and OpenSG
OSG::GLUTWindowRefPtr gwin = OSG::GLUTWindow::create();
gwin->setGlutId(winid);
gwin->init();
// create the scene
_scene = OSG::makeCoredNode<OSG::Group>();
// create four lights sharing the same beacon.
OSG::TransformRefPtr light_trans;
OSG::NodeRefPtr light_beacon =
OSG::makeCoredNode<OSG::Transform>(&light_trans);
light_trans->editMatrix().setTranslate(0.0, 0.0, 10.0);
// red light.
OSG::PointLightRefPtr light1_core;
OSG::NodeRefPtr light1 =
OSG::makeCoredNode<OSG::PointLight>(&light1_core);
light1_core->setAmbient(0.0,0.0,0.0,1);
light1_core->setDiffuse(1.0,0.0,0.0,1);
light1_core->setSpecular(0.8f,0.8f,0.8f,1);
light1_core->setBeacon(light_beacon);
light1_core->setOn(true);
// green light.
OSG::PointLightRefPtr light2_core;
OSG::NodeRefPtr light2 =
OSG::makeCoredNode<OSG::PointLight>(&light2_core);
light2_core->setAmbient(0.0,0.0,0.0,1);
light2_core->setDiffuse(0.0,1.0,0.0,1);
light2_core->setSpecular(0.8f,0.8f,0.8f,1);
light2_core->setBeacon(light_beacon);
light2_core->setOn(true);
// blue light.
OSG::PointLightRefPtr light3_core;
OSG::NodeRefPtr light3 =
OSG::makeCoredNode<OSG::PointLight>(&light3_core);
light3_core->setAmbient(0.0,0.0,0.0,1);
light3_core->setDiffuse(0.0,0.0,1.0,1);
light3_core->setSpecular(0.8f,0.8f,0.8f,1);
light3_core->setBeacon(light_beacon);
light3_core->setOn(true);
// white light.
OSG::PointLightRefPtr light4_core;
OSG::NodeRefPtr light4 =
OSG::makeCoredNode<OSG::PointLight>(&light4_core);
light4_core->setAmbient(0.0,0.0,0.0,1);
light4_core->setDiffuse(1.0,1.0,1.0,1);
light4_core->setSpecular(0.0,0.0,0.0,1);
light4_core->setBeacon(light_beacon);
light4_core->setOn(true);
OSG::NodeRefPtr bottom = OSG::makePlane(25.0, 25.0, 128, 128);
// create three spheres.
OSG::NodeRefPtr sphere1 = OSG::makeLatLongSphere(50, 50, 1.0);
OSG::TransformRefPtr sphere1_trans_core;
OSG::NodeRefPtr sphere1_trans =
OSG::makeCoredNode<OSG::Transform>(&sphere1_trans_core);
sphere1_trans_core->editMatrix().setTranslate(-5.0, 0.0, 5.0);
sphere1_trans->addChild(sphere1);
OSG::NodeRefPtr sphere2 = OSG::makeLatLongSphere(50, 50, 1.0);
OSG::TransformRefPtr sphere2_trans_core;
OSG::NodeRefPtr sphere2_trans =
OSG::makeCoredNode<OSG::Transform>(&sphere2_trans_core);
sphere2_trans_core->editMatrix().setTranslate(0.0, 0.0, 5.0);
sphere2_trans->addChild(sphere2);
OSG::NodeRefPtr sphere3 = OSG::makeLatLongSphere(50, 50, 1.0);
OSG::TransformRefPtr sphere3_trans_core;
OSG::NodeRefPtr sphere3_trans =
OSG::makeCoredNode<OSG::Transform>(&sphere3_trans_core);
sphere3_trans_core->editMatrix().setTranslate(5.0, 0.0, 5.0);
sphere3_trans->addChild(sphere3);
light1->addChild(sphere1_trans);
light2->addChild(sphere2_trans);
light3->addChild(sphere3_trans);
light4->addChild(bottom);
_scene->addChild(light_beacon);
_scene->addChild(light1);
_scene->addChild(light2);
_scene->addChild(light3);
//.........这里部分代码省略.........
示例8: main
//
// Initialize GLUT & OpenSG and set up the scene
//
int main(int argc, char **argv)
{
// OSG init
OSG::osgInit(argc,argv);
// GLUT init
int winid = setupGLUT(&argc, argv);
// open a new scope, because the pointers below should go out of scope
// before entering glutMainLoop.
// Otherwise OpenSG will complain about objects being alive after shutdown.
{
// the connection between GLUT and OpenSG
OSG::GLUTWindowRefPtr gwin = OSG::GLUTWindow::create();
gwin->setGlutId(winid);
gwin->init();
// create the SimpleSceneManager helper
mgr = OSG::SimpleSceneManager::create();
mgr->setWindow(gwin);
// create a pretty simple graph: a Group with two Transforms as children,
// each of which carries a single Geometry.
// The scene
OSG::NodeRefPtr scene = OSG::Node::create();
// The cylinder and its transformation
OSG::NodeRefPtr cyl = OSG::Node::create();
OSG::GeometryRefPtr cylgeo = OSG::makeCylinderGeo( 1.4f, .3f, 24,
true, true, true );
cyl->setCore(cylgeo);
cyltrans = OSG::Transform::create();
OSG::NodeRefPtr cyltransnode = OSG::Node::create();
cyltransnode->setCore (cyltrans);
cyltransnode->addChild(cyl );
// add it to the scene
scene->addChild(cyltransnode);
// The torus and its transformation
OSG::NodeRefPtr torus = OSG::Node::create();
OSG::GeometryRefPtr torusgeo = OSG::makeTorusGeo( .2f, 1, 24, 36 );
torus->setCore(torusgeo);
tortrans = OSG::Transform::create();
OSG::NodeRefPtr tortransnode = OSG::Node::create();
tortransnode->setCore (tortrans);
tortransnode->addChild(torus );
// add it to the scene
scene->addChild(tortransnode);
//
// create the shader program
//
OSG::ShaderProgramChunkRefPtr prog_chunk = OSG::ShaderProgramChunk::create();
OSG::ShaderProgramRefPtr vertShader = OSG::ShaderProgram::createVertexShader();
OSG::ShaderProgramRefPtr fragShader = OSG::ShaderProgram::createFragmentShader();
vertShader->setProgram(get_vp_program());
fragShader->setProgram(get_fp_program());
//
// binding the unifrom block to a buffer binding point can be performed
// either by calling the shaders's addUniformBlock method or by
// adding a 'uniform block' variable to a ShaderProgramVariableChunk.
// In the following we use both variants for illustration.
//
fragShader->addUniformBlock("Materials", 1); // block binding point
fragShader->addUniformBlock("Lights", 2); // block binding point
//
// The following is replaced by adding ShaderProgramVariableChunk objects
// to the chunk material. See below...
//
// fragShader->addUniformBlock("GeomState", 3); // block binding point
prog_chunk->addShader(vertShader);
prog_chunk->addShader(fragShader);
//
// create uniform buffer objects and corresponding materials
//
OSG::UniformBufferObjChunkRefPtr ubo_material_database = create_material_database_state(materials);
ubo_light_state = create_light_state(lights);
OSG::PolygonChunkRefPtr polygon_chunk = OSG::PolygonChunk::create();
polygon_chunk->setFrontMode(GL_FILL);
polygon_chunk->setBackMode(GL_FILL);
polygon_chunk->setCullFace(GL_NONE);
//.........这里部分代码省略.........
示例9: main
// Initialize GLUT & OpenSG and set up the scene
int main(int argc, char **argv)
{
OSG::preloadSharedObject("OSGFileIO");
OSG::preloadSharedObject("OSGTBFileIO");
OSG::preloadSharedObject("OSGImageFileIO");
// OSG init
OSG::osgInit(argc,argv);
// GLUT init
int winid = setupGLUT(&argc, argv);
// open a new scope, because the pointers below should go out of scope
// before entering glutMainLoop.
// Otherwise OpenSG will complain about objects being alive after shutdown.
{
// the connection between GLUT and OpenSG
OSG::GLUTWindowRefPtr gwin = OSG::GLUTWindow::create();
gwin->setGlutId(winid);
gwin->init();
// create the scene
// create a pretty simple graph: a Group with two Transforms as children,
// each of which carries a single Geometry.
// The scene group
OSG::NodeRefPtr scene = OSG::Node::create();
OSG::GroupRefPtr g = OSG::Group::create();
scene->setCore(g);
// The cylinder and its transformation
OSG::NodeRefPtr cyl = OSG::Node::create();
OSG::GeometryRefPtr cylgeo = OSG::makeCylinderGeo( 1.4f, .3f, 64,
true, true, true );
cyl->setCore(cylgeo);
cyltrans = OSG::Transform::create();
OSG::NodeRefPtr cyltransnode = OSG::Node::create();
cyltransnode->setCore (cyltrans);
cyltransnode->addChild(cyl );
// add it to the scene
scene->addChild(cyltransnode);
// The torus and its transformation
OSG::NodeRefPtr torus = OSG::Node::create();
OSG::GeometryRefPtr torusgeo = OSG::makeTorusGeo( .2f, 1, 32, 64 );
torus->setCore(torusgeo);
tortrans = OSG::Transform::create();
OSG::NodeRefPtr tortransnode = OSG::Node::create();
tortransnode->setCore (tortrans);
tortransnode->addChild(torus );
// add it to the scene
scene->addChild(tortransnode);
// create the materials: Here, just using cgfx materials.
OSG::CgFXMaterialRefPtr mat1 = OSG::CgFXMaterial::create();
if(argc > 1)
{
mat1->setEffectFile(argv[1]);
}
// assign the material to the geometry
cylgeo->setMaterial(mat1);
// assign the material to the geometry
torusgeo->setMaterial(mat1);
OSG::commitChanges();
// create the SimpleSceneManager helper
mgr = new OSG::SimpleSceneManager;
// tell the manager what to manage
mgr->setWindow(gwin );
// file io
OSG::FCFileType::FCPtrStore Containers;
Containers.insert(scene);
//Use an empty Ignore types vector
OSG::FCFileType::FCTypeVector IgnoreTypes;
//IgnoreTypes.push_back(Node::getClassType().getId());
//Write the Field Containers to a xml file
OSG::FCFileHandler::the()->write(Containers,OSG::BoostPath("C:/Users/danielg/Desktop/test.xml"),IgnoreTypes);
//Read FieldContainers from an XML file
//.........这里部分代码省略.........
示例10: main
// Initialize GLUT & OpenSG and set up the scene
int main(int argc, char **argv)
{
// OSG init
OSG::osgInit(argc,argv);
// GLUT init
int winid = setupGLUT(&argc, argv);
// open a new scope, because the pointers below should go out of scope
// before entering glutMainLoop.
// Otherwise OpenSG will complain about objects being alive after shutdown.
{
// the connection between GLUT and OpenSG
OSG::GLUTWindowRefPtr gwin = OSG::GLUTWindow::create();
gwin->setGlutId(winid);
gwin->init();
// create the scene
// this time, create just the core of the geometry
OSG::GeometryRefPtr torus = OSG::makeTorusGeo( .5, 2, 8, 12 );
// create the scene
// the scene has a single group with ncopies transformations below,
// each of these carries a Node that shares the geometry
/*
The Switch NodeCore very similar to the Group, but it has the additional
capability to only show one or none of its children.
This is controlled by the choice Field, and is used below in the keys
function.
*/
// create the root Switch node
OSG::NodeRefPtr scene = OSG::Node::create();
sw = OSG::Switch::create();
sw->setChoice(OSG::Switch::ALL);
scene->setCore(sw);
// create the copied geometry nodes and their transformations
for(OSG::UInt16 i = 0; i<ncopies; ++i)
{
// create the nodes for the shared Geometry core
OSG::NodeRefPtr geonode = OSG::Node::create();
// assign the Core to the Node
geonode->setCore(torus);
// add a transformation for every Geometry
OSG::NodeRefPtr transnode = OSG::Node::create();
trans[i] = OSG::Transform::create();
transnode->setCore (trans[i]);
transnode->addChild(geonode );
scene->addChild(transnode);
}
OSG::commitChanges();
// create the SimpleSceneManager helper
mgr = new OSG::SimpleSceneManager;
// tell the manager what to manage
mgr->setWindow(gwin );
mgr->setRoot (scene);
// show the whole scene
mgr->showAll();
}
// GLUT main loop
glutMainLoop();
return 0;
}
示例11: main
// Initialize GLUT & OpenSG and set up the scene
int main(int argc, char **argv)
{
// OSG init
OSG::osgInit(argc,argv);
// GLUT init
int winid = setupGLUT(&argc, argv);
// open a new scope, because the pointers below should go out of scope
// before entering glutMainLoop.
// Otherwise OpenSG will complain about objects being alive after shutdown.
{
// the connection between GLUT and OpenSG
OSG::GLUTWindowRefPtr gwin = OSG::GLUTWindow::create();
gwin->setGlutId(winid);
gwin->init();
// The scene group
OSG::NodeRefPtr scene = OSG::Node::create();
OSG::GroupRefPtr g = OSG::Group::create();
scene->setCore(g);
if(argc < 2)
{
FWARNING(("No file given!\n"));
FWARNING(("Supported file formats:\n"));
std::list<const char*> suffixes;
OSG::SceneFileHandler::the()->getSuffixList(suffixes);
for(std::list<const char*>::iterator it = suffixes.begin();
it != suffixes.end();
++it)
{
FWARNING(("%s\n", *it));
}
fileroot = OSG::makeTorus(.5, 2, 16, 16);
}
else
{
fileroot = OSG::SceneFileHandler::the()->read(argv[1]);
/*
All scene file loading is handled via the SceneFileHandler.
*/
}
scene->addChild(fileroot);
// Create a small geometry to show the ray and what was hit
// Contains a line and a single triangle.
// The line shows the ray, the triangle whatever was hit.
OSG::SimpleMaterialRefPtr red = OSG::SimpleMaterial::create();
red->setDiffuse (OSG::Color3f( 1,0,0 ));
red->setTransparency(0.5);
red->setLit (false);
isectPoints = OSG::GeoPnt3fProperty::create();
isectPoints->addValue(OSG::Pnt3f(0,0,0));
isectPoints->addValue(OSG::Pnt3f(0,0,0));
isectPoints->addValue(OSG::Pnt3f(0,0,0));
isectPoints->addValue(OSG::Pnt3f(0,0,0));
isectPoints->addValue(OSG::Pnt3f(0,0,0));
OSG::GeoUInt32PropertyRefPtr index = OSG::GeoUInt32Property::create();
index->addValue(0);
index->addValue(1);
index->addValue(2);
index->addValue(3);
index->addValue(4);
OSG::GeoUInt32PropertyRefPtr lens = OSG::GeoUInt32Property::create();
lens->addValue(2);
lens->addValue(3);
OSG::GeoUInt8PropertyRefPtr type = OSG::GeoUInt8Property::create();
type->addValue(GL_LINES);
type->addValue(GL_TRIANGLES);
testgeocore = OSG::Geometry::create();
testgeocore->setPositions(isectPoints);
testgeocore->setIndices(index);
testgeocore->setLengths(lens);
testgeocore->setTypes(type);
testgeocore->setMaterial(red);
OSG::NodeRefPtr testgeo = OSG::Node::create();
testgeo->setCore(testgeocore);
scene->addChild(testgeo);
// create the SimpleSceneManager helper
mgr = OSG::SimpleSceneManager::create();
// tell the manager what to manage
//.........这里部分代码省略.........
示例12: main
OSG_END_NAMESPACE
// Initialize GLUT & OpenSG and set up the scene
int main(int argc, char **argv)
{
// OSG init
OSG::osgInit(argc,argv);
// GLUT init
int winid = setupGLUT(&argc, argv);
// open a new scope, because the pointers below should go out of scope
// before entering glutMainLoop.
// Otherwise OpenSG will complain about objects being alive after shutdown.
{
// the connection between GLUT and OpenSG
OSG::GLUTWindowRefPtr gwin = OSG::GLUTWindow::create();
gwin->setGlutId(winid);
gwin->init();
// load the scene
OSG::NodeRefPtr scene;
if(argc < 2)
{
FWARNING(("No file given!\n"));
scene = OSG::makeTorus(.5, 2, 16, 16);
}
else
{
scene = OSG::SceneFileHandler::the()->read(argv[1]);
}
/*
An Attachment is a special field container that can be attached to
many of the internal classes like Nodes, NodeCores and many others.
There can be multiple Attachments attached to an object.
Attachments can be attached to all FieldContainers that are derived from
AttachmentContainer. This includes most higher-level classes in the
system, like Nodes, NodeCores, Windows, Viewports etc. See the
inheritance graph for details.
One predefined kind of Attachment is the Name, which can
keep the name of an object. Some of loaders (e.g. the WRL loader)
create these kinds of Attachments for named nodes.
*/
/*
An Attachment is a FieldContainer and as such needs to be created using
::create().
*/
OSG::NameRefPtr name = OSG::Name::create();
/*
The NameAttachment only has a single field, there's no need to use the
mask here.
*/
name->editFieldPtr()->setValue("Scene");
/*
Attach the name to the scene node.
*/
scene->addAttachment(name);
/*
Check if the scene has a Name attachment
Attachments are categorized by the GroupID of their class. Every
AttachmentContainer generally keeps only one attachment of a specific
kind.
*/
OSG::AttachmentRefPtr a;
a = scene->findAttachment(OSG::Name::getClassType());
if(a != NULL)
{
OSG::NameRefPtr n = OSG::dynamic_pointer_cast<OSG::Name>(a);
SLOG << "Node name: " << n->getField().getValue() << OSG::endLog;
}
else
{
SLOG << "Node has no name!" << OSG::endLog;
}
/*
As names are used quite often there are two convenience functions
that wrap the code given above: setName and getName. They are declared
in OSGSimpleAttachments.h.
*/
if(getName(scene))
{
SLOG << "Node is named: " << getName(scene) << OSG::endLog;
}
else
{
//.........这里部分代码省略.........
示例13: main
// Initialize GLUT & OpenSG and set up the scene
int main(int argc, char **argv)
{
// OSG init
OSG::osgInit(argc,argv);
// GLUT init
int winid = setupGLUT(&argc, argv);
// open a new scope, because the pointers below should go out of scope
// before entering glutMainLoop.
// Otherwise OpenSG will complain about objects being alive after shutdown.
{
// the connection between GLUT and OpenSG
OSG::GLUTWindowRefPtr gwin = OSG::GLUTWindow::create();
gwin->setGlutId(winid);
gwin->init();
// load the scene
OSG::NodeRefPtr scene;
if(argc < 2)
{
FWARNING(("No file given!\n"));
FWARNING(("Supported file formats:\n"));
std::list<const char*> suffixes;
OSG::SceneFileHandler::the()->getSuffixList(suffixes, OSG::SceneFileType::OSG_READ_SUPPORTED);
for(std::list<const char*>::iterator it = suffixes.begin();
it != suffixes.end();
++it)
{
FWARNING(("%s\n", *it));
}
scene = OSG::makeTorus(.5, 2, 16, 16);
}
else
{
/*
All scene file loading is handled via the SceneFileHandler.
*/
scene = OSG::SceneFileHandler::the()->read(argv[1]);
}
OSG::commitChanges();
// calc size of the scene
OSG::Vec3f min, max;
OSG::BoxVolume vol;
scene->getWorldVolume(vol);
vol.getBounds(min, max);
OSG::Vec3f d = max - min;
OSG::Real32 offset = d.length() / 2.0f;
// now create a deep clone
OSG::NodeRefPtr sceneClone = OSG::deepCloneTree(scene);
// this clones all nodes but the cores of type Material and Transform are shared.
//NodePtr sceneClone = deepCloneTree(scene, "Material, Transform");
// now change all geometries from the cloned scene just to show
// that it is a real deep copy.
traverse(sceneClone, &changeGeo);
// create a small scene graph with two transformation nodes.
OSG::NodeRefPtr root = OSG::makeCoredNode<OSG::Group>();
OSG::ComponentTransformRefPtr t1;
OSG::NodeRefPtr tn1 =
OSG::makeCoredNode<OSG::ComponentTransform>(&t1);
OSG::ComponentTransformRefPtr t2;
OSG::NodeRefPtr tn2 =
OSG::makeCoredNode<OSG::ComponentTransform>(&t2);
t1->setTranslation(OSG::Vec3f(- offset, 0.0f, 0.0f));
t2->setTranslation(OSG::Vec3f(offset, 0.0f, 0.0f));
tn1->addChild(scene);
tn2->addChild(sceneClone);
root->addChild(tn1);
root->addChild(tn2);
OSG::commitChanges();
// create the SimpleSceneManager helper
mgr = new OSG::SimpleSceneManager;
// tell the manager what to manage
mgr->setWindow(gwin );
mgr->setRoot (root);
// show the whole scene
mgr->showAll();
}
// GLUT main loop
glutMainLoop();
//.........这里部分代码省略.........
示例14: main
// Initialize GLUT & OpenSG and set up the scene
int main(int argc, char **argv)
{
// OSG init
OSG::osgInit(argc,argv);
// GLUT init
int winid = setupGLUT(&argc, argv);
// Args given?
if(argc > 1)
{
if(sscanf(argv[1], "%u", &nlights) != 1)
{
FWARNING(("Number of lights '%s' not understood.\n", argv[1]));
nlights = 3;
}
}
// open a new scope, because the pointers below should go out of scope
// before entering glutMainLoop.
// Otherwise OpenSG will complain about objects being alive after shutdown.
{
// the connection between GLUT and OpenSG
OSG::GLUTWindowRefPtr gwin = OSG::GLUTWindow::create();
gwin->setGlutId(winid);
gwin->init();
/*
A Light defines a source of light in the scene. Generally, two types
of information are of interest: The position of the light source
(geometry), and what elements of the scene are lit (semantics).
Using the position of the light in the graph for geometry allows
moving the Light just like any other node, by putting it below a
OSG::Transform Node and changing the transformation. This consistency
also simplifies attaching Lights to moving parts in the scene: just
put them below the same Transform and they will move with the object.
The semantic interpretation also makes sense, it lets you restrict the
influence area of the light to a subgraph of the scene. This can be
used for efficiency, as every active light increases the amount of
calculations necessary per vertex, even if the light doesn't influence
the vertex, because it is too far away. It can also be used to
overcome the restrictions on the number of lights. OpenSG currently
only allows 8 concurrently active lights.
It is also not difficult to imagine situations where both
interpretations are necessary at the same time. Take for example a car
driving through a night scene. You'd want to headlights to be fixed to
the car and move together with it. But at the same time they should
light the houses you're driving by, and not the mountains in the
distance.
Thus there should be a way to do both at the same time. OpenSG solves
this by splitting the two tasks to two Nodes. The Light's Node is for
the sematntic part, it defines which object are lit by the Light. FOr
the geometrc part the Light keeps a SFNodePtr to a different Node, the
so called beacon. The local coordinate system of the beacon provides
the reference coordinate system for the light's position.
Thus the typical setup of an OpenSG scenegraph starts with a set of
lights, which light the whole scene, followed by the actual geometry.
Tip: Using the beacon of the camera (see \ref PageSystemWindowCamera)
as the beacon of a light source creates a headlight.
Every light is closely related to OpenGL's light specification. It has
a diffuse, specular and ambient color. Additionally it can be switched
on and off using the on field.
*/
// Create the scene
OSG::NodeRefPtr scene = OSG::Node::create();
OSG::GroupRefPtr group = OSG::Group::create();
scene->setCore(group);
// create the scene to be lit
// a simple torus is fine for now.
// You can add more Geometry here if you want to.
OSG::NodeRefPtr lit_scene = OSG::makeTorus(.5, 2, 32, 64);
// helper node to keep the lights on top of each other
OSG::NodeRefPtr lastnode = lit_scene;
// create the light sources
OSG::Color3f colors[] =
{
OSG::Color3f(1,0,0), OSG::Color3f(0,1,0), OSG::Color3f(0,0,1),
OSG::Color3f(1,1,0), OSG::Color3f(0,1,1), OSG::Color3f(1,0,1),
OSG::Color3f(1,1,1), OSG::Color3f(1,1,1)
};
if(nlights > 8)
{
//.........这里部分代码省略.........
示例15: main
//
// Initialize GLUT & OpenSG and set up the scene
//
int main(int argc, char **argv)
{
// OSG init
OSG::osgInit(argc,argv);
// GLUT init
int winid = setupGLUT(&argc, argv);
// open a new scope, because the pointers below should go out of scope
// before entering glutMainLoop.
// Otherwise OpenSG will complain about objects being alive after shutdown.
{
// the connection between GLUT and OpenSG
OSG::GLUTWindowRefPtr gwin = OSG::GLUTWindow::create();
gwin->setGlutId(winid);
gwin->init();
// create the SimpleSceneManager helper
mgr = OSG::SimpleSceneManager::create();
mgr->setWindow(gwin);
// create a pretty simple graph: a Group with two Transforms as children,
// each of which carries a single Geometry.
// The scene
OSG::NodeRefPtr scene = OSG::Node::create();
// The cylinder and its transformation
OSG::NodeRefPtr cyl = OSG::Node::create();
OSG::GeometryRefPtr cylgeo = OSG::makeCylinderGeo( 1.4f, .3f, 24,
true, true, true );
cyl->setCore(cylgeo);
cyltrans = OSG::Transform::create();
OSG::NodeRefPtr cyltransnode = OSG::Node::create();
cyltransnode->setCore (cyltrans);
cyltransnode->addChild(cyl );
// add it to the scene
scene->addChild(cyltransnode);
// The torus and its transformation
OSG::NodeRefPtr torus = OSG::Node::create();
OSG::GeometryRefPtr torusgeo = OSG::makeTorusGeo( .2f, 1, 24, 36 );
torus->setCore(torusgeo);
tortrans = OSG::Transform::create();
OSG::NodeRefPtr tortransnode = OSG::Node::create();
tortransnode->setCore (tortrans);
tortransnode->addChild(torus );
// add it to the scene
scene->addChild(tortransnode);
//
// create the shader program
//
OSG::ShaderProgramChunkRefPtr prog_chunk = OSG::ShaderProgramChunk::create();
OSG::ShaderProgramRefPtr vertShader = OSG::ShaderProgram::createVertexShader();
OSG::ShaderProgramRefPtr fragShader = OSG::ShaderProgram::createFragmentShader();
vertShader->setProgram(get_vp_program());
fragShader->setProgram(get_fp_program());
//
// binding the shader storage block to a buffer binding point can be performed
// either by calling the shaders's addShaderStorageBlock method or by
// adding a 'buffer block' variable to a ShaderProgramVariableChunk.
// In the following we use both variants for illustration.
//
fragShader->addShaderStorageBlock("ExampleBlock", 1); // block binding point
prog_chunk->addShader(vertShader);
prog_chunk->addShader(fragShader);
//
// create shader storage buffer object for block 'ExampleBlock'
//
OSG::MultiPropertySSBOChunkRefPtr ssbo_example_block = create_example_block_state();
OSG::PolygonChunkRefPtr polygon_chunk = OSG::PolygonChunk::create();
polygon_chunk->setFrontMode(GL_FILL);
polygon_chunk->setBackMode(GL_FILL);
polygon_chunk->setCullFace(GL_NONE);
OSG::DepthChunkRefPtr depth_chunk = OSG::DepthChunk::create();
depth_chunk->setEnable(true);
OSG::ChunkMaterialRefPtr prog_state = OSG::ChunkMaterial::create();
prog_state->addChunk(ssbo_example_block, 1); // buffer binding point 1
prog_state->addChunk(prog_chunk);
prog_state->addChunk(polygon_chunk);
//.........这里部分代码省略.........