瀏覽代碼

Render text labels in tutorial 105 (fixes #1104 and #1089).

Jérémie Dumas 6 年之前
父節點
當前提交
a5590c6389
共有 4 個文件被更改,包括 12 次插入2 次删除
  1. 3 0
      include/igl/opengl/ViewerData.h
  2. 1 1
      tutorial/105_Overlays/CMakeLists.txt
  3. 7 0
      tutorial/105_Overlays/main.cpp
  4. 1 1
      tutorial/CMakeLists.txt

+ 3 - 0
include/igl/opengl/ViewerData.h

@@ -113,6 +113,9 @@ public:
   // Alec: This is very confusing. Why does add_edges have a different API from
   // set_edges?
   IGL_INLINE void add_edges (const Eigen::MatrixXd& P1, const Eigen::MatrixXd& P2, const Eigen::MatrixXd& C);
+
+  // Adds text labels at the given positions in 3D.
+  // Note: This requires the ImGui viewer plugin to display text labels.
   IGL_INLINE void add_label (const Eigen::VectorXd& P,  const std::string& str);
 
   // Computes the normals of the mesh

+ 1 - 1
tutorial/105_Overlays/CMakeLists.txt

@@ -2,4 +2,4 @@ get_filename_component(PROJECT_NAME ${CMAKE_CURRENT_SOURCE_DIR} NAME)
 project(${PROJECT_NAME})
 
 add_executable(${PROJECT_NAME}_bin main.cpp)
-target_link_libraries(${PROJECT_NAME}_bin igl::core igl::opengl igl::opengl_glfw tutorials)
+target_link_libraries(${PROJECT_NAME}_bin igl::core igl::opengl igl::opengl_glfw igl::opengl_glfw_imgui tutorials)

+ 7 - 0
tutorial/105_Overlays/main.cpp

@@ -1,5 +1,6 @@
 #include <igl/readOFF.h>
 #include <igl/opengl/glfw/Viewer.h>
+#include <igl/opengl/glfw/imgui/ImGuiMenu.h>
 #include <sstream>
 #include "tutorial_shared_path.h"
 
@@ -67,6 +68,12 @@ int main(int argc, char *argv[])
   l2 << M(0) << ", " << M(1) << ", " << M(2);
   viewer.data().add_label(M,l2.str());
 
+  // Rendering of text labels is handled by ImGui, so we need to enable the ImGui
+  // plugin to show text labels.
+  igl::opengl::glfw::imgui::ImGuiMenu menu;
+  menu.callback_draw_viewer_window = [](){};
+  viewer.plugins.push_back(&menu);
+
   // Launch the viewer
   viewer.launch();
 }

+ 1 - 1
tutorial/CMakeLists.txt

@@ -55,8 +55,8 @@ if(TUTORIALS_CHAPTER1)
   add_subdirectory("102_DrawMesh")
   add_subdirectory("103_Events")
   add_subdirectory("104_Colors")
-  add_subdirectory("105_Overlays")
   if(LIBIGL_WITH_OPENGL_GLFW_IMGUI)
+    add_subdirectory("105_Overlays")
     add_subdirectory("106_ViewerMenu")
   endif()
   add_subdirectory("107_MultipleMeshes")