static void keyboard(unsigned char k, int, int) { switch(k) { case 27: case 'q': case 'Q': { cleanup(); osgExit(); std::exit(EXIT_SUCCESS); } break; case '1': { UInt32 width = win->getWidth(); UInt32 height = win->getHeight(); std::cout << "Creating acquisition stage " << width << "x" << height << std::endl; if (!dynamicVp) { createAcquisitionStage(); createDynamicViewport(); } else { enableStaticScene(); } } break; } glutPostRedisplay(); }
// react to keys void keyboard(unsigned char k, int, int) { switch(k) { case 27: osgExit(); exit(1); } }
void keyboard(unsigned char k, int, int) { switch(k) { case 27: cleanup(); osgExit(); exit(0); break; case 'q': toggleAnim(0, false); break; case 'w': toggleAnim(0, true); break; case 'e': resetAnim(0); break; case 'r': toggleAnimEnable(0); break; case 't': increaseTimeScale(0); break; case 'y': decreaseTimeScale(0); break; case 'u': toggleAnimDirection(0); break; case 'a': toggleAnim(1, false); break; case 's': toggleAnim(1, true); break; case 'd': resetAnim(1); break; case 'f': toggleAnimEnable(1); break; case 'g': increaseTimeScale(1); break; case 'h': decreaseTimeScale(1); break; case 'j': toggleAnimDirection(1); break; } }
void fini(void) { delete mgr; mgr = NULL; cubesN = NULL; cubes = NULL; commitChanges(); osgExit(); }
// // main entry point // int main(int argc, char *argv[]) { int ret = doMain(argc, argv); glutMainLoop(); cleanup(); osgExit(); return ret; }
void cleanup() { //----------------------------------------------------------------------------// // Snippet-1-4 - BEGIN // //----------------------------------------------------------------------------// SystemCore::cleanup(); // clean up SystemCore and registered components //----------------------------------------------------------------------------// // Snippet-1-4 - END // //----------------------------------------------------------------------------// osgExit(); }
void ComplexSceneManager::run(void) { if(_fMainloop) { _fMainloop(); } else { FWARNING(("ComplexSceneManager: no mainloop exiting\n")); } osgExit(); }
int main(int argc, char *argv[]) { osgInit(argc, argv); std::cout << "testAnimTemplate" << std::endl; testAnimTemplate(); std::cout << "testAnim" << std::endl; testAnim(); osgExit(); return 0; }
// Activate the OpenSG namespace OSG_USING_NAMESPACE int main(int argc, char **argv) { // OSG init osgInit(argc,argv); NodePtr mpNode = Node::create(); MaterialPoolPtr mp = MaterialPool::create(); beginEditCP(mpNode); mpNode->setCore(mp); endEditCP(mpNode); // create some materials SimpleMaterialPtr mat1 = SimpleMaterial::create(); beginEditCP(mat1); mat1->setAmbient(Color3f(0.2, 0.2, 0.2)); mat1->setDiffuse(Color3f(1,0,0)); endEditCP(mat1); SimpleMaterialPtr mat2 = SimpleMaterial::create(); beginEditCP(mat2); mat2->setAmbient(Color3f(0.2, 0.2, 0.2)); mat2->setDiffuse(Color3f(0,1,0)); endEditCP(mat2); // this adds a material to the material pool. You can also add // all materials from a subtree via mp->add(node) beginEditCP(mp); mp->add(mat1); mp->add(mat2); endEditCP(mp); // now write the material pool out. SceneFileHandler::the().write(mpNode, "materials.osb"); osgExit(); return 0; }
static void keyboard(unsigned char k, int, int) { UInt32 winWidth = win->getWidth(); UInt32 winHeight = win->getHeight(); UInt32 width = fw * winWidth; UInt32 height = fh * winHeight; switch(k) { case 27: case 'q': case 'Q': { cleanup(); osgExit(); std::exit(EXIT_SUCCESS); } break; case '1': { std::cout << "Creating screenshot (Grab FG) " << width << "x" << height << " in '" << output_file << std::endl; writeHiResScreenShot(output_file, width, height); } break; case '2': { std::cout << "Creating screenshot (FBO) " << width << "x" << height << " in '" << output_file_fbo << std::endl; writeHiResScreenShotFBO(output_file_fbo, width, height); } break; } glutPostRedisplay(); }
// react to keys void keyboard(unsigned char k, int , int ) { switch(k) { case 27: { osgExit(); exit(1); } break; case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': { beginEditCP(sw, Switch::ChoiceFieldMask); sw->setChoice(k - '0'); endEditCP(sw, Switch::ChoiceFieldMask); break; } break; case 'a': { beginEditCP(sw, Switch::ChoiceFieldMask); sw->setChoice(Switch::ALL); endEditCP(sw, Switch::ChoiceFieldMask); } break; case 'n': { beginEditCP(sw, Switch::ChoiceFieldMask); sw->setChoice(Switch::NONE); endEditCP(sw, Switch::ChoiceFieldMask); } break; } }
// react to keys void keyboard(unsigned char k, int, int) { switch(k) { case 27: osgExit(); exit(1); case 'c': beginEditCP(colorFilterPtr); colorFilterPtr->setEnabled(!colorFilterPtr->getEnabled()); endEditCP(colorFilterPtr); break; case 'r': beginEditCP(resolutionFilterPtr); resolutionFilterPtr->setEnabled(!resolutionFilterPtr->getEnabled()); endEditCP(resolutionFilterPtr); break; case 'd': beginEditCP(distortionFilterPtr); distortionFilterPtr->setEnabled(!distortionFilterPtr->getEnabled()); endEditCP(distortionFilterPtr); break; } }
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 and edit a CheckboxButton. Note: the only function call shown specific to CheckboxButton is setSelected. In DefaultLookAndFeel, the options for changing the style of the CheckBox are shown. CheckboxButton also inherits off Button so all features of Button may be used. -setSelected(bool): Determines if the CheckboxButton is checked(true) or not checked(false). ******************************************************/ CheckboxButtonRecPtr ExampleCheckboxButton = CheckboxButton::create(); ExampleCheckboxButton->setMinSize(Vec2f(50, 25)); ExampleCheckboxButton->setMaxSize(Vec2f(300, 100)); ExampleCheckboxButton->setPreferredSize(Vec2f(200, 50)); ExampleCheckboxButton->setEnabled(true); ExampleCheckboxButton->setText("Checkbox Button"); ExampleCheckboxButton->setAlignment(Vec2f(0.5,0.5)); ExampleCheckboxButton->setSelected(true); // Create The Main InternalWindow // Create Background to be used with the Main InternalWindow ColorLayerRecPtr MainInternalWindowBackground = ColorLayer::create(); MainInternalWindowBackground->setColor(Color4f(1.0,1.0,1.0,0.5)); LayoutRecPtr MainInternalWindowLayout = FlowLayout::create(); InternalWindowRecPtr MainInternalWindow = InternalWindow::create(); MainInternalWindow->pushToChildren(ExampleCheckboxButton); MainInternalWindow->setLayout(MainInternalWindowLayout); MainInternalWindow->setBackgrounds(MainInternalWindowBackground); MainInternalWindow->setAlignmentInDrawingSurface(Vec2f(0.5f,0.5f)); MainInternalWindow->setScalingInDrawingSurface(Vec2f(0.5f,0.5f)); MainInternalWindow->setDrawTitlebar(false); MainInternalWindow->setResizable(false); // Create the Drawing Surface UIDrawingSurfaceRecPtr TutorialDrawingSurface = UIDrawingSurface::create(); TutorialDrawingSurface->setGraphics(TutorialGraphics); TutorialDrawingSurface->setEventProducer(TutorialWindow); TutorialDrawingSurface->openWindow(MainInternalWindow); // Create the UI Foreground Object UIForegroundRecPtr TutorialUIForeground = UIForeground::create(); TutorialUIForeground->setDrawingSurface(TutorialDrawingSurface); // Tell the Manager what to manage sceneManager.setRoot(scene); // Add the UI Foreground Object to the Scene ViewportRecPtr TutorialViewport = sceneManager.getWindow()->getPort(0); TutorialViewport->addForeground(TutorialUIForeground); // Show the whole Scene sceneManager.showAll(); //Open Window Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f); Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5); TutorialWindow->openWindow(WinPos, WinSize, "13CheckboxButton"); //Enter main Loop TutorialWindow->mainLoop(); } osgExit(); return 0; }
// Initialize GLUT & OpenSG and set up the rootNode 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); TutorialMouseListener TheTutorialMouseListener; TutorialMouseMotionListener TheTutorialMouseMotionListener; TutorialWindow->addMouseListener(&TheTutorialMouseListener); TutorialWindow->addMouseMotionListener(&TheTutorialMouseMotionListener); TutorialUpdateListener TheTutorialUpdateListener; TutorialWindow->addUpdateListener(&TheTutorialUpdateListener); // Create the SimpleSceneManager helper mgr = new SimpleSceneManager; // Tell the Manager what to manage mgr->setWindow(TutorialWindow); //Make Main Scene Node NodeRefPtr scene = makeCoredNode<Group>(); setName(scene, "scene"); rootNode = Node::create(); setName(rootNode, "rootNode"); ComponentTransformRefPtr Trans; Trans = ComponentTransform::create(); { rootNode->setCore(Trans); // add the torus as a child rootNode->addChild(scene); } //Make The Physics Characteristics Node PhysicsCharacteristicsDrawableUnrecPtr PhysDrawable = PhysicsCharacteristicsDrawable::create(); PhysDrawable->setRoot(rootNode); PhysDrawableNode = Node::create(); PhysDrawableNode->setCore(PhysDrawable); PhysDrawableNode->setTravMask(TypeTraits<UInt32>::getMin()); rootNode->addChild(PhysDrawableNode); //Light Beacon NodeRefPtr TutorialLightBeacon = makeCoredNode<Transform>(); //Light Node DirectionalLightRefPtr TutorialLight = DirectionalLight::create(); TutorialLight->setDirection(0.0,0.0,-1.0); TutorialLight->setBeacon(TutorialLightBeacon); NodeRefPtr TutorialLightNode = Node::create(); TutorialLightNode->setCore(TutorialLight); scene->addChild(TutorialLightNode); scene->addChild(TutorialLightBeacon); //Setup Physics Scene physicsWorld = PhysicsWorld::create(); physicsWorld->setWorldContactSurfaceLayer(0.01); physicsWorld->setAutoDisableFlag(1); physicsWorld->setAutoDisableTime(0.75); physicsWorld->setWorldContactMaxCorrectingVel(1.0); //physicsWorld->setGravity(Vec3f(0.0, 0.0, -9.81)); //physicsWorld->setCfm(0.001); //physicsWorld->setErp(0.2); hashSpace = PhysicsHashSpace::create(); physHandler = PhysicsHandler::create(); physHandler->setWorld(physicsWorld); physHandler->pushToSpaces(hashSpace); physHandler->setUpdateNode(rootNode); physHandler->attachUpdateProducer(TutorialWindow->editEventProducer()); rootNode->addAttachment(physHandler); rootNode->addAttachment(physicsWorld); rootNode->addAttachment(hashSpace); /************************************************************************/ /* create spaces, geoms and bodys */ /************************************************************************/ //create a group for our space GroupRefPtr spaceGroup; spaceGroupNode = makeCoredNode<Group>(&spaceGroup); //add Attachments to nodes... spaceGroupNode->addAttachment(hashSpace); TutorialLightNode->addChild(spaceGroupNode); //Create Character ShipBody = buildShip(Vec3f(3.0,3.0,10.0), Pnt3f((Real32)(rand()%100)-50.0,(Real32)(rand()%100)-50.0,25.0)); ShipMotor = buildMotor(ShipBody); for(UInt32 i(0) ; i<5 ; ++i) { buildBox(Vec3f(10.0,10.0,10.0), Pnt3f((Real32)(rand()%100)-50.0,(Real32)(rand()%100)-50.0,25.0)); } // tell the manager what to manage mgr->setRoot (rootNode); // show the whole rootNode mgr->showAll(); Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f); Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5); TutorialWindow->openWindow(WinPos, WinSize, "04ZeroGravityShip"); //Enter main Loop TutorialWindow->mainLoop(); osgExit(); return 0; }
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)); TutorialWindow->connectKeyTyped(boost::bind(keyTyped, _1, &sceneManager)); //Particle System 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 PSMaterial = ChunkMaterial::create(); PSMaterial->addChunk(PSPointChunk); PSMaterial->addChunk(PSMaterialChunkChunk); PSMaterial->addChunk(PSBlendChunk); Distribution3DRefPtr PositionDistribution = createPositionDistribution(); Pnt3f PositionReturnValue; //Particle System ParticleSystemRefPtr 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, Vec3f(0.0f,0.0f,1.0f), Color4f(1.0,0.0,0.0,1.0), Vec3f(1.0,1.0,1.0), -1, Vec3f(0.0f,0.0f,0.0f), //Velocity Vec3f(0.0f,0.0f,0.0f) //acceleration ); } ExampleParticleSystem->attachUpdateProducer(TutorialWindow); //Particle System Drawer PointParticleSystemDrawerRefPtr ExampleParticleSystemDrawer = PointParticleSystemDrawer::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 and add the Torus NodeRefPtr scene = Node::create(); scene->setCore(Group::create()); scene->addChild(ParticleNode); sceneManager.setRoot(scene); // Show the whole Scene sceneManager.showAll(); //Create an DistanceKill DistanceKillParticleAffectorRefPtr ExampleDistanceKillParticleAffector = DistanceKillParticleAffector::create(); ExampleDistanceKillParticleAffector->setKillDistance(1000.0f); ExampleDistanceKillParticleAffector->setParticleSystemNode(ParticleNode); ExampleDistanceKillParticleAffector->setDistanceFromSource(DistanceKillParticleAffector::DISTANCE_FROM_CAMERA); ExampleDistanceKillParticleAffector->setDistanceFromCamera(sceneManager.getCamera()); ExampleParticleSystem->pushToAffectors(ExampleDistanceKillParticleAffector); //Open Window Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f); Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5); TutorialWindow->openWindow(WinPos, WinSize, "09DistanceKillParticleAffector"); //Enter main Loop TutorialWindow->mainLoop(); } osgExit(); return 0; }
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 Spinner Model. This dictates how the Spinner functions. -setMaximum(int): Determine the Maximum value the Spinner can have. -setMinimum(int): Determine the Minimum value the Spinner can have. -setStepSize(int): Determine the incremental step size. -setValue(SharedFieldRecPtr(new SFInt32(int)): Determine initial starting value of the Spinner. Note: the StepSize can be changed dynamically as done in this Tutorial with ButtonSelectedListeners. ******************************************************/ //Int32SpinnerModelPtr TheModel(new Int32SpinnerModel()); Int32SpinnerModelPtr TheModel(new Int32SpinnerModel()); TheModel->setMaximum(100); TheModel->setMinimum(-100); TheModel->setStepSize(1); TheModel->setValue(boost::any(Int32(0))); /****************************************************** Create a Spinner and and assign it a Model. ******************************************************/ SpinnerRecPtr ExampleSpinner = Spinner::create(); ExampleSpinner->setModel(TheModel); /****************************************************** Create a RadioButtonPanel to allow for certain characteristics of the Spinner to be changed dynamically. See 14RadioButton for more information about RadioButtons. ******************************************************/ RadioButtonRecPtr SingleIncrementButton = RadioButton::create(); RadioButtonRecPtr DoubleIncrementButton = RadioButton::create(); SingleIncrementButton->setText("Increment by 1"); SingleIncrementButton->setPreferredSize(Vec2f(100, 50)); SingleIncrementButton->connectButtonSelected(boost::bind(handleSingleIncbuttonSelected, _1, TheModel)); DoubleIncrementButton->setText("Increment by 2"); DoubleIncrementButton->setPreferredSize(Vec2f(100, 50)); DoubleIncrementButton->connectButtonSelected(boost::bind(handleDoubleIncbuttonSelected, _1, TheModel)); RadioButtonGroupRecPtr SelectionRadioButtonGroup = RadioButtonGroup::create(); SelectionRadioButtonGroup->addButton(SingleIncrementButton); SelectionRadioButtonGroup->addButton(DoubleIncrementButton); SingleIncrementButton->setSelected(true); // Create The Main InternalWindow // Create Background to be used with the Main InternalWindow ColorLayerRecPtr MainInternalWindowBackground = ColorLayer::create(); MainInternalWindowBackground->setColor(Color4f(1.0,1.0,1.0,0.5)); LayoutRecPtr MainInternalWindowLayout = FlowLayout::create(); InternalWindowRecPtr MainInternalWindow = InternalWindow::create(); MainInternalWindow->pushToChildren(SingleIncrementButton); MainInternalWindow->pushToChildren(DoubleIncrementButton); MainInternalWindow->pushToChildren(ExampleSpinner); MainInternalWindow->setLayout(MainInternalWindowLayout); MainInternalWindow->setBackgrounds(MainInternalWindowBackground); MainInternalWindow->setAlignmentInDrawingSurface(Vec2f(0.5f,0.5f)); MainInternalWindow->setScalingInDrawingSurface(Vec2f(0.5f,0.5f)); MainInternalWindow->setDrawTitlebar(false); MainInternalWindow->setResizable(false); // Create the Drawing Surface UIDrawingSurfaceRecPtr TutorialDrawingSurface = UIDrawingSurface::create(); TutorialDrawingSurface->setGraphics(TutorialGraphics); TutorialDrawingSurface->setEventProducer(TutorialWindow); TutorialDrawingSurface->openWindow(MainInternalWindow); // Create the UI Foreground Object UIForegroundRecPtr TutorialUIForeground = UIForeground::create(); TutorialUIForeground->setDrawingSurface(TutorialDrawingSurface); // Tell the Manager what to manage sceneManager.setRoot(scene); // Add the UI Foreground Object to the Scene ViewportRecPtr TutorialViewport = sceneManager.getWindow()->getPort(0); TutorialViewport->addForeground(TutorialUIForeground); // Show the whole Scene sceneManager.showAll(); //Open Window Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f); Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5); TutorialWindow->openWindow(WinPos, WinSize, "29Spinner"); //Enter main Loop TutorialWindow->mainLoop(); } osgExit(); return 0; }
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); TutorialMouseListener TheTutorialMouseListener; TutorialMouseMotionListener TheTutorialMouseMotionListener; TutorialWindow->addMouseListener(&TheTutorialMouseListener); TutorialWindow->addMouseMotionListener(&TheTutorialMouseMotionListener); // Create the SimpleSceneManager helper mgr = new SimpleSceneManager; // Tell the Manager what to manage mgr->setWindow(TutorialWindow); //Particle System Material TextureObjChunkRefPtr QuadTextureObjChunk = TextureObjChunk::create(); ImageRefPtr LoadedImage = ImageFileHandler::the()->read("Data/Cloud.png"); QuadTextureObjChunk->setImage(LoadedImage); TextureEnvChunkRefPtr QuadTextureEnvChunk = TextureEnvChunk::create(); QuadTextureEnvChunk->setEnvMode(GL_MODULATE); BlendChunkRefPtr PSBlendChunk = BlendChunk::create(); PSBlendChunk->setSrcFactor(GL_SRC_ALPHA); PSBlendChunk->setDestFactor(GL_ONE_MINUS_SRC_ALPHA); 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 PSMaterial = ChunkMaterial::create(); PSMaterial->addChunk(QuadTextureObjChunk); PSMaterial->addChunk(QuadTextureEnvChunk); PSMaterial->addChunk(PSMaterialChunk); PSMaterial->addChunk(PSBlendChunk); //Affector ExampleAgeSizeParticleAffector = OSG::AgeSizeParticleAffector::create(); //ages ExampleAgeSizeParticleAffector->editMFAges()->push_back(0.0); ExampleAgeSizeParticleAffector->editMFAges()->push_back(0.05); ExampleAgeSizeParticleAffector->editMFAges()->push_back(0.2); ExampleAgeSizeParticleAffector->editMFAges()->push_back(0.36); ExampleAgeSizeParticleAffector->editMFAges()->push_back(0.7); ExampleAgeSizeParticleAffector->editMFAges()->push_back(0.8); ExampleAgeSizeParticleAffector->editMFAges()->push_back(1.0); //sizes ExampleAgeSizeParticleAffector->editMFSizes()->push_back(Vec3f(1.0,0.5,1.0)); ExampleAgeSizeParticleAffector->editMFSizes()->push_back(Vec3f(1.0,0.5,1.0)); ExampleAgeSizeParticleAffector->editMFSizes()->push_back(Vec3f(20.0,0.5,30.0)); ExampleAgeSizeParticleAffector->editMFSizes()->push_back(Vec3f(3.0,3.0,3.0)); ExampleAgeSizeParticleAffector->editMFSizes()->push_back(Vec3f(6.0,60.0,6.0)); ExampleAgeSizeParticleAffector->editMFSizes()->push_back(Vec3f(2.0,3.0,1.0)); ExampleAgeSizeParticleAffector->editMFSizes()->push_back(Vec3f(10.0,1.0,10.0)); //Particle System ExampleParticleSystem = OSG::ParticleSystem::create(); ExampleParticleSystem->attachUpdateListener(TutorialWindow); ExampleParticleSystem->pushToAffectors(ExampleAgeSizeParticleAffector); //Particle System Drawer ExampleParticleSystemDrawer = OSG::QuadParticleSystemDrawer::create(); ExampleBurstGenerator = OSG::BurstParticleGenerator::create(); //Attach the function objects to the Generator ExampleBurstGenerator->setPositionDistribution(createPositionDistribution()); ExampleBurstGenerator->setLifespanDistribution(createLifespanDistribution()); ExampleBurstGenerator->setBurstAmount(10.0); ExampleBurstGenerator->setVelocityDistribution(createVelocityDistribution()); //ExampleBurstGenerator->setAccelerationDistribution(createAccelerationDistribution()); ExampleBurstGenerator->setSizeDistribution(createSizeDistribution()); //Particle System Node ParticleSystemCoreRefPtr ParticleNodeCore = OSG::ParticleSystemCore::create(); ParticleNodeCore->setSystem(ExampleParticleSystem); ParticleNodeCore->setDrawer(ExampleParticleSystemDrawer); ParticleNodeCore->setMaterial(PSMaterial); NodeRefPtr ParticleNode = OSG::Node::create(); ParticleNode->setCore(ParticleNodeCore); //Ground Node NodeRefPtr GoundNode = makePlane(30.0,30.0,10,10); Matrix GroundTransformation; GroundTransformation.setRotate(Quaternion(Vec3f(1.0f,0.0,0.0), -3.14195f)); TransformRefPtr GroundTransformCore = Transform::create(); GroundTransformCore->setMatrix(GroundTransformation); NodeRefPtr GroundTransformNode = Node::create(); GroundTransformNode->setCore(GroundTransformCore); GroundTransformNode->addChild(GoundNode); // Make Main Scene Node and add the Torus NodeRefPtr scene = OSG::Node::create(); scene->setCore(OSG::Group::create()); scene->addChild(ParticleNode); scene->addChild(GroundTransformNode); mgr->setRoot(scene); // Show the whole Scene mgr->showAll(); //Open Window Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f); Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5); TutorialWindow->openWindow(WinPos, WinSize, "07AgeSizeParticleAffector"); //Enter main Loop TutorialWindow->mainLoop(); osgExit(); return 0; }
// Initialize GLUT & OpenSG and set up the scene int main(int argc, char **argv) { if(argc != 2) { std::cout << "Usage: 04Xml2Osb.exe [Filename]" << std::endl; return -1; } Path FilePath(argv[1]); if(!boost::filesystem::exists(FilePath)) { std::cout << "No file by name: "<< FilePath.string() << " exists." << std::endl; return -1; } // OSG init osgInit(argc,argv); NodePtr TheScene(NullFC); //Load the Scene FCFileType::FCPtrStore NewContainers; NewContainers = FCFileHandler::the()->read(FilePath); FCFileType::FCPtrStore::iterator Itor; for(Itor = NewContainers.begin() ; Itor != NewContainers.end() ; ++Itor) { if( (*Itor)->getType() == Node::getClassType() && Node::Ptr::dcast(*Itor)->getParent() == NullFC) { TheScene = Node::Ptr::dcast(*Itor); } } //Check if the scene was loaded if(TheScene == NullFC) { std::cout << "Failed to load a scene from: "<< FilePath.string() << "." << std::endl; return -1; } //Run Graph optimizations GraphOpSeq *graphop = new GraphOpSeq; graphop->addGraphOp(new VerifyGeoGraphOp); graphop->addGraphOp(new StripeGraphOp); //graphop->addGraphOp(new MaterialMergeGraphOp); //graphop->addGraphOp(new SharePtrGraphOp); if(graphop != NULL) { graphop->run(TheScene); } //Export the Scene to an osb file std::string ExportFileName(FilePath.string().substr(0,FilePath.string().size()-3) + "osb"); SceneFileHandler::the().write(TheScene, ExportFileName.c_str()); // OSG exit osgExit(); return 0; }
// Initialize WIN32 & OpenSG and set up the scene int main(int argc, char **argv) { preloadSharedObject("OSGTBFileIO"); // 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->connectMouseDragged(boost::bind(mouseDragged, _1, &sceneManager)); TutorialWindow->connectMouseWheelMoved(boost::bind(mouseWheelMoved, _1, &sceneManager)); TutorialWindow->connectKeyTyped(boost::bind(keyTyped, _1)); // create the scene NodeUnrecPtr scene = makeTorus(1.0, 2.0, 16, 16); sceneManager.setRoot (scene); //Create the Documentation SimpleScreenDoc TheSimpleScreenDoc(&sceneManager, TutorialWindow); // show the whole scene sceneManager.showAll(); //Load Sound Definitions FCFileType::FCPtrStore NewContainers; NewContainers = FCFileHandler::the()->read(BoostPath("Data/04SoundData.xml")); FCFileType::FCPtrStore::iterator Itor; for(Itor = NewContainers.begin() ; Itor != NewContainers.end() ; ++Itor) { //Get Sounds if( (*Itor)->getType().isDerivedFrom(Sound::getClassType())) { Sounds.push_back(dynamic_pointer_cast<Sound>(*Itor)); Sounds.back()->connectSoundPlayed (boost::bind(handleSoundPlayed, _1)); Sounds.back()->connectSoundStopped (boost::bind(handleSoundStopped, _1)); Sounds.back()->connectSoundPaused (boost::bind(handleSoundPaused, _1)); Sounds.back()->connectSoundUnpaused(boost::bind(handleSoundUnpaused, _1)); Sounds.back()->connectSoundLooped (boost::bind(handleSoundLooped, _1)); } //Get Sound Groups if( (*Itor)->getType().isDerivedFrom(SoundGroup::getClassType())) { SoundGroups.push_back(dynamic_pointer_cast<SoundGroup>(*Itor)); } } //Initialize the Sound Manager SoundManager::the()->attachUpdateProducer(TutorialWindow); SoundManager::the()->setCamera(sceneManager.getCamera()); Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f); Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5); TutorialWindow->openWindow(WinPos, WinSize, "04 XML Sound Loading Window"); //Enter main loop TutorialWindow->mainLoop(); } osgExit(); return 0; }
// 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)); BoostPath FilePath("../Animation/Data/Nanobot.dae"); if(argc >= 2) { FilePath = BoostPath(argv[1]); if(!boost::filesystem::exists(FilePath)) { std::cerr << "Could not load file: "<< FilePath.string() << ", because no such files exists."<< std::endl; FilePath = BoostPath("../Animation/Data/Nanobot.dae"); } } NodeRefPtr LoadedRoot; std::vector<AnimationRecPtr> LoadedAnimations; FCFileType::FCPtrStore ObjStore; try { ObjStore = FCFileHandler::the()->read(FilePath); } catch(std::exception &ex) { std::cerr << "Failed to load file: " << FilePath.string() << ", error:" << ex.what() << std::endl; return -1; } for(FCFileType::FCPtrStore::iterator StorItor(ObjStore.begin()); StorItor != ObjStore.end(); ++StorItor) { //Animations if((*StorItor)->getType().isDerivedFrom(Animation::getClassType())) { LoadedAnimations.push_back(dynamic_pointer_cast<Animation>(*StorItor)); LoadedAnimations.back()->attachUpdateProducer(TutorialWindow); LoadedAnimations.back()->start(); } //Root Node if((*StorItor)->getType() == Node::getClassType() && dynamic_pointer_cast<Node>(*StorItor)->getParent() == NULL) { LoadedRoot = dynamic_pointer_cast<Node>(*StorItor); } } if(LoadedRoot == NULL) { LoadedRoot = SceneFileHandler::the()->read(FilePath.string().c_str()); } if(LoadedRoot == NULL) { LoadedRoot= makeTorus(.5, 2, 32, 32); } //Make the fog node PostShaderStageRecPtr PostShaderStageCore = PostShaderStage::create(); PostShaderStageCore->clearPasses(); PostShaderStageCore->addPass("", generateNoEffectProg()); DirectionalLightRecPtr SceneLightCore = DirectionalLight::create(); SceneLightCore->setAmbient(Color4f(0.2f, 0.2f, 0.2f, 1.0f)); SceneLightCore->setDiffuse(Color4f(0.8f, 0.8f, 0.8f, 1.0f)); SceneLightCore->setSpecular(Color4f(1.0f, 1.0f, 1.0f, 1.0f)); NodeRefPtr SceneLight = makeNodeFor(SceneLightCore); SceneLight->addChild(LoadedRoot); NodeRefPtr PostShaderStageNode = makeNodeFor(PostShaderStageCore); PostShaderStageNode->addChild(SceneLight); //Make Main Scene Node NodeRefPtr scene = makeCoredNode<Group>(); scene->addChild(PostShaderStageNode); // tell the manager what to manage sceneManager.setRoot (scene); SceneLightCore->setBeacon(sceneManager.getCamera()->getBeacon()); //Create the Documentation Foreground and add it to the viewport SimpleScreenDoc TheSimpleScreenDoc(&sceneManager, TutorialWindow); // show the whole scene sceneManager.showAll(); sceneManager.getWindow()->getPort(0)->setTravMask(1); RenderOptionsRecPtr ViewportRenderOptions = RenderOptions::create(); ViewportRenderOptions->setRenderProperties(0x0); ViewportRenderOptions->setRenderProperties(RenderPropertiesPool::the()->getFrom1("Default")); ViewportRenderOptions->setRenderProperties(0x01); sceneManager.getWindow()->getPort(0)->setRenderOptions(ViewportRenderOptions); Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f); Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5); TutorialWindow->openWindow(WinPos, WinSize, "Collada Loader"); TutorialWindow->connectKeyPressed(boost::bind(keyPressed, _1, TutorialWindow.get(), PostShaderStageCore.get())); //Enter main Loop TutorialWindow->mainLoop(); } osgExit(); return 0; }
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 simple Font to be used with the TextField UIFontRecPtr sampleFont = 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 TextFieldRecPtr ExampleTextField = 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 TextFieldRecPtr ExampleTextField2 = 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 ColorLayerRecPtr MainInternalWindowBackground = ColorLayer::create(); MainInternalWindowBackground->setColor(Color4f(1.0,1.0,1.0,0.5)); LayoutRecPtr MainInternalWindowLayout = FlowLayout::create(); InternalWindowRecPtr MainInternalWindow = InternalWindow::create(); MainInternalWindow->pushToChildren(ExampleTextField); MainInternalWindow->pushToChildren(ExampleTextField2); MainInternalWindow->setLayout(MainInternalWindowLayout); MainInternalWindow->setBackgrounds(MainInternalWindowBackground); MainInternalWindow->setAlignmentInDrawingSurface(Vec2f(0.5f,0.5f)); MainInternalWindow->setScalingInDrawingSurface(Vec2f(0.5f,0.5f)); MainInternalWindow->setDrawTitlebar(false); MainInternalWindow->setResizable(false); // Create the Drawing Surface UIDrawingSurfaceRecPtr TutorialDrawingSurface = UIDrawingSurface::create(); TutorialDrawingSurface->setGraphics(TutorialGraphics); TutorialDrawingSurface->setEventProducer(TutorialWindow); TutorialDrawingSurface->openWindow(MainInternalWindow); // Create the UI Foreground Object UIForegroundRecPtr TutorialUIForeground = UIForeground::create(); TutorialUIForeground->setDrawingSurface(TutorialDrawingSurface); // Tell the Manager what to manage sceneManager.setRoot(scene); // Add the UI Foreground Object to the Scene ViewportRecPtr TutorialViewport = sceneManager.getWindow()->getPort(0); TutorialViewport->addForeground(TutorialUIForeground); // Show the whole Scene sceneManager.showAll(); //Open Window Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f); Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5); TutorialWindow->openWindow(WinPos, WinSize, "16TextField"); //Enter main Loop TutorialWindow->mainLoop(); } osgExit(); return 0; }
int main(int argc, char **argv) { // OSG init osgInit(argc,argv); { // Set up Window WindowEventProducerRecPtr TutorialWindow = createNativeWindow(); TutorialWindow->initWindow(); // Create the SimpleSceneManager helper SimpleSceneManagerRefPtr sceneManager = SimpleSceneManager::create(); 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(); /****************************************************** Creates RadioButton components and edit them. The RadioButton class inherits from the Button class. Radio Buttons are special ToggleButtons. When they are selected, any RadioButton in the same group is deselected, so there can only be one option selected. Advanced options for RadioButton can be found in the DefaultLookAndFeel.cpp file found in OSGUserInterface/Source Files/ LookAndFeel (options for changing the RadioButton style, etc). ******************************************************/ RadioButtonRecPtr ExampleRadioButton1 = RadioButton::create(); RadioButtonRecPtr ExampleRadioButton2 = RadioButton::create(); RadioButtonRecPtr ExampleRadioButton3 = RadioButton::create(); ExampleRadioButton1->setAlignment(Vec2f(0.0,0.5)); ExampleRadioButton1->setPreferredSize(Vec2f(100, 50)); ExampleRadioButton1->setText("Option 1"); ExampleRadioButton2->setAlignment(Vec2f(0.0,0.5)); ExampleRadioButton2->setPreferredSize(Vec2f(100, 50)); ExampleRadioButton2->setText("Option 2"); ExampleRadioButton3->setAlignment(Vec2f(0.0,0.5)); ExampleRadioButton3->setPreferredSize(Vec2f(100, 50)); ExampleRadioButton3->setText("Option 3"); /*************************************************** Create and populate a group of RadioButtons. Defining the group allows you to pick which RadioButtons are tied together so that only one can be selected. Each RadioButtonGroup can only have ONE RadioButton selected at a time, and by selecting this RadioButton, will deselect all other RadioButtons in the RadioButtonGroup. ******************************************************/ RadioButtonGroupRecPtr ExampleRadioButtonGroup = RadioButtonGroup::create(); ExampleRadioButtonGroup->addButton(ExampleRadioButton1); ExampleRadioButtonGroup->addButton(ExampleRadioButton2); ExampleRadioButtonGroup->addButton(ExampleRadioButton3); ExampleRadioButtonGroup->setSelectedButton(ExampleRadioButton2); FlowLayoutRecPtr MainInternalWindowLayout = FlowLayout::create(); MainInternalWindowLayout->setOrientation(FlowLayout::VERTICAL_ORIENTATION); MainInternalWindowLayout->setMajorAxisAlignment(0.5f); MainInternalWindowLayout->setMinorAxisAlignment(0.5f); // Create The Main InternalWindow // Create Background to be used with the Main InternalWindow ColorLayerRecPtr MainInternalWindowBackground = ColorLayer::create(); MainInternalWindowBackground->setColor(Color4f(1.0,1.0,1.0,0.5)); InternalWindowRecPtr MainInternalWindow = InternalWindow::create(); MainInternalWindow->pushToChildren(ExampleRadioButton1); MainInternalWindow->pushToChildren(ExampleRadioButton2); MainInternalWindow->pushToChildren(ExampleRadioButton3); MainInternalWindow->setLayout(MainInternalWindowLayout); MainInternalWindow->setBackgrounds(MainInternalWindowBackground); MainInternalWindow->setAlignmentInDrawingSurface(Vec2f(0.5f,0.5f)); MainInternalWindow->setScalingInDrawingSurface(Vec2f(0.5f,0.5f)); MainInternalWindow->setDrawTitlebar(false); MainInternalWindow->setResizable(false); // Create the Drawing Surface UIDrawingSurfaceRecPtr TutorialDrawingSurface = UIDrawingSurface::create(); TutorialDrawingSurface->setGraphics(TutorialGraphics); TutorialDrawingSurface->setEventProducer(TutorialWindow); TutorialDrawingSurface->openWindow(MainInternalWindow); // Create the UI Foreground Object UIForegroundRecPtr TutorialUIForeground = UIForeground::create(); TutorialUIForeground->setDrawingSurface(TutorialDrawingSurface); // Tell the Manager what to manage sceneManager->setRoot(scene); // Add the UI Foreground Object to the Scene ViewportRecPtr TutorialViewport = sceneManager->getWindow()->getPort(0); TutorialViewport->addForeground(TutorialUIForeground); //Create the Documentation Foreground and add it to the viewport SimpleScreenDoc TheSimpleScreenDoc(sceneManager, TutorialWindow); // Show the whole Scene sceneManager->showAll(); //Open Window Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f); Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5); TutorialWindow->openWindow(WinPos, WinSize, "14RadioButton"); //Enter main Loop TutorialWindow->mainLoop(); } osgExit(); return 0; }
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(); /****************************************************** Creates some Button components and edit their Text. ******************************************************/ ButtonRecPtr ExampleButton1 = Button::create(); ButtonRecPtr ExampleButton2 = Button::create(); ButtonRecPtr ExampleButton3 = Button::create(); ButtonRecPtr ExampleButton4 = Button::create(); ButtonRecPtr ExampleButton5 = Button::create(); ButtonRecPtr ExampleButton6 = Button::create(); ExampleButton1->setText("This"); ExampleButton2->setText("is a"); ExampleButton3->setText("sample"); ExampleButton4->setText("two"); ExampleButton5->setText("ExamplePanel"); ExampleButton6->setText("layout"); /****************************************************** Create some Flow and BoxLayouts to be used with the Main Frame and two Panels. ******************************************************/ FlowLayoutRecPtr MainInternalWindowLayout = FlowLayout::create(); FlowLayoutRecPtr ExamplePanel1Layout = FlowLayout::create(); FlowLayoutRecPtr ExamplePanel2Layout = FlowLayout::create(); ExamplePanel1Layout->setOrientation(FlowLayout::VERTICAL_ORIENTATION); /****************************************************** Create two Backgrounds to be used with Panels and MainInternalWindow. ******************************************************/ ColorLayerRecPtr MainInternalWindowBackground = ColorLayer::create(); ColorLayerRecPtr ExamplePanelBackground = ColorLayer::create(); MainInternalWindowBackground->setColor(Color4f(1.0,1.0,1.0,0.5)); ExamplePanelBackground->setColor(Color4f(0.0,0.0,0.0,1.0)); /****************************************************** Create a Border to be used with the two Panels. ******************************************************/ LineBorderRecPtr ExamplePanelBorder = LineBorder::create(); ExamplePanelBorder->setColor(Color4f(0.9, 0.9, 0.9, 1.0)); ExamplePanelBorder->setWidth(3); /****************************************************** Create MainInternalWindow and two Panel Components and edit their characteristics. -setPreferredSize(Vec2f): Determine the size of the Panel. -pushToChildren(ComponentName): Adds a Component to the ComponentContainer as a Child (meaning it will be displayed within it). -setLayout(LayoutName): Determines the Layout of the ComponentContainer. ******************************************************/ InternalWindowRecPtr MainInternalWindow = InternalWindow::create(); PanelRecPtr ExamplePanel1 = Panel::create(); PanelRecPtr ExamplePanel2 = Panel::create(); // Edit Panel1, Panel2 ExamplePanel1->setPreferredSize(Vec2f(200, 200)); ExamplePanel1->pushToChildren(ExampleButton1); ExamplePanel1->pushToChildren(ExampleButton2); ExamplePanel1->pushToChildren(ExampleButton3); ExamplePanel1->setLayout(ExamplePanel1Layout); ExamplePanel1->setBackgrounds(ExamplePanelBackground); ExamplePanel1->setBorders(ExamplePanelBorder); ExamplePanel2->setPreferredSize(Vec2f(200, 200)); ExamplePanel2->pushToChildren(ExampleButton4); ExamplePanel2->pushToChildren(ExampleButton5); ExamplePanel2->pushToChildren(ExampleButton6); ExamplePanel2->setLayout(ExamplePanel2Layout); ExamplePanel2->setBackgrounds(ExamplePanelBackground); ExamplePanel2->setBorders(ExamplePanelBorder); // Create The Main InternalWindow MainInternalWindow->pushToChildren(ExamplePanel1); MainInternalWindow->pushToChildren(ExamplePanel2); MainInternalWindow->setLayout(MainInternalWindowLayout); MainInternalWindow->setBackgrounds(MainInternalWindowBackground); MainInternalWindow->setAlignmentInDrawingSurface(Vec2f(0.5f,0.5f)); MainInternalWindow->setScalingInDrawingSurface(Vec2f(0.5f,0.5f)); MainInternalWindow->setDrawTitlebar(false); MainInternalWindow->setResizable(false); MainInternalWindow->setAllInsets(5); // Create the Drawing Surface UIDrawingSurfaceRecPtr TutorialDrawingSurface = UIDrawingSurface::create(); TutorialDrawingSurface->setGraphics(TutorialGraphics); TutorialDrawingSurface->setEventProducer(TutorialWindow); TutorialDrawingSurface->openWindow(MainInternalWindow); // Create the UI Foreground Object UIForegroundRecPtr TutorialUIForeground = UIForeground::create(); TutorialUIForeground->setDrawingSurface(TutorialDrawingSurface); // Tell the Manager what to manage sceneManager.setRoot(scene); // Add the UI Foreground Object to the Scene ViewportRecPtr TutorialViewport = sceneManager.getWindow()->getPort(0); TutorialViewport->addForeground(TutorialUIForeground); // Show the whole Scene sceneManager.showAll(); //Open Window Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f); Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5); TutorialWindow->openWindow(WinPos, WinSize, "10Container"); //Enter main Loop TutorialWindow->mainLoop(); } osgExit(); return 0; }
int main(int argc, char **argv) { // OSG init osgInit(argc,argv); // Set up Window TutorialWindow = createNativeWindow(); TutorialWindow->initWindow(); TutorialWindow->setDisplayCallback(display); TutorialWindow->setReshapeCallback(reshape); //Add Key Listener TutorialKeyListener TheKeyListener; TutorialWindow->addKeyListener(&TheKeyListener); //Add Mouse Listeners TutorialMouseListener TheTutorialMouseListener; TutorialMouseMotionListener TheTutorialMouseMotionListener; TutorialWindow->addMouseListener(&TheTutorialMouseListener); TutorialWindow->addMouseMotionListener(&TheTutorialMouseMotionListener); // Create the SimpleSceneManager helper mgr = new SimpleSceneManager; // Tell the Manager what to manage mgr->setWindow(TutorialWindow); //Particle System 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.5f,0.5f,0.5f,0.3f)); PSMaterialChunkChunk->setDiffuse(Color4f(0.8f,0.8f,0.8f,0.3f)); PSMaterialChunkChunk->setSpecular(Color4f(1.0f,1.0f,1.0f,0.3f)); PSMaterialChunkChunk->setColorMaterial(GL_AMBIENT_AND_DIFFUSE); ChunkMaterialRefPtr PSMaterial = ChunkMaterial::create(); PSMaterial->addChunk(PSPointChunk); PSMaterial->addChunk(PSMaterialChunkChunk); PSMaterial->addChunk(PSBlendChunk); //Particle System ParticleSystemRefPtr ExampleParticleSystem = ParticleSystem::create(); for(UInt32 i(0) ; i<10 ; ++i) { ExampleParticleSystem->addParticle(Pnt3f(i,i,i), Vec3f(0.0,0.0f,1.0f), Color4f(1.0,0.0,0.0,0.5), Vec3f(1.0,1.0,1.0), -1.0, Vec3f(0.0f,0.0f,0.0f), //Velocity Vec3f(0.0f,0.0f,0.0f) ); } ExampleParticleSystem->attachUpdateListener(TutorialWindow); //Particle System Drawer //Point ExamplePointParticleSystemDrawer = PointParticleSystemDrawer::create(); //ExamplePointParticleSystemDrawer->setForcePerParticleSizing(true); //Line ExampleLineParticleSystemDrawer = LineParticleSystemDrawer::create(); ExampleLineParticleSystemDrawer->setLineDirectionSource(LineParticleSystemDrawer::DIRECTION_NORMAL);//DIRECTION_VELOCITY_CHANGE); ExampleLineParticleSystemDrawer->setLineLengthSource(LineParticleSystemDrawer::LENGTH_SIZE_X); //Quad ExampleQuadParticleSystemDrawer = QuadParticleSystemDrawer::create(); //Disc ExampleDiscParticleSystemDrawer = DiscParticleSystemDrawer::create(); ExampleDiscParticleSystemDrawer->setSegments(16); ExampleDiscParticleSystemDrawer->setCenterAlpha(1.0); ExampleDiscParticleSystemDrawer->setEdgeAlpha(0.0); //Particle System Node ParticleNodeCore = ParticleSystemCore::create(); ParticleNodeCore->setSystem(ExampleParticleSystem); ParticleNodeCore->setDrawer(ExampleLineParticleSystemDrawer); 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); mgr->setRoot(scene); // Show the whole Scene mgr->showAll(); //Open Window Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f); Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5); TutorialWindow->openWindow(WinPos, WinSize, "01ParticleSystemDrawers"); commitChanges(); //Enter main Loop TutorialWindow->mainLoop(); osgExit(); return 0; }
int main(int argc, char **argv) { // OSG init osgInit(argc,argv); // Set up Window TutorialWindow = createNativeWindow(); TutorialWindow->initWindow(); TutorialWindow->setDisplayCallback(display); TutorialWindow->setReshapeCallback(reshape); //Add Window Listener TutorialKeyListener TheKeyListener; TutorialWindow->addKeyListener(&TheKeyListener); TutorialMouseListener TheTutorialMouseListener; TutorialMouseMotionListener TheTutorialMouseMotionListener; TutorialWindow->addMouseListener(&TheTutorialMouseListener); TutorialWindow->addMouseMotionListener(&TheTutorialMouseMotionListener); // Create the SimpleSceneManager helper mgr = new SimpleSceneManager; // Tell the Manager what to manage mgr->setWindow(TutorialWindow); //Shader Material BlendChunkUnrecPtr ExampleBlendChunk = BlendChunk::create(); ExampleBlendChunk->setSrcFactor(GL_SRC_ALPHA); ExampleBlendChunk->setDestFactor(GL_ONE_MINUS_SRC_ALPHA); //Material Chunk MaterialChunkUnrecPtr ShaderMaterialChunk = MaterialChunk::create(); ShaderMaterialChunk->setAmbient(Color4f(0.4f,0.4f,0.4f,1.0f)); ShaderMaterialChunk->setDiffuse(Color4f(0.7f,0.7f,0.7f,1.0f)); ShaderMaterialChunk->setSpecular(Color4f(1.0f,1.0f,1.0f,1.0f)); //Shader Chunk SimpleSHLChunkUnrecPtr TheSHLChunk = SimpleSHLChunk::create(); TheSHLChunk->setVertexProgram(createSHLVertexProg()); TheSHLChunk->setFragmentProgram(createSHLFragProg()); //Color Parameter ShaderVariableVec4fUnrecPtr Color1Parameter = ShaderVariableVec4f::create(); Color1Parameter->setName("Color1"); Color1Parameter->setValue(Vec4f(0.0f,1.0f,0.0f,1.0f)); ShaderVariableVec4fUnrecPtr Color2Parameter = ShaderVariableVec4f::create(); Color2Parameter->setName("Color2"); Color2Parameter->setValue(Vec4f(1.0f,1.0f,1.0f,1.0f)); //Shader Parameter Chunk SHLParameterChunkUnrecPtr SHLParameters = SHLParameterChunk::create(); SHLParameters->getParameters().push_back(Color1Parameter); SHLParameters->getParameters().push_back(Color2Parameter); SHLParameters->setSHLChunk(TheSHLChunk); ChunkMaterialUnrecPtr ShaderMaterial = ChunkMaterial::create(); ShaderMaterial->addChunk(ShaderMaterialChunk); ShaderMaterial->addChunk(TheSHLChunk); ShaderMaterial->addChunk(SHLParameters); //Torus Node GeometryUnrecPtr TorusGeometry = makeTorusGeo(5.0f,20.0f, 32,32); TorusGeometry->setMaterial(ShaderMaterial); NodeUnrecPtr TorusNode = Node::create(); TorusNode->setCore(TorusGeometry); // Make Main Scene Node NodeUnrecPtr scene = Node::create(); scene->setCore(Group::create()); scene->addChild(TorusNode); mgr->setRoot(scene); // Show the whole Scene mgr->showAll(); //Create the Animations initAnimations(Color1Parameter, "value"); //Open Window Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f); Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5); TutorialWindow->openWindow(WinPos, WinSize, "04ShaderAnimation"); //Main Loop TutorialWindow->mainLoop(); osgExit(); return 0; }
// Initialize GLUT & OpenSG and start the cluster server int main(int argc,char **argv) { int winid; char *name ="ClusterServer"; char *connectionType="StreamSock"; bool fullscreen =true; std::string address =""; char *opt; // initialize Glut glutInit(&argc, argv); glutInitDisplayMode( GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE); // evaluate params for(int a=1 ; a<argc ; ++a) { if(argv[a][0] == '-') { switch(argv[a][1]) { case 'm': connectionType="Multicast"; break; case 'p': connectionType="SockPipeline"; break; case 'w': fullscreen=false; break; case 'a': address = argv[a][2] ? argv[a]+2 : argv[++a]; if(address == argv[argc]) { SLOG << "address missing" << endLog; return 0; } std::cout << address << endLog; break; default: std::cout << argv[0] << "-m " << "-p " << "-w " << "-a address " << endLog; return 0; } } else { name=argv[a]; } } try { ChangeList::setReadWriteDefault(); // init OpenSG osgInit(argc, argv); winid = glutCreateWindow(name); if(fullscreen) glutFullScreen(); glutDisplayFunc(display); glutIdleFunc(display); glutReshapeFunc(reshape); glutSetCursor(GLUT_CURSOR_NONE); glEnable( GL_LIGHTING ); glEnable( GL_LIGHT0 ); glEnable( GL_NORMALIZE ); // create the render action ract=RenderAction::create(); // setup the OpenSG Glut window window = GLUTWindow::create(); window->setId(winid); window->init(); // create the cluster server server = new ClusterServer(window,name,connectionType,address); // start the server server->start(); // enter glut main loop glutMainLoop(); } catch(OSG_STDEXCEPTION_NAMESPACE::exception &e) { SLOG << e.what() << endLog; delete server; osgExit(); } return 0; }
int main(int argc, char **argv) { // OSG init osgInit(argc,argv); // Set up Window TutorialWindow = createNativeWindow(); TutorialWindow->initWindow(); TutorialWindow->setDisplayCallback(display); TutorialWindow->setReshapeCallback(reshape); //Add Window Listener TutorialKeyListener TheKeyListener; TutorialWindow->addKeyListener(&TheKeyListener); TutorialMouseListener TheTutorialMouseListener; TutorialMouseMotionListener TheTutorialMouseMotionListener; TutorialWindow->addMouseListener(&TheTutorialMouseListener); TutorialWindow->addMouseMotionListener(&TheTutorialMouseMotionListener); // Create the SimpleSceneManager helper mgr = new SimpleSceneManager; // Tell the Manager what to manage mgr->setWindow(TutorialWindow); //Print key command info std::cout << "\n\nKEY COMMANDS:" << std::endl; std::cout << "CTRL-Q Exit\n\n" << std::endl; //SkeletonDrawer System Material LineChunkUnrecPtr ExampleLineChunk = LineChunk::create(); ExampleLineChunk->setWidth(2.0f); ExampleLineChunk->setSmooth(true); BlendChunkUnrecPtr ExampleBlendChunk = BlendChunk::create(); ExampleBlendChunk->setSrcFactor(GL_SRC_ALPHA); ExampleBlendChunk->setDestFactor(GL_ONE_MINUS_SRC_ALPHA); MaterialChunkUnrecPtr ExampleMaterialChunk = MaterialChunk::create(); ExampleMaterialChunk->setAmbient(Color4f(1.0f,1.0f,1.0f,1.0f)); ExampleMaterialChunk->setDiffuse(Color4f(0.0f,0.0f,0.0f,1.0f)); ExampleMaterialChunk->setSpecular(Color4f(0.0f,0.0f,0.0f,1.0f)); ChunkMaterialUnrecPtr ExampleMaterial = ChunkMaterial::create(); ExampleMaterial->addChunk(ExampleLineChunk); ExampleMaterial->addChunk(ExampleMaterialChunk); ExampleMaterial->addChunk(ExampleBlendChunk); //Joint Node Hierarchy NodeRecPtr ExampleJointNode; //Create a new skeleton SkeletonBlendedGeometryRecPtr ExampleSkeleton; //Load skeleton from an XML file FCFileType::FCPtrStore NewContainers; NewContainers = FCFileHandler::the()->read(BoostPath("./Data/14Skeleton.xml")); FCFileType::FCPtrStore::iterator Itor; for(Itor = NewContainers.begin() ; Itor != NewContainers.end() ; ++Itor) { //We only want the skeleton; ignore anything else saved in the XML file if( (*Itor)->getType() == (SkeletonBlendedGeometry::getClassType())) { ExampleSkeleton = (dynamic_pointer_cast<SkeletonBlendedGeometry>(*Itor)); } if( (*Itor)->getType() == (Node::getClassType()) && (dynamic_pointer_cast<Node>(*Itor)->getParent() == NULL)) { ExampleJointNode = (dynamic_pointer_cast<Node>(*Itor)); } } //SkeletonDrawer SkeletonDrawableUnrecPtr ExampleSkeletonDrawable = SkeletonDrawable::create(); ExampleSkeletonDrawable->setSkeleton(ExampleSkeleton); ExampleSkeletonDrawable->setMaterial(ExampleMaterial); //Skeleton Node NodeUnrecPtr SkeletonNode = Node::create(); SkeletonNode->setCore(ExampleSkeletonDrawable); // Make Main Scene Node and add the Torus NodeUnrecPtr scene = Node::create(); scene->setCore(Group::create()); scene->addChild(SkeletonNode); mgr->setRoot(scene); // Show the whole Scene mgr->showAll(); //Open Window Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f); Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5); TutorialWindow->openWindow(WinPos, WinSize, "14SkeletonLoader"); //Main Loop TutorialWindow->mainLoop(); osgExit(); return 0; }
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 simple Font to be used with the PasswordField UIFontRecPtr ExampleFont = UIFont::create(); ExampleFont->setSize(16); /****************************************************** Create and edit a PasswordField. A PasswordField is a TextField which allows for text to be entered secretly. -setEchoCar("char"): Determine which character replaces text in the PasswordField. See 16TextField for more information. ******************************************************/ TextFieldRecPtr ExampleTextField = TextField::create(); ExampleTextField->setText(""); ExampleTextField->setEmptyDescText("username"); ExampleTextField->setPreferredSize(Vec2f(130.0f,ExampleTextField->getPreferredSize().y())); PasswordFieldRecPtr ExamplePasswordField = PasswordField::create(); ExamplePasswordField->setPreferredSize(Vec2f(130, ExamplePasswordField->getPreferredSize().y())); ExamplePasswordField->setTextColor(Color4f(0.0, 0.0, 0.0, 1.0)); ExamplePasswordField->setSelectionBoxColor(Color4f(0.0, 0.0, 1.0, 1.0)); ExamplePasswordField->setSelectionTextColor(Color4f(1.0, 1.0, 1.0, 1.0)); //ExamplePasswordField->setText("Text"); // "Text" will be replaced by "####" in the PasswordField ExamplePasswordField->setEchoChar("#"); ExamplePasswordField->setEditable(true); ExamplePasswordField->setFont(ExampleFont); ExamplePasswordField->setSelectionStart(2); ExamplePasswordField->setSelectionEnd(3); ExamplePasswordField->setAlignment(Vec2f(0.0,0.5)); ExamplePasswordField->setEmptyDescText("password"); // Create The Main InternalWindow // Create Background to be used with the Main InternalWindow ColorLayerRecPtr MainInternalWindowBackground = ColorLayer::create(); MainInternalWindowBackground->setColor(Color4f(1.0,1.0,1.0,0.5)); FlowLayoutRecPtr MainInternalWindowLayout = FlowLayout::create(); MainInternalWindowLayout->setOrientation(FlowLayout::VERTICAL_ORIENTATION); InternalWindowRecPtr MainInternalWindow = InternalWindow::create(); MainInternalWindow->pushToChildren(ExampleTextField); MainInternalWindow->pushToChildren(ExamplePasswordField); MainInternalWindow->setLayout(MainInternalWindowLayout); MainInternalWindow->setBackgrounds(MainInternalWindowBackground); MainInternalWindow->setAlignmentInDrawingSurface(Vec2f(0.5f,0.5f)); MainInternalWindow->setScalingInDrawingSurface(Vec2f(0.5f,0.5f)); MainInternalWindow->setDrawTitlebar(false); MainInternalWindow->setResizable(false); // Create the Drawing Surface UIDrawingSurfaceRecPtr TutorialDrawingSurface = UIDrawingSurface::create(); TutorialDrawingSurface->setGraphics(TutorialGraphics); TutorialDrawingSurface->setEventProducer(TutorialWindow); TutorialDrawingSurface->openWindow(MainInternalWindow); // Create the UI Foreground Object UIForegroundRecPtr TutorialUIForeground = UIForeground::create(); TutorialUIForeground->setDrawingSurface(TutorialDrawingSurface); // Tell the Manager what to manage sceneManager.setRoot(scene); // Add the UI Foreground Object to the Scene ViewportRecPtr TutorialViewport = sceneManager.getWindow()->getPort(0); TutorialViewport->addForeground(TutorialUIForeground); //Create the Documentation Foreground and add it to the viewport SimpleScreenDoc TheSimpleScreenDoc(&sceneManager, TutorialWindow); // Show the whole Scene sceneManager.showAll(); //Open Window Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f); Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5); TutorialWindow->openWindow(WinPos, WinSize, "24PasswordField"); //Enter main Loop TutorialWindow->mainLoop(); } osgExit(); return 0; }
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 RotatedComponent. -setAngle(Angle, in radians): Determine the angle the Component initially is rotated. -setInternalComponent(Component): Determine what Component will be rotated. -setResizePolicy(RotatedComponent::ENUM): Takes NO_RESIZING, RESIZE_TO_MIN, or RESIZE_TO_MAX arguments. ******************************************************/ RotatedComponentRecPtr TheRotatedComponent = RotatedComponent::create(); // Define PI Real32 PI(3.14159); TheRotatedComponent->setAngle(PI/4); ComponentRecPtr InnerPanel = createPanel(); TheRotatedComponent->setInternalComponent(InnerPanel); TheRotatedComponent->setResizePolicy(RotatedComponent::RESIZE_TO_MIN); /****************************************************** Create a ToggleButton which can be used to start and stop the Button from rotating. Note: due to the way FlowLayout works you will notice that this ToggleButton will move as well. In cases where a Rotating Component is used, an alternate Layout may be preferred to prevent other Components from moving as well. This is intentionally left this way to illustrate why this might be the case. A SplitPanel with fixed divider for example would prevent the ToggleButton from moving, while still allowing the Panel to move freely. ******************************************************/ ToggleButtonRecPtr RotateControlButton = ToggleButton::create(); RotateControlButton->setText("Start Rotating"); RotateControlButton->setPreferredSize(Vec2f(100.0f, 29.0f)); RotateControlButton->connectButtonSelected(boost::bind(handleButtonSelected, _1, TutorialWindow.get(), TheRotatedComponent.get())); RotateControlButton->connectButtonDeselected(boost::bind(handleButtonDeselected, _1, TutorialWindow.get(), TheRotatedComponent.get())); // Create The Main InternalWindow // Create Background to be used with the Main InternalWindow ColorLayerRecPtr MainInternalWindowBackground = ColorLayer::create(); MainInternalWindowBackground->setColor(Color4f(1.0,1.0,1.0,0.5)); LayoutRecPtr MainInternalWindowLayout = FlowLayout::create(); InternalWindowRecPtr MainInternalWindow = InternalWindow::create(); MainInternalWindow->pushToChildren(TheRotatedComponent); MainInternalWindow->pushToChildren(RotateControlButton); MainInternalWindow->setLayout(MainInternalWindowLayout); MainInternalWindow->setBackgrounds(MainInternalWindowBackground); MainInternalWindow->setAlignmentInDrawingSurface(Vec2f(0.5f,0.5f)); MainInternalWindow->setScalingInDrawingSurface(Vec2f(0.8f,0.8f)); MainInternalWindow->setDrawTitlebar(false); MainInternalWindow->setResizable(false); // Create the Drawing Surface UIDrawingSurfaceRecPtr TutorialDrawingSurface = UIDrawingSurface::create(); TutorialDrawingSurface->setGraphics(TutorialGraphics); TutorialDrawingSurface->setEventProducer(TutorialWindow); TutorialDrawingSurface->openWindow(MainInternalWindow); // Create the UI Foreground Object UIForegroundRecPtr TutorialUIForeground = UIForeground::create(); TutorialUIForeground->setDrawingSurface(TutorialDrawingSurface); // Tell the Manager what to manage sceneManager.setRoot(scene); // Add the UI Foreground Object to the Scene ViewportRecPtr TutorialViewport = sceneManager.getWindow()->getPort(0); TutorialViewport->addForeground(TutorialUIForeground); //Create the Documentation Foreground and add it to the viewport SimpleScreenDoc TheSimpleScreenDoc(&sceneManager, TutorialWindow); // Show the whole Scene sceneManager.showAll(); //Open Window Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f); Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5); TutorialWindow->openWindow(WinPos, WinSize, "30RotatedComponent"); //Enter main Loop TutorialWindow->mainLoop(); } osgExit(); return 0; }
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. ******************************************************/ CardLayoutRecPtr ExampleCardLayout = CardLayout::create(); PanelRecPtr ExampleCardPanel = Panel::create(); /****************************************************** Create Button Components to be used with CardLayout to allow for interactivity. ******************************************************/ ButtonRecPtr ExampleButton1 = Button::create(); ButtonRecPtr ExampleButton2 = Button::create(); ButtonRecPtr ExampleButton3 = Button::create(); ButtonRecPtr ExampleButton4 = Button::create(); ButtonRecPtr ExampleButton5 = Button::create(); ButtonRecPtr ExampleButton6 = Button::create(); ButtonRecPtr ExampleButton7 = Button::create(); ButtonRecPtr ExampleButton8 = Button::create(); ExampleButton1->setText("Next Card"); ExampleButton1->setConstraints(ExampleButton1Constraints); // Add Action ExampleButton1->connectActionPerformed(boost::bind(handleNextCardAction, _1, ExampleCardLayout.get(), ExampleCardPanel.get())); ExampleButton2->setText("Previous Card"); ExampleButton2->setConstraints(ExampleButton2Constraints); // Add Action ExampleButton2->connectActionPerformed(boost::bind(handleBackCardAction, _1, ExampleCardLayout.get(), ExampleCardPanel.get())); ExampleButton3->setText("This"); ExampleButton4->setText("is"); ExampleButton5->setText("Card"); ExampleButton6->setText("Layout"); ExampleButton7->setText("First Card"); ExampleButton7->setConstraints(ExampleButton7Constraints); // Add Action ExampleButton7->connectActionPerformed(boost::bind(handleFirstCardAction, _1, ExampleCardLayout.get(), ExampleCardPanel.get())); ExampleButton8->setText("Last Card"); ExampleButton8->setConstraints(ExampleButton8Constraints); // Add Action ExampleButton8->connectActionPerformed(boost::bind(handleLastCardAction, _1, ExampleCardLayout.get(), ExampleCardPanel.get())); ExampleCardPanel->setLayout(ExampleCardLayout); ExampleCardPanel->pushToChildren(ExampleButton3); ExampleCardPanel->pushToChildren(ExampleButton4); ExampleCardPanel->pushToChildren(ExampleButton5); ExampleCardPanel->pushToChildren(ExampleButton6); ExampleCardPanel->setConstraints(ExampleCardPanelConstraints); // Create The Main InternalWindow // Create Background to be used with the Main InternalWindow ColorLayerRecPtr MainInternalWindowBackground = ColorLayer::create(); MainInternalWindowBackground->setColor(Color4f(1.0,1.0,1.0,0.5)); InternalWindowRecPtr MainInternalWindow = InternalWindow::create(); MainInternalWindow->pushToChildren(ExampleButton1); MainInternalWindow->pushToChildren(ExampleButton2); MainInternalWindow->pushToChildren(ExampleButton7); MainInternalWindow->pushToChildren(ExampleButton8); MainInternalWindow->pushToChildren(ExampleCardPanel); MainInternalWindow->setLayout(MainInternalWindowLayout); MainInternalWindow->setBackgrounds(MainInternalWindowBackground); MainInternalWindow->setAlignmentInDrawingSurface(Vec2f(0.5f,0.5f)); MainInternalWindow->setScalingInDrawingSurface(Vec2f(0.5f,0.5f)); MainInternalWindow->setDrawTitlebar(false); MainInternalWindow->setResizable(false); // Create the Drawing Surface UIDrawingSurfaceRecPtr TutorialDrawingSurface = UIDrawingSurface::create(); TutorialDrawingSurface->setGraphics(TutorialGraphics); TutorialDrawingSurface->setEventProducer(TutorialWindow); TutorialDrawingSurface->openWindow(MainInternalWindow); // Create the UI Foreground Object UIForegroundRecPtr TutorialUIForeground = UIForeground::create(); TutorialUIForeground->setDrawingSurface(TutorialDrawingSurface); // Tell the Manager what to manage sceneManager.setRoot(scene); // Add the UI Foreground Object to the Scene ViewportRecPtr TutorialViewport = sceneManager.getWindow()->getPort(0); TutorialViewport->addForeground(TutorialUIForeground); //Create the Documentation Foreground and add it to the viewport SimpleScreenDoc TheSimpleScreenDoc(&sceneManager, TutorialWindow); // Show the whole Scene sceneManager.showAll(); //Open Window Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f); Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5); TutorialWindow->openWindow(WinPos, WinSize, "11CardLayout"); //Enter main Loop TutorialWindow->mainLoop(); } osgExit(); return 0; }