int main(int argc, char **argv) { // OSG init osgInit(argc,argv); { TheLuaManager->init(); // 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); //Setup the Lua Manager BoostPath ModulePath("./Data/"); std::string PackagePath = std::string("?;") + (ModulePath / "?.lua" ).file_string() + ";" + (ModulePath / "?" / "init.lua").file_string(); TheLuaManager->setPackagePath(PackagePath); // Make Torus Node (creates Torus in background of scene) GeometryRefPtr TorusGeometry = makeTorusGeo(.5, 2, 16, 16); setName(TorusGeometry,"Torus Geometry"); //calcVertexTangents(TorusGeometry,0,Geometry::TexCoords7FieldId, Geometry::TexCoords6FieldId); NodeRefPtr TorusGeometryNode = Node::create(); setName(TorusGeometryNode,"Torus Geometry Node"); TorusGeometryNode->setCore(TorusGeometry); //Torus Transformation Node TransformRefPtr TheTorusNodeTransform = Transform::create(); NodeRefPtr TheTorusTransfromNode = Node::create(); TheTorusTransfromNode->setCore(TheTorusNodeTransform); TheTorusTransfromNode->addChild(TorusGeometryNode); setName(TheTorusTransfromNode,"Torus Transform Node"); // Make Main Scene Node and add the Torus NodeRefPtr scene = Node::create(); scene->setCore(Group::create()); scene->addChild(TheTorusTransfromNode); setName(scene,"Scene Node"); //Light Beacon Node TransformRefPtr TheLightBeaconNodeTransform = Transform::create(); NodeRefPtr TheLightBeaconNode = Node::create(); TheLightBeaconNode->setCore(TheLightBeaconNodeTransform); setName(TheLightBeaconNode,"Light Beacon Node"); //Light Node DirectionalLightRefPtr TheLightCore = DirectionalLight::create(); TheLightCore->setDirection(Vec3f(1.0,0.0,0.0)); TheLightCore->setAmbient(Color4f(1.0,1.0,1.0,1.0)); TheLightCore->setDiffuse(Color4f(1.0,1.0,1.0,1.0)); TheLightCore->setSpecular(Color4f(1.0,1.0,1.0,1.0)); TheLightCore->setBeacon(TheLightBeaconNode); NodeRefPtr TheLightNode = Node::create(); TheLightNode->setCore(TheLightCore); TheLightNode->addChild(scene); setName(TheLightNode,"Light Node"); NodeRefPtr RootNode = Node::create(); RootNode->setCore(Group::create()); RootNode->addChild(TheLightNode); RootNode->addChild(TheLightBeaconNode); setName(RootNode,"Root Node"); // Create the Graphics GraphicsRefPtr TutorialGraphics = Graphics2D::create(); // Initialize the LookAndFeelManager to enable default settings LookAndFeelManager::the()->getLookAndFeel()->init(); //Create the Main interface LuaDebuggerInterface TheLuaDebuggerInterface; // Create The Main InternalWindow // Create Background to be used with the Main InternalWindow ColorLayerRefPtr MainInternalWindowBackground = ColorLayer::create(); MainInternalWindowBackground->setColor(Color4f(1.0,1.0,1.0,0.5)); BorderLayoutRefPtr MainInternalWindowLayout = BorderLayout::create(); //Split Panel BorderLayoutConstraintsRefPtr SplitPanelConstraints = BorderLayoutConstraints::create(); SplitPanelConstraints->setRegion(BorderLayoutConstraints::BORDER_CENTER); TheLuaDebuggerInterface.getMainSplitPanel()->setConstraints(SplitPanelConstraints); BorderLayoutConstraintsRefPtr ButtonPanelConstraints = BorderLayoutConstraints::create(); ButtonPanelConstraints->setRegion(BorderLayoutConstraints::BORDER_NORTH); TheLuaDebuggerInterface.getButtonPanel()->setConstraints(ButtonPanelConstraints); BorderLayoutConstraintsRefPtr CodeAreaInfoPanelConstraints = BorderLayoutConstraints::create(); CodeAreaInfoPanelConstraints->setRegion(BorderLayoutConstraints::BORDER_SOUTH); TheLuaDebuggerInterface.getCodeAreaInfoPanel()->setConstraints(CodeAreaInfoPanelConstraints); InternalWindowRefPtr MainInternalWindow = InternalWindow::create(); MainInternalWindow->pushToChildren(TheLuaDebuggerInterface.getButtonPanel()); MainInternalWindow->pushToChildren(TheLuaDebuggerInterface.getMainSplitPanel()); MainInternalWindow->pushToChildren(TheLuaDebuggerInterface.getCodeAreaInfoPanel()); MainInternalWindow->setLayout(MainInternalWindowLayout); MainInternalWindow->setBackgrounds(MainInternalWindowBackground); MainInternalWindow->setTitle("Lua Debugger"); setName(MainInternalWindow,"Internal Window"); // Create the Drawing Surface UIDrawingSurfaceRefPtr TutorialDrawingSurface = UIDrawingSurface::create(); TutorialDrawingSurface->setGraphics(TutorialGraphics); TutorialDrawingSurface->setEventProducer(TutorialWindow); TutorialDrawingSurface->openWindow(MainInternalWindow); // Create the UI Foreground Object UIForegroundRefPtr TutorialUIForeground = UIForeground::create(); TutorialUIForeground->setDrawingSurface(TutorialDrawingSurface); //Scene Background GradientBackgroundRefPtr SceneBackground = GradientBackground::create(); SceneBackground->addLine(Color3f(0.0,0.0,0.0),0.0); setName(SceneBackground,"Scene Background"); // Tell the Manager what to manage sceneManager.setWindow(TutorialWindow); sceneManager.setRoot(RootNode); //sceneManager.setHeadlight(false); // Add the UI Foreground Object to the Scene ViewportRefPtr TutorialViewport = sceneManager.getWindow()->getPort(0); TutorialViewport->addForeground(TutorialUIForeground); TutorialViewport->setBackground(SceneBackground); TutorialWindow->connectKeyTyped(boost::bind(keyTyped, _1, &TheLuaDebuggerInterface)); // 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, "03LuaDebugger"); MainInternalWindow->setAlignmentInDrawingSurface(Vec2f(0.5f,0.5f)); MainInternalWindow->setPreferredSize(WinSize * 0.85); //Enter main Loop TutorialWindow->mainLoop(); TheLuaManager->uninit(); } 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); // 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. MainInternalWindow2->pushToChildren(ExampleToggleButton); MainInternalWindow2->setLayout(MainInternalWindowLayout2); MainInternalWindow2->setBackgrounds(MainInternalWindowBackground); MainInternalWindow2->setPosition(Pnt2f(150,150)); MainInternalWindow2->setPreferredSize(Vec2f(300,300)); MainInternalWindow2->setTitle(std::string("Internal Window 2")); MainInternalWindow2->setIconable(false); MainInternalWindow2->setAllwaysOnTop(true); // Create the Drawing Surface UIDrawingSurfaceRefPtr TutorialDrawingSurface = UIDrawingSurface::create(); TutorialDrawingSurface->setGraphics(TutorialGraphics); TutorialDrawingSurface->setEventProducer(TutorialWindow); TutorialDrawingSurface->openWindow(MainInternalWindow); TutorialDrawingSurface->openWindow(MainInternalWindow2); // Create the UI Foreground Object UIForegroundRefPtr TutorialUIForeground = OSG::UIForeground::create(); TutorialUIForeground->setDrawingSurface(TutorialDrawingSurface); // Create the SimpleSceneManager helper mgr = new SimpleSceneManager; // Tell the Manager what to manage mgr->setWindow(TutorialWindow); mgr->setRoot(scene); // Add the UI Foreground Object to the Scene ViewportRefPtr TutorialViewport = mgr->getWindow()->getPort(0); TutorialViewport->addForeground(TutorialUIForeground); // 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, "37InternalWindow"); //Enter main Loop TutorialWindow->mainLoop(); osgExit(); return 0; }