本文整理汇总了C++中osgInit函数的典型用法代码示例。如果您正苦于以下问题:C++ osgInit函数的具体用法?C++ osgInit怎么用?C++ osgInit使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了osgInit函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, char **argv)
{
// OSG init
osgInit(argc,argv);
{
// Set up Window
WindowEventProducerRecPtr TutorialWindow = createNativeWindow();
TutorialWindow->initWindow();
// Create the SimpleSceneManager helper
SimpleSceneManager sceneManager;
TutorialWindow->setDisplayCallback(boost::bind(display, &sceneManager));
TutorialWindow->setReshapeCallback(boost::bind(reshape, _1, &sceneManager));
// Tell the Manager what to manage
sceneManager.setWindow(TutorialWindow);
TutorialWindow->connectKeyTyped(boost::bind(keyPressed, _1));
// Make Torus Node (creates Torus in background of scene)
NodeRecPtr TorusGeometryNode = makeTorus(.5, 2, 16, 16);
// Make Main Scene Node and add the Torus
NodeRecPtr scene = Node::create();
scene->setCore(Group::create());
scene->addChild(TorusGeometryNode);
// Create the Graphics
GraphicsRecPtr TutorialGraphics = Graphics2D::create();
// Initialize the LookAndFeelManager to enable default settings
LookAndFeelManager::the()->getLookAndFeel()->init();
/******************************************************
Create BorderLayout and some
BorderLayoutConstraints to be used
to set up CardLayout.
******************************************************/
BorderLayoutRecPtr MainInternalWindowLayout = BorderLayout::create();
BorderLayoutConstraintsRecPtr ExampleButton1Constraints = BorderLayoutConstraints::create();
BorderLayoutConstraintsRecPtr ExampleButton2Constraints = BorderLayoutConstraints::create();
BorderLayoutConstraintsRecPtr ExampleButton7Constraints = BorderLayoutConstraints::create();
BorderLayoutConstraintsRecPtr ExampleButton8Constraints = BorderLayoutConstraints::create();
BorderLayoutConstraintsRecPtr ExampleCardPanelConstraints = BorderLayoutConstraints::create();
ExampleButton1Constraints->setRegion(BorderLayoutConstraints::BORDER_EAST);
ExampleButton2Constraints->setRegion(BorderLayoutConstraints::BORDER_WEST);
ExampleButton7Constraints->setRegion(BorderLayoutConstraints::BORDER_NORTH);
ExampleButton8Constraints->setRegion(BorderLayoutConstraints::BORDER_SOUTH);
ExampleCardPanelConstraints->setRegion(BorderLayoutConstraints::BORDER_CENTER);
/******************************************************
Create CardLayout. CardLayout shows
a single Component at a time, meaning
it is not exactly practical to use it
alone for a Layout. This tutorial uses
the BorderLayout to include a Panel in
the Center Region, and within that Panel
using a CardLayout. A single card is
displayed at one time within a
ComponentContainer using CardLayout.
CardLayout has four functions:
next, previous, first, and last.
->next(CardContainerName): Causes
CardLayout to display the next card.
->previous(CardContainerName): Causes
CardLayout to display the
previous card.
->first(CardContainerName): Causes
CardLayout to display the
first card.
->last(CardContainerName): Causes
CardLayout to display the
last card.
These are most useful when combined with
Action, as shown at the top of
this Tutorial, to assign actions to the
Buttons or Components to allow the user
to cycle through the Card Layout and
view different ExampleCards.
Note that CardContainerName is the name
of the ComponentContainer which is using the
CardLayout, while the begin/endEditCP
is performed on the CardLayout itself.
******************************************************/
//.........这里部分代码省略.........
示例2: main
int main (int argc, char **argv)
{
osgInit(argc,argv);
// GLUT init
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE);
int id=glutCreateWindow("OpenSG");
glutReshapeFunc(reshape);
glutDisplayFunc(display);
glutMouseFunc(mouse);
glutMotionFunc(motion);
glutKeyboardFunc(keyboard);
GLUTWindowPtr gwin=GLUTWindow::create();
gwin->setId(id);
gwin->init();
// create the scene
NodePtr scene = Node::create();
beginEditCP(scene);
scene->setCore(Group::create());
endEditCP(scene);
// create the SimpleSceneManager helper
_mgr = new SimpleSceneManager;
// tell the manager what to manage
_mgr->setWindow(gwin );
_mgr->setRoot (scene);
// create the geometry.
NodePtr plane = makePlane( 1, 1, 2, 2 );
NodePtr torus = makeTorus( .2, 1, 16, 8 );
GeometryPtr plane_geo, torus_geo;
plane_geo = GeometryPtr::dcast(plane->getCore());
torus_geo = GeometryPtr::dcast(torus->getCore());
PolygonChunkPtr pchunk = PolygonChunk::create();
beginEditCP(pchunk);
pchunk->setFrontMode(GL_LINE);
pchunk->setBackMode(GL_LINE);
pchunk->setOffsetFactor(-1.0);
pchunk->setOffsetLine(true);
endEditCP(pchunk);
// create materials for the plane.
SimpleMaterialPtr pm1 = SimpleMaterial::create();
beginEditCP(pm1);
pm1->setDiffuse( Color3f( 0,1,0 ) );
pm1->setAmbient( Color3f( 0,1,0 ) );
pm1->setSpecular( Color3f( 0,0,0 ) );
endEditCP(pm1);
SimpleMaterialPtr pm2 = SimpleMaterial::create();
beginEditCP(pm2);
pm2->setDiffuse( Color3f( 1,0,0 ) );
pm2->setAmbient( Color3f( 1,0,0 ) );
pm2->setSpecular( Color3f( 0,0,0 ) );
pm2->addChunk(pchunk);
endEditCP(pm2);
MultiPassMaterialPtr mppm = MultiPassMaterial::create();
beginEditCP(mppm);
mppm->addMaterial(pm1);
mppm->addMaterial(pm2);
endEditCP(mppm);
plane_geo->setMaterial(mppm);
// create materials for the torus.
SimpleMaterialPtr tm1 = SimpleMaterial::create();
beginEditCP(tm1);
tm1->setDiffuse( Color3f( 0,0,1 ) );
tm1->setAmbient( Color3f( 0,0,1 ) );
tm1->setTransparency(0.6);
endEditCP(tm1);
SimpleMaterialPtr tm2 = SimpleMaterial::create();
beginEditCP(tm2);
tm2->setDiffuse( Color3f( 1,0,0 ) );
tm2->setAmbient( Color3f( 1,0,0 ) );
tm2->setSpecular( Color3f( 0,0,0 ) );
tm2->addChunk(pchunk);
endEditCP(tm2);
MultiPassMaterialPtr mptm = MultiPassMaterial::create();
beginEditCP(mptm);
mptm->addMaterial(tm1);
mptm->addMaterial(tm2);
endEditCP(mptm);
torus_geo->setMaterial( mptm );
beginEditCP(scene);
scene->addChild(plane);
scene->addChild(torus);
//.........这里部分代码省略.........
示例3: main
int main(int argc, char **argv)
{
// OSG init
osgInit(argc,argv);
// Set up Window
TutorialWindow = createNativeWindow();
TutorialWindow->initWindow();
TutorialWindow->setDisplayCallback(display);
TutorialWindow->setReshapeCallback(reshape);
TutorialKeyListener TheKeyListener;
TutorialWindow->addKeyListener(&TheKeyListener);
// Make Torus Node (creates Torus in background of scene)
NodeRefPtr TorusGeometryNode = makeTorus(.5, 2, 16, 16);
// Make Main Scene Node and add the Torus
NodeRefPtr scene = OSG::Node::create();
scene->setCore(OSG::Group::create());
scene->addChild(TorusGeometryNode);
// Create the Graphics
GraphicsRefPtr TutorialGraphics = OSG::Graphics2D::create();
// Initialize the LookAndFeelManager to enable default settings
LookAndFeelManager::the()->getLookAndFeel()->init();
//Background
TutorialBackground = GradientBackground::create();
TutorialBackground->addLine(Color3f(1.0,0.0,0.0), 0.0);
TutorialBackground->addLine(Color3f(0.0,1.0,0.0), 0.2);
TutorialBackground->addLine(Color3f(0.0,0.0,1.0), 0.4);
TutorialBackground->addLine(Color3f(0.0,1.0,1.0), 0.6);
TutorialBackground->addLine(Color3f(1.0,1.0,0.0), 0.8);
TutorialBackground->addLine(Color3f(1.0,1.0,1.0), 1.0);
TheUndoManager = UndoManager::create();
UndoManagerChangeListener TheUndoManagerChangeListener;
TheUndoManager->addChangeListener(&TheUndoManagerChangeListener);
LabelRefPtr SingleFieldLabel = OSG::Label::create();
SingleFieldLabel->setText("Single Field");
SingleFieldLabel->setBorders(NULL);
SingleFieldLabel->setBackgrounds(NULL);
LabelRefPtr MultiFieldLabel = OSG::Label::create();
MultiFieldLabel->setText("Multi Field");
MultiFieldLabel->setBorders(NULL);
MultiFieldLabel->setBackgrounds(NULL);
LabelRefPtr SinglePtrFieldLabel = OSG::Label::create();
SinglePtrFieldLabel->setText("Single Ptr Field");
SinglePtrFieldLabel->setBorders(NULL);
SinglePtrFieldLabel->setBackgrounds(NULL);
LabelRefPtr MultiPtrFieldLabel = OSG::Label::create();
MultiPtrFieldLabel->setText("Multi Ptr Field");
MultiPtrFieldLabel->setBorders(NULL);
MultiPtrFieldLabel->setBackgrounds(NULL);
TabPanelRefPtr ExampleTabPanel = OSG::TabPanel::create();
ExampleTabPanel->setPreferredSize(Vec2f(600,600));
ExampleTabPanel->addTab(SingleFieldLabel, createSingleFieldPanel());
ExampleTabPanel->addTab(MultiFieldLabel, createMultiFieldPanel());
ExampleTabPanel->addTab(SinglePtrFieldLabel, createSinglePtrFieldPanel());
ExampleTabPanel->addTab(MultiPtrFieldLabel, createMultiPtrFieldPanel());
ExampleTabPanel->setTabAlignment(0.5f);
ExampleTabPanel->setTabPlacement(TabPanel::PLACEMENT_NORTH);
ExampleTabPanel->setSelectedIndex(0);
//UndoList
UndoRedoListModel = DefaultListModel::create();
UndoRedoListModel->pushBack(boost::any(std::string("Top")));
ListSelectionModelPtr UndoRedoListSelectionModel(new DefaultListSelectionModel());
UndoRedoList = List::create();
UndoRedoList->setPreferredSize(Vec2f(200, 300));
UndoRedoList->setOrientation(List::VERTICAL_ORIENTATION);
UndoRedoList->setModel(UndoRedoListModel);
UndoRedoList->setSelectionModel(UndoRedoListSelectionModel);
UndoRedoListListener TheUndoRedoListListener;
UndoRedoList->getSelectionModel()->addListSelectionListener(&TheUndoRedoListListener);
UndoButton = OSG::Button::create();
UndoButton->setText("Undo");
UndoButton->setEnabled(TheUndoManager->numberOfUndos() != 0);
UndoButtonActionListener TheUndoButtonActionListener;
UndoButton->addActionListener(&TheUndoButtonActionListener);
RedoButton = OSG::Button::create();
RedoButton->setText("Redo");
RedoButton->setEnabled(TheUndoManager->numberOfRedos() != 0);
RedoButtonActionListener TheRedoButtonActionListener;
RedoButton->addActionListener(&TheRedoButtonActionListener);
//.........这里部分代码省略.........
示例4: main
int main(int argc, char **argv)
{
// OSG init
osgInit(argc,argv);
// Set up Window
TutorialWindow = createNativeWindow();
TutorialWindow->initWindow();
TutorialWindow->setDisplayCallback(display);
TutorialWindow->setReshapeCallback(reshape);
TutorialKeyListener TheKeyListener;
TutorialWindow->addKeyListener(&TheKeyListener);
// Make Torus Node (creates Torus in background of scene)
NodeRefPtr TorusGeometryNode = makeTorus(.5, 2, 16, 16);
// Make Main Scene Node and add the Torus
NodeRefPtr scene = OSG::Node::create();
scene->setCore(OSG::Group::create());
scene->addChild(TorusGeometryNode);
// Create the Graphics
GraphicsRefPtr TutorialGraphics = OSG::Graphics2D::create();
// Initialize the LookAndFeelManager to enable default settings
LookAndFeelManager::the()->getLookAndFeel()->init();
/******************************************************
Create an Button Component and
a simple Font.
See 17Label_Font for more
information about Fonts.
******************************************************/
ButtonRefPtr ExampleButton = OSG::Button::create();
UIFontRefPtr ExampleFont = OSG::UIFont::create();
ExampleFont->setSize(16);
ExampleButton->setMinSize(Vec2f(50, 25));
ExampleButton->setMaxSize(Vec2f(200, 100));
ExampleButton->setPreferredSize(Vec2f(100, 50));
ExampleButton->setToolTipText("Button 1 ToolTip");
ExampleButton->setText("Button 1");
ExampleButton->setFont(ExampleFont);
ExampleButton->setTextColor(Color4f(1.0, 0.0, 0.0, 1.0));
ExampleButton->setRolloverTextColor(Color4f(1.0, 0.0, 1.0, 1.0));
ExampleButton->setActiveTextColor(Color4f(1.0, 0.0, 0.0, 1.0));
ExampleButton->setAlignment(Vec2f(1.0,0.0));
/******************************************************
Create a ToggleButton and determine its
characteristics. ToggleButton inherits
off of Button, so all characteristsics
used above can be used with ToggleButtons
as well.
The only difference is that when pressed,
ToggleButton remains pressed until pressed
again.
-setSelected(bool): Determine whether the
ToggleButton is Selected (true) or
deselected (false).
******************************************************/
ToggleButtonRefPtr ExampleToggleButton = OSG::ToggleButton::create();
ExampleToggleButton->setSelected(false);
ExampleToggleButton->setText("ToggleMe");
ExampleToggleButton->setToolTipText("Toggle Button ToolTip");
// Create Background to be used with the MainInternalWindow
ColorLayerRefPtr MainInternalWindowBackground = OSG::ColorLayer::create();
MainInternalWindowBackground->setColor(Color4f(1.0,1.0,1.0,0.5));
// Create The Internal Window
InternalWindowRefPtr MainInternalWindow = OSG::InternalWindow::create();
LayoutRefPtr MainInternalWindowLayout = OSG::FlowLayout::create();
// Assign the Button to the MainInternalWindow so it will be displayed
// when the view is rendered.
MainInternalWindow->pushToChildren(ExampleButton);
MainInternalWindow->setLayout(MainInternalWindowLayout);
MainInternalWindow->setBackgrounds(MainInternalWindowBackground);
MainInternalWindow->setPosition(Pnt2f(50,50));
MainInternalWindow->setPreferredSize(Vec2f(300,300));
MainInternalWindow->setTitle(std::string("Internal Window 1"));
// Create The Internal Window
InternalWindowRefPtr MainInternalWindow2 = OSG::InternalWindow::create();
LayoutRefPtr MainInternalWindowLayout2 = OSG::FlowLayout::create();
// Assign the Button to the MainInternalWindow so it will be displayed
// when the view is rendered.
//.........这里部分代码省略.........
示例5: main
int main(int argc, char **argv)
{
// OSG init
osgInit(argc,argv);
{
// Set up Window
WindowEventProducerRecPtr TutorialWindow = createNativeWindow();
TutorialWindow->initWindow();
// Create the SimpleSceneManager helper
SimpleSceneManager sceneManager;
TutorialWindow->setDisplayCallback(boost::bind(display, &sceneManager));
TutorialWindow->setReshapeCallback(boost::bind(reshape, _1, &sceneManager));
// Tell the Manager what to manage
sceneManager.setWindow(TutorialWindow);
//Attach to events
TutorialWindow->connectMousePressed(boost::bind(mousePressed, _1, &sceneManager));
TutorialWindow->connectMouseReleased(boost::bind(mouseReleased, _1, &sceneManager));
TutorialWindow->connectMouseMoved(boost::bind(mouseMoved, _1, &sceneManager));
TutorialWindow->connectMouseDragged(boost::bind(mouseDragged, _1, &sceneManager));
// Material blend chunk
BlendChunkRefPtr PSBlendChunk = BlendChunk::create();
PSBlendChunk->setSrcFactor(GL_SRC_ALPHA);
PSBlendChunk->setDestFactor(GL_ONE_MINUS_SRC_ALPHA);
//load up images for PS drawer
ImageRefPtr rocket = ImageFileHandler::the()->read("Data/rocket.png");
ImageRefPtr smoke = ImageFileHandler::the()->read("Data/Smokey.png");
//Texture Chunk
TextureObjChunkRefPtr PSRocketTexChunk = TextureObjChunk::create();
PSRocketTexChunk->setImage(rocket);
TextureEnvChunkRefPtr PSRocketTexEnvChunk = TextureEnvChunk::create();
PSRocketTexEnvChunk->setEnvMode(GL_MODULATE);
TextureObjChunkRefPtr SmokeTexChunk = TextureObjChunk::create();
SmokeTexChunk->setImage(smoke);
TextureEnvChunkRefPtr SmokeTexEnvChunk = TextureEnvChunk::create();
SmokeTexEnvChunk->setEnvMode(GL_MODULATE);
//Particle System Material
MaterialChunkRefPtr PSMaterialChunkChunk = MaterialChunk::create();
PSMaterialChunkChunk->setAmbient(Color4f(1.0f,0.5f,0.3f,1.0f));
PSMaterialChunkChunk->setDiffuse(Color4f(1.0f,0.5f,0.3f,0.6f));
PSMaterialChunkChunk->setSpecular(Color4f(1.0f,0.5f,0.3f,0.6f));
PSMaterialChunkChunk->setColorMaterial(GL_AMBIENT_AND_DIFFUSE);
// Assembling materials
ChunkMaterialRefPtr PSMaterial = ChunkMaterial::create();
PSMaterial->addChunk(PSMaterialChunkChunk);
PSMaterial->addChunk(PSBlendChunk);
PSMaterial->addChunk(PSRocketTexChunk);
ChunkMaterialRefPtr TrailMaterial = ChunkMaterial::create();
TrailMaterial->addChunk(PSMaterialChunkChunk);
TrailMaterial->addChunk(PSBlendChunk);
TrailMaterial->addChunk(SmokeTexChunk);
AgeFadeParticleAffectorRefPtr AgeFadeAffector = AgeFadeParticleAffector::create();
AgeFadeAffector->setFadeInTime(0.0f);
AgeFadeAffector->setStartAlpha(1.0f);
AgeFadeAffector->setEndAlpha(0.0f);
AgeFadeAffector->setFadeOutTime(0.35f);
AgeFadeAffector->setFadeToAlpha(1.0f);
// Creating a particle generator
RateParticleGeneratorRefPtr ExampleGenerator = RateParticleGenerator::create();
//Attach the function objects to the Generator
ExampleGenerator->setPositionDistribution(createPositionDistribution());
ExampleGenerator->setGenerationRate(3.0);
ExampleGenerator->setVelocityDistribution(createVelocityDistribution());
ExampleGenerator->setNormalDistribution(createNormalDistribution());
ExampleGenerator->setLifespanDistribution(createLifespanDistribution());
ExampleGenerator->setSizeDistribution(createSizeDistribution());
//Creating Particle System
ParticleSystemRecPtr ExampleParticleSystem = ParticleSystem::create();
ExampleParticleSystem->addParticle(Pnt3f(0,0,-100),Vec3f(0,1,0),Color4f(1,1,1,1),Vec3f(1,1,1),0.1,Vec3f(0,0,0),Vec3f(0,0,0));
ExampleParticleSystem->addParticle(Pnt3f(0,0,100),Vec3f(0,1,0),Color4f(1,1,1,1),Vec3f(1,1,1),0.1,Vec3f(0,0,0),Vec3f(0,0,0));
ExampleParticleSystem->setMaxParticles(5); // 5 rockets max to avoid collisions. they are bad.
ExampleParticleSystem->pushToAffectors(AgeFadeAffector);
ExampleParticleSystem->attachUpdateProducer(TutorialWindow);
//Creating Particle System Drawer
QuadParticleSystemDrawerRefPtr ExampleParticleSystemDrawer = QuadParticleSystemDrawer::create();
ExampleParticleSystemDrawer->setNormalAndUpSource(QuadParticleSystemDrawer::NORMAL_VIEW_DIRECTION,
QuadParticleSystemDrawer::UP_VELOCITY);
QuadParticleSystemDrawerRefPtr ExampleTrailDrawer = QuadParticleSystemDrawer::create();
ExampleTrailDrawer->setNormalAndUpSource(QuadParticleSystemDrawer::NORMAL_VIEW_DIRECTION,
QuadParticleSystemDrawer::UP_PARTICLE_NORMAL);
//.........这里部分代码省略.........
示例6: main
// Initialize OpenSG and set up the scene
int main(int argc, char **argv)
{
//Set the number of aspects
ThreadManager::setNumAspects(2);
ChangeList::setReadWriteDefault(true);
// OSG init
osgInit(argc,argv);
{
// Set up Window
TutorialWindow = createNativeWindow();
TutorialWindow->setUseCallbackForDraw(true);
TutorialWindow->setUseCallbackForReshape(true);
//Initialize Window
TutorialWindow->initWindow();
// Create the SimpleSceneManager helper
SimpleSceneManager sceneManager;
TutorialWindow->setDisplayCallback(boost::bind(display, &sceneManager));
TutorialWindow->setReshapeCallback(boost::bind(reshape, _1, &sceneManager));
// Tell the Manager what to manage
sceneManager.setWindow(TutorialWindow);
//Attach to events
TutorialWindow->connectMousePressed(boost::bind(mousePressed, _1, &sceneManager));
TutorialWindow->connectMouseReleased(boost::bind(mouseReleased, _1, &sceneManager));
TutorialWindow->connectMouseMoved(boost::bind(mouseMoved, _1, &sceneManager));
TutorialWindow->connectMouseDragged(boost::bind(mouseDragged, _1, &sceneManager));
//Torus Material
MaterialRecPtr TheTorusMaterial = SimpleMaterial::create();
dynamic_pointer_cast<SimpleMaterial>(TheTorusMaterial)->setAmbient(Color3f(0.2,0.2,0.2));
dynamic_pointer_cast<SimpleMaterial>(TheTorusMaterial)->setDiffuse(Color3f(0.7,0.7,0.7));
dynamic_pointer_cast<SimpleMaterial>(TheTorusMaterial)->setSpecular(Color3f(0.7,0.7,0.7));
dynamic_pointer_cast<SimpleMaterial>(TheTorusMaterial)->setShininess(100.0f);
//Torus Geometry
GeometryRecPtr TorusGeometry = makeTorusGeo(.5, 2, 32, 32);
TorusGeometry->setMaterial(TheTorusMaterial);
NodeRecPtr TorusGeometryNode = Node::create();
TorusGeometryNode->setCore(TorusGeometry);
//Make Torus Node
NodeRecPtr TorusNode = Node::create();
TransformRecPtr TorusNodeTrans = Transform::create();
setName(TorusNodeTrans, std::string("TorusNodeTransformationCore"));
TorusNode->setCore(TorusNodeTrans);
TorusNode->addChild(TorusGeometryNode);
//Make Main Scene Node
NodeRecPtr scene = Node::create();
ComponentTransformRecPtr Trans = ComponentTransform::create();
setName(Trans, std::string("MainTransformationCore"));
scene->setCore(Trans);
scene->addChild(TorusNode);
AnimationRecPtr TheAnimation = setupAnimation(TorusNodeTrans, TutorialWindow);
TutorialWindow->connectKeyPressed(boost::bind(keyPressed, _1, TheAnimation.get(), TutorialWindow.get()));
TheAnimation->connectAnimationStarted(boost::bind(animationStarted, _1));
TheAnimation->connectAnimationStopped(boost::bind(animationStopped, _1));
TheAnimation->connectAnimationPaused(boost::bind(animationPaused, _1));
TheAnimation->connectAnimationUnpaused(boost::bind(animationUnpaused, _1));
TheAnimation->connectAnimationEnded(boost::bind(animationEnded, _1));
TheAnimation->connectAnimationCycled(boost::bind(animationCycled, _1));
commitChanges();
// tell the manager what to manage
sceneManager.setRoot (scene);
// show the whole scene
sceneManager.showAll();
Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f);
Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5);
TutorialWindow->openWindow(WinPos,
WinSize,
"OpenSG 01Animation Window");
// store a pointer to the application thread
ApplicationThread = dynamic_cast<OSG::Thread *>(OSG::ThreadManager::getAppThread());
//create the thread that will run generation of new matrices
RenderThread =
OSG::dynamic_pointer_cast<OSG::Thread>(
OSG::ThreadManager::the()->getThread("render", true));
//Start the render thread on aspect 1
RenderThread->runFunction(draw, 1, static_cast<void *>(&sceneManager));
//.........这里部分代码省略.........
示例7: main
int main(int argc, char **argv)
{
preloadSharedObject("OSGImageFileIO");
// OSG init
osgInit(argc,argv);
{
// Set up Window
WindowEventProducerRecPtr TutorialWindow = createNativeWindow();
TutorialWindow->initWindow();
// Create the SimpleSceneManager helper
SimpleSceneManager sceneManager;
TutorialWindow->setDisplayCallback(boost::bind(display, &sceneManager));
TutorialWindow->setReshapeCallback(boost::bind(reshape, _1, &sceneManager));
// Tell the Manager what to manage
sceneManager.setWindow(TutorialWindow);
//Attach to events
TutorialWindow->connectMouseReleased(boost::bind(mouseReleased, _1, &sceneManager));
TutorialWindow->connectMouseDragged(boost::bind(mouseDragged, _1, &sceneManager));
TutorialWindow->connectMouseWheelMoved(boost::bind(mouseWheelMoved, _1, &sceneManager));
TutorialWindow->connectKeyTyped(boost::bind(keyTyped, _1, &sceneManager));
//Particle System Material
//point material
PointChunkRefPtr PSPointChunk = PointChunk::create();
PSPointChunk->setSize(5.0f);
PSPointChunk->setSmooth(true);
BlendChunkRefPtr PSBlendChunk = BlendChunk::create();
PSBlendChunk->setSrcFactor(GL_SRC_ALPHA);
PSBlendChunk->setDestFactor(GL_ONE_MINUS_SRC_ALPHA);
MaterialChunkRefPtr PSMaterialChunkChunk = MaterialChunk::create();
PSMaterialChunkChunk->setAmbient(Color4f(0.3f,0.3f,0.3f,1.0f));
PSMaterialChunkChunk->setDiffuse(Color4f(0.7f,0.7f,0.7f,1.0f));
PSMaterialChunkChunk->setSpecular(Color4f(0.9f,0.9f,0.9f,1.0f));
PSMaterialChunkChunk->setColorMaterial(GL_AMBIENT_AND_DIFFUSE);
ChunkMaterialRefPtr PSPointMaterial = ChunkMaterial::create();
PSPointMaterial->addChunk(PSPointChunk);
PSPointMaterial->addChunk(PSMaterialChunkChunk);
PSPointMaterial->addChunk(PSBlendChunk);
//smoke material
TextureObjChunkRefPtr QuadTextureObjChunk = TextureObjChunk::create();
ImageRefPtr LoadedImage = ImageFileHandler::the()->read("Data/Smoke.png");
QuadTextureObjChunk->setImage(LoadedImage);
TextureEnvChunkRefPtr QuadTextureEnvChunk = TextureEnvChunk::create();
QuadTextureEnvChunk->setEnvMode(GL_MODULATE);
MaterialChunkRefPtr PSMaterialChunk = MaterialChunk::create();
PSMaterialChunk->setAmbient(Color4f(0.3f,0.3f,0.3f,1.0f));
PSMaterialChunk->setDiffuse(Color4f(0.7f,0.7f,0.7f,1.0f));
PSMaterialChunk->setSpecular(Color4f(0.9f,0.9f,0.9f,1.0f));
PSMaterialChunk->setColorMaterial(GL_AMBIENT_AND_DIFFUSE);
ChunkMaterialRefPtr PSSmokeMaterial = ChunkMaterial::create();
PSSmokeMaterial->addChunk(QuadTextureObjChunk);
PSSmokeMaterial->addChunk(PSMaterialChunk);
PSSmokeMaterial->addChunk(PSBlendChunk);
PSSmokeMaterial->addChunk(QuadTextureEnvChunk);
//Particle System
//Rocket
ParticleSystemRecPtr RocketParticleSystem = ParticleSystem::create();
RocketParticleSystem->attachUpdateProducer(TutorialWindow);
//smoke
ParticleSystemRecPtr SmokeParticleSystem = ParticleSystem::create();
SmokeParticleSystem->attachUpdateProducer(TutorialWindow);
//Shrapnel
ParticleSystemRecPtr ShrapnelParticleSystem = ParticleSystem::create();
ShrapnelParticleSystem->attachUpdateProducer(TutorialWindow);
//Fireball
ParticleSystemRecPtr FireballParticleSystem = ParticleSystem::create();
FireballParticleSystem->attachUpdateProducer(TutorialWindow);
//Particle System Drawer
//Rocket does not have a drawer because it is being attached to a special node core
//Smoke
QuadParticleSystemDrawerRecPtr SmokeParticleSystemDrawer = QuadParticleSystemDrawer::create();
//SmokeParticleSystemDrawer->setQuadSizeScaling(Vec2f(0.5f,0.5f));
//Shrapnel
PointParticleSystemDrawerRecPtr ExampleShrapnelParticleSystemDrawer = PointParticleSystemDrawer::create();
ExampleShrapnelParticleSystemDrawer->setForcePerParticleSizing(true);
//Fireball
PointParticleSystemDrawerRecPtr ExampleFireballParticleSystemDrawer = PointParticleSystemDrawer::create();
ExampleFireballParticleSystemDrawer->setForcePerParticleSizing(true);
//Particle System Node
//collision node
//NodeRefPtr EnvironmentNode = makeSphere(2,4.0f);
//.........这里部分代码省略.........
示例8: main
// Initialize GLUT & OpenSG and set up the scene
int main(int argc, char **argv)
{
// OSG init
osgInit(argc,argv);
// GLUT init
int winid = setupGLUT(&argc, argv);
// the connection between GLUT and OpenSG
GLUTWindowPtr gwin= GLUTWindow::create();
gwin->setId(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 the single indexed geometry...
*/
GeoPTypesPtr type = GeoPTypesUI8::create();
beginEditCP(type, GeoPTypesUI8::GeoPropDataFieldMask);
{
type->push_back(GL_POLYGON );
type->push_back(GL_TRIANGLES);
type->push_back(GL_QUADS );
}
endEditCP (type, GeoPTypesUI8::GeoPropDataFieldMask);
GeoPLengthsPtr lens = GeoPLengthsUI32::create();
beginEditCP(lens, GeoPLengthsUI32::GeoPropDataFieldMask);
{
lens->push_back(4);
lens->push_back(6);
lens->push_back(8);
}
endEditCP (lens, GeoPLengthsUI32::GeoPropDataFieldMask);
GeoPositions3fPtr pnts = GeoPositions3f::create();
beginEditCP(pnts, GeoPositions3f::GeoPropDataFieldMask);
{
// the base
pnts->push_back(Pnt3f(-1, -1, -1));
pnts->push_back(Pnt3f(-1, -1, 1));
pnts->push_back(Pnt3f( 1, -1, 1));
pnts->push_back(Pnt3f( 1, -1, -1));
// the roof base
pnts->push_back(Pnt3f(-1, 0, -1));
pnts->push_back(Pnt3f(-1, 0, 1));
pnts->push_back(Pnt3f( 1, 0, 1));
pnts->push_back(Pnt3f( 1, 0, -1));
// the gable
pnts->push_back(Pnt3f( 0, 1, -1));
pnts->push_back(Pnt3f( 0, 1, 1));
}
endEditCP (pnts, GeoPositions3f::GeoPropDataFieldMask);
GeoColors3fPtr colors = GeoColors3f::create();
beginEditCP(colors, GeoColors3f::GeoPropDataFieldMask);
{
colors->push_back(Color3f(1, 1, 0));
colors->push_back(Color3f(1, 0, 0));
colors->push_back(Color3f(1, 0, 0));
colors->push_back(Color3f(1, 1, 0));
colors->push_back(Color3f(0, 1, 1));
colors->push_back(Color3f(1, 0, 1));
}
endEditCP (colors, GeoPositions3f::GeoPropDataFieldMask);
/*
A new property: normals.
They are used for lighting calculations and have to point away from the
surface. Normals are standard vectors.
*/
GeoNormals3fPtr norms = GeoNormals3f::create();
beginEditCP(norms, GeoNormals3f::GeoPropDataFieldMask);
{
norms->push_back(Vec3f(-1, 0, 0));
norms->push_back(Vec3f( 1, 0, 0));
norms->push_back(Vec3f( 0, -1, 0));
norms->push_back(Vec3f( 0, 1, 0));
norms->push_back(Vec3f( 0, 0, -1));
norms->push_back(Vec3f( 0, 0, 1));
}
endEditCP (norms, GeoNormals3f::GeoPropDataFieldMask);
/*
To use different indices for different attributes they have to be
//.........这里部分代码省略.........
示例9: main
int main(int argc, char **argv)
{
// OSG init
osgInit(argc,argv);
{
// Set up Window
WindowEventProducerRecPtr TutorialWindow = createNativeWindow();
TutorialWindow->initWindow();
// Create the SimpleSceneManager helper
SimpleSceneManager sceneManager;
TutorialWindow->setDisplayCallback(boost::bind(display, &sceneManager));
TutorialWindow->setReshapeCallback(boost::bind(reshape, _1, &sceneManager));
// Tell the Manager what to manage
sceneManager.setWindow(TutorialWindow);
TutorialWindow->connectKeyTyped(boost::bind(keyPressed, _1));
// Make Torus Node (creates Torus in background of scene)
NodeRecPtr TorusGeometryNode = makeTorus(.5, 2, 16, 16);
// Make Main Scene Node and add the Torus
NodeRecPtr scene = Node::create();
scene->setCore(Group::create());
scene->addChild(TorusGeometryNode);
// Create the Graphics
GraphicsRecPtr TutorialGraphics = Graphics2D::create();
// Initialize the LookAndFeelManager to enable default settings
LookAndFeelManager::the()->getLookAndFeel()->init();
/******************************************************
Create a Panel containing Buttons to
add to ScrollPanel using a function
(located at bottom of this file)
******************************************************/
PanelRecPtr ExampleViewablePanel = createPanelWithButtons();
/******************************************************
Create a UIViewport to use with the
ScrollPanel. This sets up a secondary
TutorialViewport inside the ScrollPanel.
Without this, the ScrollPanel would
not function correctly.
The Panel created above is added to be
viewed in the UIViewport and the size
and position are set.
******************************************************/
UIViewportRecPtr ScrollPanelUIViewport = UIViewport::create();
ScrollPanelUIViewport->setViewComponent(ExampleViewablePanel);
ScrollPanelUIViewport->setViewPosition(Pnt2f(150,150));
ScrollPanelUIViewport->setPreferredSize(Vec2f(200,200));
/******************************************************
Create the ScrollPanel itself.
-setHorizontalResizePolicy(ScrollPanel::
ENUM): Determines the Horizontal
resize policy. The ScrollPanel will
automatically resize itself to the
Size of its Component within for
RESIZE_TO_VIEW, or add a ScrollBar
as needed for NO_RESIZE. Takes
NO_RESIZE and RESIZE_TO_VIEW
arguments.
-setVerticalResizePolicy(ScrollPanel::
ENUM): Determines the Vertical
resize policy. The ScrollPanel will
automatically resize itself to the
Size of its Component within for
RESIZE_TO_VIEW, or add a ScrollBar
as needed for NO_RESIZE. Takes
NO_RESIZE and RESIZE_TO_VIEW
arguments.
-setViewComponent(Component): Determine
which Component will be added into
the ScrollPanel. Note that this
must be the same as the UIViewport
created above and does not require
a begin/endEditCP.
******************************************************/
ScrollPanelRecPtr ExampleScrollPanel = ScrollPanel::create();
ExampleScrollPanel->setPreferredSize(Vec2f(100,100));
ExampleScrollPanel->setVerticalScrollBarAlignment(ScrollPanel::SCROLLBAR_ALIGN_LEFT);
ExampleScrollPanel->setHorizontalScrollBarAlignment(ScrollPanel::SCROLLBAR_ALIGN_BOTTOM);
//ExampleScrollPanel->setHorizontalResizePolicy(ScrollPanel::RESIZE_TO_VIEW);
//ExampleScrollPanel->setVerticalResizePolicy(ScrollPanel::RESIZE_TO_VIEW);
//.........这里部分代码省略.........
示例10: main
int main(int argc, char **argv)
{
// OSG init
osgInit(argc,argv);
// Set up Window
TutorialWindow = createNativeWindow();
TutorialWindow->initWindow();
TutorialWindow->setDisplayCallback(display);
TutorialWindow->setReshapeCallback(reshape);
TutorialKeyListener TheKeyListener;
TutorialWindow->addKeyListener(&TheKeyListener);
// Make Torus Node (creates Torus in background of scene)
NodeRefPtr TorusGeometryNode = makeTorus(.5, 2, 16, 16);
// Make Main Scene Node and add the Torus
NodeRefPtr scene = OSG::Node::create();
scene->setCore(OSG::Group::create());
scene->addChild(TorusGeometryNode);
// Create the Graphics
GraphicsRefPtr TutorialGraphics = OSG::Graphics2D::create();
// Initialize the LookAndFeelManager to enable default settings
LookAndFeelManager::the()->getLookAndFeel()->init();
// Create a simple Font to be used with the TextField
UIFontRefPtr sampleFont = OSG::UIFont::create();
sampleFont->setSize(16);
/******************************************************
Create and edit the TextField. A TextField is
a Component which allows a single line of text
to be displayed. Text can be entered via the
keyboard, and selected with arrow keys or
the Mouse.
-setTextColor(Color4f): Determine the
Text Color.
setSelectionBoxColor(Color4f): Determine
the Color of highlighting around
selected Text.
-setSelectionTextColor(Color4f): Determine
the Color of selected Text.
-setText("TextToBeDisplayed"): Determine
initial Text within TextField.
-setFont(FontName): Determine the Font
used within TextField.
-setSelectionStart(StartCharacterNumber):
Determine the character with which
the selection will initially start.
-setSelectionEnd(EndCharacterNumber):
Determine the character which the
selection ends before.
-setAlignment(float): Determine
the alignment of the text.
The float is a percentage is from the
top of the text [0.0-1.0]. Note: be
sure to visually verify this, as due
to font size and line size this does
not always place it exactly
at the percentage point.
******************************************************/
// Create a TextField component
TextFieldRefPtr ExampleTextField = OSG::TextField::create();
ExampleTextField->setPreferredSize(Vec2f(100, 50));
ExampleTextField->setTextColor(Color4f(0.0, 0.0, 0.0, 1.0));
ExampleTextField->setSelectionBoxColor(Color4f(0.0, 0.0, 1.0, 1.0));
ExampleTextField->setSelectionTextColor(Color4f(1.0, 1.0, 1.0, 1.0));
ExampleTextField->setText("What");
ExampleTextField->setFont(sampleFont);
// The next two functions will select the "a" from above
ExampleTextField->setSelectionStart(2);
ExampleTextField->setSelectionEnd(3);
ExampleTextField->setAlignment(Vec2f(0.0,0.5));
// Create another TextField Component
TextFieldRefPtr ExampleTextField2 = OSG::TextField::create();
ExampleTextField2->setText("");
ExampleTextField2->setEmptyDescText("Write in me, please");
ExampleTextField2->setPreferredSize(Vec2f(200.0f,ExampleTextField2->getPreferredSize().y()));
// Create The Main InternalWindow
// Create Background to be used with the Main InternalWindow
ColorLayerRefPtr MainInternalWindowBackground = OSG::ColorLayer::create();
MainInternalWindowBackground->setColor(Color4f(1.0,1.0,1.0,0.5));
LayoutRefPtr MainInternalWindowLayout = OSG::FlowLayout::create();
InternalWindowRefPtr MainInternalWindow = OSG::InternalWindow::create();
MainInternalWindow->pushToChildren(ExampleTextField);
//.........这里部分代码省略.........
示例11: main
// Initialize GLUT & OpenSG and set up the scene
int main(int argc, char **argv)
{
// OSG init
osgInit(argc,argv);
{
// Set up Window
WindowEventProducerRecPtr TutorialWindow = createNativeWindow();
//Initialize Window
TutorialWindow->initWindow();
SimpleSceneManager sceneManager;
TutorialWindow->setDisplayCallback(boost::bind(display, &sceneManager));
TutorialWindow->setReshapeCallback(boost::bind(reshape, _1, &sceneManager));
// Tell the Manager what to manage
sceneManager.setWindow(TutorialWindow);
//Attach to events
TutorialWindow->connectMousePressed(boost::bind(mousePressed, _1, &sceneManager));
TutorialWindow->connectMouseReleased(boost::bind(mouseReleased, _1, &sceneManager));
TutorialWindow->connectMouseDragged(boost::bind(mouseDragged, _1, &sceneManager));
TutorialWindow->connectMouseWheelMoved(boost::bind(mouseWheelMoved, _1, &sceneManager));
//Torus Material
SimpleMaterialUnrecPtr TheTorusMaterial = SimpleMaterial::create();
TheTorusMaterial->setAmbient(Color3f(0.3,0.3,0.3));
TheTorusMaterial->setDiffuse(Color3f(0.7,0.7,0.7));
TheTorusMaterial->setSpecular(Color3f(1.0,1.0,1.0));
TheTorusMaterial->setShininess(20.0);
//Torus Geometry
GeometryUnrecPtr TorusGeometry = makeTorusGeo(.5, 2, 32, 32);
TorusGeometry->setMaterial(TheTorusMaterial);
NodeUnrecPtr TorusGeometryNode = Node::create();
TorusGeometryNode->setCore(TorusGeometry);
//Make Torus Node
NodeUnrecPtr TorusNode = Node::create();
TransformUnrecPtr TorusNodeTrans = Transform::create();
setName(TorusNodeTrans, std::string("TorusNodeTransformationCore"));
TorusNode->setCore(TorusNodeTrans);
TorusNode->addChild(TorusGeometryNode);
//Make Main Scene Node
NodeUnrecPtr scene = Node::create();
ComponentTransformUnrecPtr Trans = ComponentTransform::create();
setName(Trans, std::string("MainTransformationCore"));
scene->setCore(Trans);
// add the torus as a child
scene->addChild(TorusNode);
AnimationGroupUnrecPtr TheAnimation = setupAnimation(TheTorusMaterial, TorusNodeTrans);
TutorialWindow->connectKeyPressed(boost::bind(keyPressed, _1,
TheAnimation.get(),
TutorialWindow.get()));
TheAnimation->attachUpdateProducer(TutorialWindow);
TheAnimation->start();
// tell the manager what to manage
sceneManager.setRoot (scene);
//Create the Documentation
SimpleScreenDoc TheSimpleScreenDoc(&sceneManager, TutorialWindow);
// show the whole scene
sceneManager.showAll();
Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f);
Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5);
TutorialWindow->openWindow(WinPos,
WinSize,
"07AnimationGroup");
//Enter main Loop
TutorialWindow->mainLoop();
}
osgExit();
return 0;
}
示例12: main
int main(int argc, char **argv)
{
// OSG init
osgInit(argc,argv);
{
// Set up Window
WindowEventProducerRecPtr TutorialWindow = createNativeWindow();
TutorialWindow->initWindow();
// Create the SimpleSceneManager helper
SimpleSceneManager sceneManager;
TutorialWindow->setDisplayCallback(boost::bind(display, &sceneManager));
TutorialWindow->setReshapeCallback(boost::bind(reshape, _1, &sceneManager));
// Tell the Manager what to manage
sceneManager.setWindow(TutorialWindow);
//Attach to events
TutorialWindow->connectMousePressed(boost::bind(mousePressed, _1, &sceneManager));
TutorialWindow->connectMouseReleased(boost::bind(mouseReleased, _1, &sceneManager));
TutorialWindow->connectMouseMoved(boost::bind(mouseMoved, _1, &sceneManager));
TutorialWindow->connectMouseDragged(boost::bind(mouseDragged, _1, &sceneManager));
TutorialWindow->connectMouseWheelMoved(boost::bind(mouseWheelMoved, _1, &sceneManager));
//Particle System Material
MaterialChunkRefPtr PSMaterialChunkChunk = MaterialChunk::create();
PSMaterialChunkChunk->setAmbient(Color4f(0.3f,0.3f,0.3f,1.0f));
PSMaterialChunkChunk->setDiffuse(Color4f(0.7f,0.7f,0.7f,1.0f));
PSMaterialChunkChunk->setSpecular(Color4f(0.9f,0.9f,0.9f,1.0f));
PSMaterialChunkChunk->setColorMaterial(GL_AMBIENT_AND_DIFFUSE);
ChunkMaterialRefPtr PSMaterial = ChunkMaterial::create();
PSMaterial->addChunk(PSMaterialChunkChunk);
Distribution3DRefPtr PositionDistribution = createPositionDistribution();
Pnt3f PositionReturnValue;
//Particle System
ParticleSystemRecPtr ExampleParticleSystem = ParticleSystem::create();
for(UInt32 i(0) ; i<500 ; ++i)//controls how many particles are created
{
if(PositionDistribution != NULL)
{
PositionReturnValue = Pnt3f(PositionDistribution->generate());
}
ExampleParticleSystem->addParticle(
PositionReturnValue,
PositionReturnValue,
Vec3f(0.0f,0.0f,1.0f),
Color4f(1.0,0.0,0.0,1.0),
Vec3f(1.0,1.0,1.0),
-1, 0,
Vec3f(0.0,0.0,0.0), Vec3f(0.0f,0.0f,0.0f), //Velocity
Vec3f(0.0f,0.0f,0.0f), //acceleration
StringToUInt32Map() );
}
ExampleParticleSystem->attachUpdateProducer(TutorialWindow);
RandomMovementParticleAffectorRecPtr ExampleRMA = RandomMovementParticleAffector::create();
ExampleRMA->setAmplitude(100.0f);
AttributeAttractRepelParticleAffectorRecPtr ExampleAttributeAttractRepelParticleAffector = AttributeAttractRepelParticleAffector::create();
ExampleAttributeAttractRepelParticleAffector->setAttributeAffected(RandomMovementParticleAffector::POSITION_ATTRIBUTE);
ExampleAttributeAttractRepelParticleAffector->setMinDistance(0.0);
ExampleAttributeAttractRepelParticleAffector->setMaxDistance(10000000000000.0);
ExampleAttributeAttractRepelParticleAffector->setQuadratic(0.01);
ExampleAttributeAttractRepelParticleAffector->setLinear(0.01);
ExampleAttributeAttractRepelParticleAffector->setConstant(0.0);
ExampleParticleSystem->pushToAffectors(ExampleRMA);
ExampleParticleSystem->pushToAffectors(ExampleAttributeAttractRepelParticleAffector);
ExampleParticleSystem->setUpdateSecAttribs(false);
//Particle System Drawer
QuadParticleSystemDrawerRefPtr ExampleParticleSystemDrawer = QuadParticleSystemDrawer::create();
//Particle System Node
ParticleSystemCoreRefPtr ParticleNodeCore = ParticleSystemCore::create();
ParticleNodeCore->setSystem(ExampleParticleSystem);
ParticleNodeCore->setDrawer(ExampleParticleSystemDrawer);
ParticleNodeCore->setMaterial(PSMaterial);
NodeRefPtr ParticleNode = Node::create();
ParticleNode->setCore(ParticleNodeCore);
// Make Main Scene Node
NodeRefPtr scene = Node::create();
scene->setCore(Group::create());
scene->addChild(ParticleNode);
TutorialWindow->connectKeyTyped(boost::bind(keyTyped, _1,
&sceneManager,
ExampleParticleSystem.get(),
//.........这里部分代码省略.........
示例13: main
// Initialize GLUT & OpenSG and set up the scene
int main(int argc, char **argv)
{
// OSG init
osgInit(argc,argv);
// Set up Window
TutorialWindowEventProducer = createDefaultWindowEventProducer();
WindowPtr MainWindow = TutorialWindowEventProducer->initWindow();
TutorialWindowEventProducer->setDisplayCallback(display);
TutorialWindowEventProducer->setReshapeCallback(reshape);
//Add Window Listener
TutorialKeyListener TheKeyListener;
TutorialWindowEventProducer->addKeyListener(&TheKeyListener);
TutorialMouseListener TheTutorialMouseListener;
TutorialMouseMotionListener TheTutorialMouseMotionListener;
TutorialWindowEventProducer->addMouseListener(&TheTutorialMouseListener);
TutorialWindowEventProducer->addMouseMotionListener(&TheTutorialMouseMotionListener);
// Create the SimpleSceneManager helper
mgr = new SimpleSceneManager;
// Tell the Manager what to manage
mgr->setWindow(TutorialWindowEventProducer->getWindow());
Path FBOFilePath;
if(argc < 2)
{
FWARNING(("No FBO file given!\n"));
FBOFilePath = Path("./Data/01LoadFBO.xml");
}
else
{
FBOFilePath = Path(std::string(argv[1]));
}
std::cout << "Loading xml File: " << FBOFilePath << std::endl;
FCFileType::FCPtrStore NewContainers;
NewContainers = FCFileHandler::the()->read(FBOFilePath);
FCFileType::FCPtrStore::iterator Itor;
for(Itor = NewContainers.begin() ; Itor != NewContainers.end() ; ++Itor)
{
if( (*Itor)->getType() == FBOViewport::getClassType())
{
TheFBOViewport = FBOViewport::Ptr::dcast(*Itor);
}
}
ChunkMaterialPtr BoxMaterial = ChunkMaterial::create();
GeometryPtr BoxGeoCore = makeBoxGeo(1.0,1.0,1.0,2,2,2);
beginEditCP(BoxGeoCore, Geometry::MaterialFieldMask);
BoxGeoCore->setMaterial(BoxMaterial);
endEditCP(BoxGeoCore, Geometry::MaterialFieldMask);
NodePtr BoxGeoNode = Node::create();
beginEditCP(BoxGeoNode, Node::CoreFieldMask);
BoxGeoNode->setCore(BoxGeoCore);
endEditCP(BoxGeoNode, Node::CoreFieldMask);
NodePtr SceneNode = Node::create();
beginEditCP(SceneNode, Node::CoreFieldMask | Node::ChildrenFieldMask);
SceneNode->setCore(Group::create());
SceneNode->addChild(BoxGeoNode);
endEditCP(SceneNode, Node::CoreFieldMask | Node::ChildrenFieldMask);
// tell the manager what to manage
mgr->setRoot (SceneNode);
// show the whole scene
mgr->showAll();
if(TheFBOViewport != NullFC)
{
//Add the texture chunk of the FBO to the Material for the box
beginEditCP(BoxMaterial, ChunkMaterial::ChunksFieldMask);
BoxMaterial->addChunk(TheFBOViewport->editTextures(0));
endEditCP(BoxMaterial, ChunkMaterial::ChunksFieldMask);
//Add The FBO Viewport the the Window
beginEditCP(TheFBOViewport, FBOViewport::ParentFieldMask);
TheFBOViewport->setParent(TutorialWindowEventProducer->getWindow());
endEditCP(TheFBOViewport, FBOViewport::ParentFieldMask);
beginEditCP(TutorialWindowEventProducer->getWindow());
ViewportPtr vp = TutorialWindowEventProducer->getWindow()->getPort(0);
addRefCP(vp);
TutorialWindowEventProducer->getWindow()->subPort(0);
//Put the FBO Vieport in front, so it is rendered first
TutorialWindowEventProducer->getWindow()->addPort(TheFBOViewport);
TutorialWindowEventProducer->getWindow()->addPort(vp );
endEditCP (TutorialWindowEventProducer->getWindow());
}
//.........这里部分代码省略.........
示例14: main
// Initialize GLUT & OpenSG and set up the scene
int main(int argc, char **argv)
{
// OSG init
osgInit(argc,argv);
// GLUT init
int winid = setupGLUT(&argc, argv);
// the connection between GLUT and OpenSG
GLUTWindowPtr gwin= GLUTWindow::create();
gwin->setId(winid);
gwin->init();
// create the scene
/*
Geometry data in OpenSG is stored in several separate vectors.
These vectors are not a direct part of the Geometry Core but
rather split up into multiple separate classes.
These classes, the GeoProperties, contain a single field containg
their values, which can be accessed directly, see the docs for
GeoProperty for the whole interface.
*/
/*
The first part: the primtive types.
These are taken from OpenGL, any values that can be passed to
glBegin(); are legal. Different types can be freely mixed.
All properties have only one field, which has the same name for every
property, thus the mask is also called the same for each property.
*/
GeoPTypesPtr type = GeoPTypesUI8::create();
beginEditCP(type, GeoPTypesUI8::GeoPropDataFieldMask);
{
type->addValue(GL_POLYGON );
type->addValue(GL_TRIANGLES);
type->addValue(GL_QUADS );
}
endEditCP (type, GeoPTypesUI8::GeoPropDataFieldMask);
/*
The second part: the primtive lengths.
These define the number of vertices to be passed to OpenGL for each
primitive. Thus there have to be at least as many entries as in the
types property.
*/
GeoPLengthsPtr lens = GeoPLengthsUI32::create();
beginEditCP(lens, GeoPLengthsUI32::GeoPropDataFieldMask);
{
lens->addValue(4);
lens->addValue(6);
lens->addValue(8);
}
endEditCP (lens, GeoPLengthsUI32::GeoPropDataFieldMask);
/*
The third part: the vertex positions.
OpenSG uses different types for vectors and points.
Points (e.g. Pnt3f) are just positions in space, they have a limited
set of operations they can handle. Vectors (e.g. Vec3f) are the more
general kind.
*/
GeoPositions3fPtr pnts = GeoPositions3f::create();
beginEditCP(pnts, GeoPositions3f::GeoPropDataFieldMask);
{
// the 4 points of the polygon
pnts->addValue(Pnt3f(-1, -1, -1));
pnts->addValue(Pnt3f(-1, -1, 1));
pnts->addValue(Pnt3f( 1, -1, 1));
pnts->addValue(Pnt3f( 1, -1, -1));
// the 6 points of the two triangles
pnts->addValue(Pnt3f( 1, 0, -1));
pnts->addValue(Pnt3f(-1, 0, -1));
pnts->addValue(Pnt3f( 0, 1, -1));
pnts->addValue(Pnt3f(-1, 0, 1));
pnts->addValue(Pnt3f( 1, 0, 1));
pnts->addValue(Pnt3f( 0, 1, 1));
// the 8 points of the two quads
pnts->addValue(Pnt3f(-1, -1, 1));
pnts->addValue(Pnt3f( 1, -1, 1));
pnts->addValue(Pnt3f( 1, 0, 1));
pnts->addValue(Pnt3f(-1, 0, 1));
pnts->addValue(Pnt3f( 1, -1, -1));
pnts->addValue(Pnt3f(-1, -1, -1));
pnts->addValue(Pnt3f(-1, 0, -1));
pnts->addValue(Pnt3f( 1, 0, -1));
}
endEditCP (pnts, GeoPositions3f::GeoPropDataFieldMask);
/*
//.........这里部分代码省略.........
示例15: main
int main(int argc, char **argv)
{
// OSG init
osgInit(argc,argv);
{
// Set up Window
WindowEventProducerRecPtr TutorialWindow = createNativeWindow();
TutorialWindow->initWindow();
// Create the SimpleSceneManager helper
SimpleSceneManager sceneManager;
TutorialWindow->setDisplayCallback(boost::bind(display, &sceneManager));
TutorialWindow->setReshapeCallback(boost::bind(reshape, _1, &sceneManager));
// Tell the Manager what to manage
sceneManager.setWindow(TutorialWindow);
TutorialWindow->connectKeyTyped(boost::bind(keyPressed, _1));
// Make Torus Node (creates Torus in background of scene)
NodeRecPtr TorusGeometryNode = makeTorus(.5, 2, 16, 16);
// Make Main Scene Node and add the Torus
NodeRecPtr scene = Node::create();
scene->setCore(Group::create());
scene->addChild(TorusGeometryNode);
// Create the Graphics
GraphicsRecPtr TutorialGraphics = Graphics2D::create();
// Initialize the LookAndFeelManager to enable default settings
LookAndFeelManager::the()->getLookAndFeel()->init();
//Create the nessicary parts for a viewport
Matrix TransformMatrix;
TransformMatrix.setTranslate(0.0f,0.0f, 0.0f);
TransformRecPtr CameraBeaconTransform = Transform::create();
CameraBeaconTransform->setMatrix(TransformMatrix);
NodeRecPtr CameraBeaconNode = Node::create();
CameraBeaconNode->setCore(CameraBeaconTransform);
// Make Torus Node (creates Torus in background of scene)
NodeRecPtr GeometryNode = makeTorus(.5, 2, 32, 32);
//Make a light Node
NodeRecPtr LightBeaconNode = makeCoredNode<Transform>();
DirectionalLightRecPtr SceneLight = DirectionalLight::create();
SceneLight->setAmbient(Color4f(0.3f,0.3f,0.3f,1.0f));
SceneLight->setDiffuse(Color4f(0.8f,0.8f,0.8f,1.0f));
SceneLight->setSpecular(Color4f(1.0f,1.0f,1.0f,1.0f));
SceneLight->setOn(true);
SceneLight->setBeacon(LightBeaconNode);
NodeRecPtr LightNode = makeNodeFor(SceneLight);
LightNode->addChild(GeometryNode);
// Make Main Scene Node and add the Torus
NodeRecPtr DefaultRootNode = Node::create();
DefaultRootNode->setCore(Group::create());
DefaultRootNode->addChild(LightNode);
DefaultRootNode->addChild(LightBeaconNode);
DefaultRootNode->addChild(CameraBeaconNode);
//Camera
PerspectiveCameraRecPtr DefaultCamera = PerspectiveCamera::create();
DefaultCamera->setBeacon(CameraBeaconNode);
DefaultCamera->setFov (osgDegree2Rad(60.f));
DefaultCamera->setNear (0.1f);
DefaultCamera->setFar (100.f);
//Background
GradientBackgroundRecPtr DefaultBackground = GradientBackground::create();
DefaultBackground->addLine(Color3f(0.0f,0.0f,0.0f), 0.0f);
DefaultBackground->addLine(Color3f(0.0f,0.0f,1.0f), 1.0f);
//Viewport
ViewportRecPtr DefaultViewport = Viewport::create();
DefaultViewport->setCamera (DefaultCamera);
DefaultViewport->setRoot (DefaultRootNode);
DefaultViewport->setSize (0.0f,0.0f, 1.0f,1.0f);
DefaultViewport->setBackground (DefaultBackground);
//GL Viewport Component
LineBorderRecPtr TheGLViewportBorder = LineBorder::create();
TheGLViewportBorder->setColor(Color4f(1.0,0.0,0.0,1.0));
TheGLViewportBorder->setWidth(3.0);
GLViewportRecPtr TheGLViewport = GLViewport::create();
TheGLViewport->setPort(DefaultViewport);
TheGLViewport->setPreferredSize(Vec2f(400.0f,400.0f));
TheGLViewport->setBorders(TheGLViewportBorder);
TheGLViewport->lookAt(Pnt3f(0.0f,0.0f,10.0f), //From
Pnt3f(0.0f,0.0f,0.0f), //At
Vec3f(0.0f,1.0f,0.0f)); //Up
ButtonRecPtr ExampleButton = Button::create();
//.........这里部分代码省略.........