#include #include #include "imgui.h" #include "imgui_impl_glfw.h" #include "imgui_impl_opengl2.h" #include #include "FileBrowser/ImGuiFileBrowser.h" #include "triangle_mesh_type.h" #include #include // Interface variables GLFWwindow* window; vcg::GlTrimesh glWrap; vcg::Trackball trackball; imgui_addons::ImGuiFileBrowser file_dialog; std::ostringstream oss; // String stream used for the log // Interface options ImVec4 clear_color = ImVec4(0.33f, 0.33f, 0.33f, 1.00f); ImVec4 mesh_color = ImVec4(0.79f, 0.9f, 0.87f, 1.00f); float line_thick=1.f; int selected_rend_mode = 5; bool showMesh=true; bool showTrackBall=true; vcg::GLW::DrawMode DMode=vcg::GLW::DMSmooth; std::string PathMesh="../../meshes/fertility_tri.off"; // Mesh data MyTriMesh mesh; void LoadMesh(std::string path) { oss<<"Loading "<::Open(mesh,path.c_str()); vcg::tri::UpdateBounding::Box(mesh); vcg::tri::UpdateNormal::PerVertexNormalizedPerFaceNormalized(mesh); if (ret==0) oss<<"Loaded "<::VertexCoordLaplacian(mesh, 1, false); vcg::tri::UpdateNormal::PerVertexNormalizedPerFaceNormalized(mesh); oss<<"Smoothed mesh"; } ImGui::End(); } void GLDrawMesh() { int display_w, display_h; glfwGetFramebufferSize(window, &display_w, &display_h); glViewport(0, 0, display_w, display_h); glClearColor(clear_color.x * clear_color.w, clear_color.y * clear_color.w, clear_color.z * clear_color.w, clear_color.w); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); glEnable(GL_NORMALIZE); glEnable(GL_COLOR_MATERIAL); glEnable(GL_CULL_FACE); glEnable(GL_DEPTH_TEST); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(40, (GLdouble)display_w/(GLdouble)display_h, 0.1, 100); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); gluLookAt(0,0,4.f, 0,0,0, 0,1,0); trackball.GetView(); trackball.Apply(); glDisable(GL_CULL_FACE); glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE); // save modelview matrix glPushMatrix(); vcg::glScale(2.0f/mesh.bbox.Diag()); vcg::glTranslate(-mesh.bbox.Center()); if (showMesh) { glColor4f(mesh_color.x * mesh_color.w, mesh_color.y * mesh_color.w, mesh_color.z * mesh_color.w, mesh_color.w); glPushAttrib(GL_ALL_ATTRIB_BITS); glLineWidth(line_thick); glWrap.SetHintParamf(vcg::GLW::HNPPointSize,line_thick); glWrap.Draw(DMode,vcg::GLW::CMNone,vcg::GLW::TMNone); glPopAttrib(); } glPopMatrix(); if (showTrackBall) trackball.DrawPostApply(); } int main(int, char**) { LoadMesh(PathMesh); glWrap.m=&mesh; InitGLFW_Window(); InitIMGui(); glewInit(); // Main loop while (!glfwWindowShouldClose(window)) { // Poll and handle events (inputs, window resize, etc.) // You can read the io.WantCaptureMouse, io.WantCaptureKeyboard flags to tell if dear imgui wants to use your inputs. // - When io.WantCaptureMouse is true, do not dispatch mouse input data to your main application, or clear/overwrite your copy of the mouse data. // - When io.WantCaptureKeyboard is true, do not dispatch keyboard input data to your main application, or clear/overwrite your copy of the keyboard data. // Generally you may always pass all inputs to dear imgui, and hide them from your application based on those two flags. glfwPollEvents(); // Start the Dear ImGui frame ImGui_ImplOpenGL2_NewFrame(); ImGui_ImplGlfw_NewFrame(); ImGui::NewFrame(); { SetRenderBar(); SetLogWindow(); SetUserBar(); showMainMenu(); } // Rendering ImGui::Render(); GLDrawMesh(); // If you are using this code with non-legacy OpenGL header/contexts (which you should not, prefer using imgui_impl_opengl3.cpp!!), // you may need to backup/reset/restore other state, e.g. for current shader using the commented lines below. ImGui_ImplOpenGL2_RenderDrawData(ImGui::GetDrawData()); glfwMakeContextCurrent(window); glfwSwapBuffers(window); } // Cleanup ImGui_ImplOpenGL2_Shutdown(); ImGui_ImplGlfw_Shutdown(); ImGui::DestroyContext(); glfwDestroyWindow(window); glfwTerminate(); return 0; }