int main(int /*argc*/, char */*argv*/[]) { Util::init(); Util::UI::Window::Properties properties; properties.positioned = true; properties.posX = 100; properties.posY = 100; properties.clientAreaWidth = 1024; properties.clientAreaHeight = 768; properties.title = "GUI Textfield and Buttons"; properties.compatibilityProfile = true; auto window = Util::UI::createWindow(properties); Util::UI::EventContext eventContext; eventContext.getEventQueue().registerEventGenerator(std::bind(&Util::UI::Window::fetchEvents, window.get())); GUI::GUI_Manager guiManager(&eventContext); guiManager.setWindow(window.get()); Util::Reference<GUI::Window> guiWin = guiManager.createWindow(Geometry::Rect_f(10, 10, 200, 200), "Window"); Util::Reference<GUI::Textfield> guiText = guiManager.createTextfield("Text"); guiText->setRect(Geometry::Rect_f(0, 0, 40, 20)); guiWin->addContent(guiText.get()); Util::Reference<GUI::Button> guiButton = guiManager.createButton("Clear"); guiButton->setActionListener( [&guiText](GUI::Component *, const Util::StringIdentifier &) { guiText->setText(""); return true; }); guiButton->setRect(Geometry::Rect_f(0, 25, 40, 20)); guiWin->addContent(guiButton.get()); bool done = false; while(!done) { eventContext.getEventQueue().process(); while(eventContext.getEventQueue().getNumEventsAvailable() > 0) { auto event = eventContext.getEventQueue().popEvent(); if(event.type == Util::UI::EVENT_QUIT || (event.type == Util::UI::EVENT_KEYBOARD && event.keyboard.pressed && event.keyboard.key == Util::UI::KEY_ESCAPE)) { done = true; } else { guiManager.handleEvent(event); } } guiManager.display(); window->swapBuffers(); } return EXIT_SUCCESS; }
int test_large_scene(Util::UI::Window * window, Util::UI::EventContext & eventContext) { // texture registry std::map<std::string, Util::Reference<Rendering::Texture> > textures; std::cout << "Create FrameContext...\n"; FrameContext fc; unsigned int renderingFlags = /*BOUNDING_BOXES|SHOW_META_OBJECTS|*/FRUSTUM_CULLING/*|SHOW_COORD_SYSTEM*/;//|SHOW_COORD_SYSTEM; std::cout << "Create scene graph...\n"; Util::Reference<GroupNode> root = new MinSG::ListNode(); /// Skybox SkyboxState * sb = SkyboxState::createSkybox("Data/texture/?.bmp"); root->addState(sb); /// Some shperes... { std::default_random_engine engine; std::uniform_real_distribution<float> coordinateDist(0.0f, 200.0f); std::vector<Util::Reference<Rendering::Mesh> > spheres; Util::Reference<Rendering::Mesh> icosahedron = Rendering::MeshUtils::PlatonicSolids::createIcosahedron(); for(int i=0;i<6;++i) spheres.push_back(Rendering::MeshUtils::PlatonicSolids::createEdgeSubdivisionSphere(icosahedron.get(), i)); // 6... 81920 triangles each for (int i = 0; i < 1000; i++) { // create a real clone inclusive internal data! MinSG::GeometryNode * gn = new GeometryNode(spheres[std::uniform_int_distribution<std::size_t>(0, spheres.size() - 1)(engine)]->clone()); gn->moveRel(Geometry::Vec3(coordinateDist(engine), coordinateDist(engine), coordinateDist(engine))); root->addChild(gn); gn->scale(0.1 + std::uniform_real_distribution<float>(0.0f, 1000.0f)(engine) / 400.0); } } /// Camera Node * schwein = loadModel(Util::FileName("Data/model/Schwein.low.t.ply"), MESH_AUTO_CENTER | MESH_AUTO_SCALE); ListNode * camera = new ListNode(); CameraNode * camNode = new CameraNode(); camNode->setViewport(Geometry::Rect_i(0, 0, 1024, 768)); camNode->setNearFar(0.1, 2000); camNode->applyVerticalAngle(80); camNode->moveRel(Geometry::Vec3(0, 4, 10)); camera->addChild(camNode); camera->addChild(schwein); schwein->moveRel(Geometry::Vec3(0, 0, 0)); schwein->rotateLocal_deg(180, Geometry::Vec3(0, 1, 0)); LightNode * myHeadLight = LightNode::createPointLight(); myHeadLight->scale(1); myHeadLight->moveRel(Geometry::Vec3(0, 0, 0)); camera->addChild(myHeadLight); LightingState * lightState = new LightingState; lightState->setLight(myHeadLight); root->addState(lightState); root->addChild(camera); /// Eventhandler MoveNodeHandler * eh = new MoveNodeHandler(); MoveNodeHandler::initClaudius(eh, camera); // --------------------------------------------------------------------------------------------- Rendering::RenderingContext::clearScreen(Util::Color4f(0.5f, 0.5f, 0.5f, 0.5f)); // ---- GET_GL_ERROR(); uint32_t fpsFrameCounter = 0; Util::Timer fpsTimer; std::cout << "\nEntering main loop...\n"; // program main loop bool done = false; while (!done) { ++fpsFrameCounter; double seconds = fpsTimer.getSeconds(); if (seconds > 1.0) { double fps = static_cast<double> (fpsFrameCounter) / seconds; std::cout << "\r " << fps << " fps "; std::cout.flush(); fpsTimer.reset(); fpsFrameCounter = 0; } // message processing loop eventContext.getEventQueue().process(); while (eventContext.getEventQueue().getNumEventsAvailable() > 0) { Util::UI::Event event = eventContext.getEventQueue().popEvent(); // check for messages switch (event.type) { // exit if the window is closed case Util::UI::EVENT_QUIT: done = true; break; // check for keypresses case Util::UI::EVENT_KEYBOARD: { if(event.keyboard.pressed && event.keyboard.key == Util::UI::KEY_ESCAPE) { done = true; } break; } } // end switch } // end of message processing // apply translation eh->execute(); // clear screen Rendering::RenderingContext::clearScreen(Util::Color4f(0.0f, 0.0f, 0.0f, 1.0f)); // enable Camera fc.setCamera(camNode); // render Scene root->display(fc, renderingFlags); window->swapBuffers(); GET_GL_ERROR(); } // end main loop // destroy scene graph MinSG::destroy(root.get()); root = nullptr; // all is well ;) std::cout << "Exited cleanly\n"; //system("pause"); return EXIT_SUCCESS; }