Browse Source

nanogui hacked as an optional plugin via IGL_VIEWER_WITH_NANOGUI

Former-commit-id: c3bd95e93f6bebff7ae4af8b8aaf056fb3ac79ab
Alec Jacobson 9 years ago
parent
commit
66a9d2aa63

+ 74 - 68
include/igl/viewer/TextRenderer.cpp

@@ -5,6 +5,7 @@
 // This Source Code Form is subject to the terms of the Mozilla Public License
 // v. 2.0. If a copy of the MPL was not distributed with this file, You can
 // obtain one at http://mozilla.org/MPL/2.0/.
+#ifdef IGL_VIEWER_WITH_NANOGUI
 #include "TextRenderer.h"
 #include "TextRenderer_fonts.h"
 #include <igl/project.h>
@@ -18,71 +19,76 @@
 #include <nanovg_gl.h>
 
 
-  IGL_INLINE igl::viewer::TextRenderer::TextRenderer(): ctx(nullptr) {}
-
-  IGL_INLINE int igl::viewer::TextRenderer::Init()
-  {
-    using namespace std;
-    #ifdef NDEBUG
-      ctx = nvgCreateGL3(NVG_STENCIL_STROKES | NVG_ANTIALIAS);
-    #else
-      ctx = nvgCreateGL3(NVG_STENCIL_STROKES | NVG_ANTIALIAS | NVG_DEBUG);
-    #endif
-
-    nvgCreateFontMem(ctx, "sans", igl_roboto_regular_ttf,
-                               igl_roboto_regular_ttf_size, 0);
-
-    return 0;
-  }
-
-  IGL_INLINE int igl::viewer::TextRenderer::Shut()
-  {
-    using namespace std;
-    if(ctx)
-      nvgDeleteGL3(ctx);
-    return 0;
-  }
-
-  IGL_INLINE void igl::viewer::TextRenderer::BeginDraw(const Eigen::Matrix4f &view, const Eigen::Matrix4f &proj,
-    const Eigen::Vector4f &_viewport, float _object_scale)
-  {
-    using namespace std;
-    viewport = _viewport;
-    proj_matrix = proj;
-    view_matrix = view;
-    object_scale = _object_scale;
-
-    Eigen::Vector2i mFBSize;
-    Eigen::Vector2i mSize;
-
-    GLFWwindow* mGLFWWindow = glfwGetCurrentContext();
-    glfwGetFramebufferSize(mGLFWWindow,&mFBSize[0],&mFBSize[1]);
-    glfwGetWindowSize(mGLFWWindow,&mSize[0],&mSize[1]);
-    glViewport(0,0,mFBSize[0],mFBSize[1]);
-
-    glClear(GL_STENCIL_BUFFER_BIT);
-
-    /* Calculate pixel ratio for hi-dpi devices. */
-    mPixelRatio = (float)mFBSize[0] / (float)mSize[0];
-    nvgBeginFrame(ctx,mSize[0],mSize[1],mPixelRatio);
-  }
-
-  IGL_INLINE void igl::viewer::TextRenderer::EndDraw()
-  {
-    using namespace std;
-    nvgEndFrame(ctx);
-  }
-
-  IGL_INLINE void igl::viewer::TextRenderer::DrawText(Eigen::Vector3d pos, Eigen::Vector3d normal, const std::string &text)
-  {
-    using namespace std;
-    pos += normal * 0.005f * object_scale;
-    Eigen::Vector3f coord = igl::project(Eigen::Vector3f(pos(0), pos(1), pos(2)),
-        view_matrix, proj_matrix, viewport);
-
-    nvgFontSize(ctx, 16*mPixelRatio);
-    nvgFontFace(ctx, "sans");
-    nvgTextAlign(ctx, NVG_ALIGN_LEFT | NVG_ALIGN_MIDDLE);
-    nvgFillColor(ctx, nvgRGBA(10,10,250,255));
-    nvgText(ctx, coord[0]/mPixelRatio, (viewport[3] - coord[1])/mPixelRatio, text.c_str(), NULL);
-  }
+IGL_INLINE igl::viewer::TextRenderer::TextRenderer(): ctx(nullptr) {}
+
+IGL_INLINE int igl::viewer::TextRenderer::Init()
+{
+  using namespace std;
+  #ifdef NDEBUG
+    ctx = nvgCreateGL3(NVG_STENCIL_STROKES | NVG_ANTIALIAS);
+  #else
+    ctx = nvgCreateGL3(NVG_STENCIL_STROKES | NVG_ANTIALIAS | NVG_DEBUG);
+  #endif
+
+  nvgCreateFontMem(ctx, "sans", igl_roboto_regular_ttf,
+                             igl_roboto_regular_ttf_size, 0);
+
+  return 0;
+}
+
+IGL_INLINE int igl::viewer::TextRenderer::Shut()
+{
+  using namespace std;
+  if(ctx)
+    nvgDeleteGL3(ctx);
+  return 0;
+}
+
+IGL_INLINE void igl::viewer::TextRenderer::BeginDraw(
+  const Eigen::Matrix4f &view, 
+  const Eigen::Matrix4f &proj,
+  const Eigen::Vector4f &_viewport, 
+  float _object_scale)
+{
+  using namespace std;
+  viewport = _viewport;
+  proj_matrix = proj;
+  view_matrix = view;
+  object_scale = _object_scale;
+
+  Eigen::Vector2i mFBSize;
+  Eigen::Vector2i mSize;
+
+  GLFWwindow* mGLFWWindow = glfwGetCurrentContext();
+  glfwGetFramebufferSize(mGLFWWindow,&mFBSize[0],&mFBSize[1]);
+  glfwGetWindowSize(mGLFWWindow,&mSize[0],&mSize[1]);
+  glViewport(0,0,mFBSize[0],mFBSize[1]);
+
+  glClear(GL_STENCIL_BUFFER_BIT);
+
+  /* Calculate pixel ratio for hi-dpi devices. */
+  mPixelRatio = (float)mFBSize[0] / (float)mSize[0];
+  nvgBeginFrame(ctx,mSize[0],mSize[1],mPixelRatio);
+}
+
+IGL_INLINE void igl::viewer::TextRenderer::EndDraw()
+{
+  using namespace std;
+  nvgEndFrame(ctx);
+}
+
+IGL_INLINE void igl::viewer::TextRenderer::DrawText(
+  Eigen::Vector3d pos, Eigen::Vector3d normal, const std::string &text)
+{
+  using namespace std;
+  pos += normal * 0.005f * object_scale;
+  Eigen::Vector3f coord = igl::project(Eigen::Vector3f(pos(0), pos(1), pos(2)),
+      view_matrix, proj_matrix, viewport);
+
+  nvgFontSize(ctx, 16*mPixelRatio);
+  nvgFontFace(ctx, "sans");
+  nvgTextAlign(ctx, NVG_ALIGN_LEFT | NVG_ALIGN_MIDDLE);
+  nvgFillColor(ctx, nvgRGBA(10,10,250,255));
+  nvgText(ctx, coord[0]/mPixelRatio, (viewport[3] - coord[1])/mPixelRatio, text.c_str(), NULL);
+}
+#endif

+ 2 - 0
include/igl/viewer/TextRenderer.h

@@ -7,6 +7,7 @@
 // obtain one at http://mozilla.org/MPL/2.0/.
 #ifndef IGL_VIEWER_TEXT_RENDERER_H
 #define IGL_VIEWER_TEXT_RENDERER_H
+#ifdef IGL_VIEWER_WITH_NANOGUI
 
 #include <Eigen/Dense>
 
@@ -52,3 +53,4 @@ namespace viewer
 #endif
 
 #endif
+#endif

+ 66 - 20
include/igl/viewer/Viewer.cpp

@@ -47,8 +47,10 @@
 #include <limits>
 #include <cassert>
 
-#include <nanogui/formhelper.h>
-#include <nanogui/screen.h>
+#ifdef IGL_VIEWER_WITH_NANOGUI
+#  include <nanogui/formhelper.h>
+#  include <nanogui/screen.h>
+#endif
 
 #include <igl/project.h>
 #include <igl/get_seconds.h>
@@ -80,7 +82,12 @@ static int global_KMod = 0;
 
 static void glfw_mouse_press(GLFWwindow* window, int button, int action, int modifier)
 {
-  bool tw_used = __viewer->screen->mouseButtonCallbackEvent(button,action,modifier);
+  bool tw_used = 
+#ifdef IGL_VIEWER_WITH_NANOGUI
+    __viewer->screen->mouseButtonCallbackEvent(button,action,modifier);
+#else
+    false;
+#endif
 
   igl::viewer::Viewer::MouseButton mb;
 
@@ -114,7 +121,9 @@ static void glfw_char_mods_callback(GLFWwindow* window, unsigned int codepoint,
 {
   // TODO: pass to nanogui (although it's also using physical key down/up
   // rather than character codes...
+#ifdef IGL_VIEWER_WITH_NANOGUI
   if(! __viewer->screen->charCallbackEvent(codepoint) )
+#endif
   {
     __viewer->key_pressed(codepoint, modifier);
   }
@@ -125,7 +134,9 @@ static void glfw_key_callback(GLFWwindow* window, int key, int scancode, int act
   if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS)
     glfwSetWindowShouldClose(window, GL_TRUE);
 
+#ifdef IGL_VIEWER_WITH_NANOGUI
   if (__viewer->screen->keyCallbackEvent(key,scancode,action,modifier) == false)
+#endif
   {
     if (action == GLFW_PRESS)
       __viewer->key_down(key, modifier);
@@ -146,7 +157,11 @@ static void glfw_window_size(GLFWwindow* window, int width, int height)
 
 static void glfw_mouse_move(GLFWwindow* window, double x, double y)
 {
-  if(__viewer->screen->cursorPosCallbackEvent(x,y) == false || __viewer->down)
+  if(
+#ifdef IGL_VIEWER_WITH_NANOGUI
+      __viewer->screen->cursorPosCallbackEvent(x,y) == false || 
+#endif
+      __viewer->down)
   {
     __viewer->mouse_move(x*highdpi, y*highdpi);
   }
@@ -158,13 +173,19 @@ static void glfw_mouse_scroll(GLFWwindow* window, double x, double y)
   scroll_x += x;
   scroll_y += y;
 
+#ifdef IGL_VIEWER_WITH_NANOGUI
   if (__viewer->screen->scrollCallbackEvent(x,y) == false)
+#endif
+  {
     __viewer->mouse_scroll(y);
+  }
 }
 
 static void glfw_drop_callback(GLFWwindow *window,int count,const char **filenames)
 {
+#ifdef IGL_VIEWER_WITH_NANOGUI
   __viewer->screen->dropCallbackEvent(count,filenames);
+#endif
 }
 
 namespace igl
@@ -173,6 +194,7 @@ namespace viewer
 {
   IGL_INLINE void Viewer::init()
   {
+#ifdef IGL_VIEWER_WITH_NANOGUI
     using namespace nanogui;
 
     ngui->setFixedSize(Eigen::Vector2i(60,20));
@@ -237,6 +259,7 @@ namespace viewer
     ngui->addVariable("Show faces labels", core.show_faceid);
 
     screen->performLayout();
+#endif
 
     core.init();
 
@@ -249,8 +272,10 @@ namespace viewer
 
   IGL_INLINE Viewer::Viewer()
   {
+#ifdef IGL_VIEWER_WITH_NANOGUI
     ngui = nullptr;
     screen = nullptr;
+#endif
 
     // Temporary variables initialization
     down = false;
@@ -286,7 +311,9 @@ namespace viewer
   {
     // Init all plugins
     for (unsigned int i = 0; i<plugins.size(); ++i)
+    {
       plugins[i]->init(this);
+    }
   }
 
   IGL_INLINE Viewer::~Viewer()
@@ -296,7 +323,9 @@ namespace viewer
   IGL_INLINE void Viewer::shutdown_plugins()
   {
     for (unsigned int i = 0; i<plugins.size(); ++i)
+    {
       plugins[i]->shutdown();
+    }
   }
 
   IGL_INLINE bool Viewer::load_mesh_from_file(const char* mesh_file_name)
@@ -345,7 +374,9 @@ namespace viewer
             igl::readOBJ(
               mesh_file_name_string,
               V, UV_V, corner_normals, F, UV_F, fNormIndices)))
+      {
         return false;
+      }
 
       data.set_mesh(V,F);
       data.set_uv(UV_V,UV_F);
@@ -473,11 +504,19 @@ namespace viewer
     // Initialization code for the trackball
     Eigen::RowVector3d center;
     if (data.V.rows() == 0)
+    {
       center << 0,0,0;
-    else
+    }else
+    {
       center = data.V.colwise().sum()/data.V.rows();
+    }
 
-    Eigen::Vector3f coord = igl::project(Eigen::Vector3f(center(0),center(1),center(2)), (core.view * core.model).eval(), core.proj, core.viewport);
+    Eigen::Vector3f coord = 
+      igl::project(
+        Eigen::Vector3f(center(0),center(1),center(2)), 
+        (core.view * core.model).eval(), 
+        core.proj, 
+        core.viewport);
     down_mouse_z = coord[2];
     down_rotation = core.trackball_angle;
 
@@ -548,23 +587,24 @@ namespace viewer
             default:
               assert(false && "Unknown rotation type");
             case ViewerCore::ROTATION_TYPE_TRACKBALL:
-              igl::trackball(core.viewport(2),
-                             core.viewport(3),
-                             2.0f,
-                             down_rotation,
-                             down_mouse_x,
-                             down_mouse_y,
-                             mouse_x,
-                             mouse_y,
-                             core.trackball_angle);
+              igl::trackball(
+                core.viewport(2),
+                core.viewport(3),
+                2.0f,
+                down_rotation,
+                down_mouse_x,
+                down_mouse_y,
+                mouse_x,
+                mouse_y,
+                core.trackball_angle);
               break;
             case ViewerCore::ROTATION_TYPE_TWO_AXIS_VALUATOR_FIXED_UP:
               igl::two_axis_valuator_fixed_up(
-                  core.viewport(2),core.viewport(3),
-                  2.0,
-                  down_rotation,
-                  down_mouse_x, down_mouse_y, mouse_x, mouse_y,
-                  core.trackball_angle);
+                core.viewport(2),core.viewport(3),
+                2.0,
+                down_rotation,
+                down_mouse_x, down_mouse_y, mouse_x, mouse_y,
+                core.trackball_angle);
               break;
           }
           //Eigen::Vector4f snapq = core.trackball_angle;
@@ -646,8 +686,10 @@ namespace viewer
       if (plugins[i]->post_draw())
         break;
 
+#ifdef IGL_VIEWER_WITH_NANOGUI
     ngui->refresh();
     screen->drawWidgets();
+#endif
   }
 
   IGL_INLINE bool Viewer::save_scene()
@@ -788,9 +830,11 @@ namespace viewer
     glfwSetInputMode(window,GLFW_CURSOR,GLFW_CURSOR_NORMAL);
 
     // Initialize FormScreen
+#ifdef IGL_VIEWER_WITH_NANOGUI
     screen = new nanogui::Screen();
     screen->initialize(window, false);
     ngui = new nanogui::FormHelper(screen);
+#endif
 
     __viewer = this;
 
@@ -862,10 +906,12 @@ namespace viewer
     core.shut();
 
     shutdown_plugins();
+#ifdef IGL_VIEWER_WITH_NANOGUI
     delete ngui;
     //delete screen;
     screen = nullptr;
     ngui = nullptr;
+#endif
 
     glfwDestroyWindow(window);
     glfwTerminate();

+ 4 - 0
include/igl/viewer/Viewer.h

@@ -32,7 +32,9 @@
 #define IGL_MOD_ALT             0x0004
 #define IGL_MOD_SUPER           0x0008
 
+#ifdef IGL_VIEWER_WITH_NANOGUI
 namespace nanogui { class FormHelper; class Screen; }
+#endif
 
 class GLFWwindow;
 
@@ -78,8 +80,10 @@ namespace viewer
     bool down;
     bool hack_never_moved;
 
+#ifdef IGL_VIEWER_WITH_NANOGUI
     nanogui::FormHelper* ngui;
     nanogui::Screen* screen;
+#endif
 
     // Keep track of the global position of the scrollwheel
     float scroll_position;

+ 8 - 0
include/igl/viewer/ViewerCore.cpp

@@ -289,6 +289,7 @@ IGL_INLINE void igl::viewer::ViewerCore::draw(ViewerData& data, OpenGL_state& op
       glUniform4f(fixed_colori, 0.0f, 0.0f, 0.0f, 0.0f);
     }
 
+#ifdef IGL_VIEWER_WITH_NANOGUI
     if (show_vertid)
     {
       textrenderer.BeginDraw(view*model, proj, viewport, object_scale);
@@ -312,6 +313,7 @@ IGL_INLINE void igl::viewer::ViewerCore::draw(ViewerData& data, OpenGL_state& op
       }
       textrenderer.EndDraw();
     }
+#endif
   }
 
   if (show_overlay)
@@ -353,6 +355,7 @@ IGL_INLINE void igl::viewer::ViewerCore::draw(ViewerData& data, OpenGL_state& op
       opengl.draw_overlay_points();
     }
 
+#ifdef IGL_VIEWER_WITH_NANOGUI
     if (data.labels_positions.rows() > 0)
     {
       textrenderer.BeginDraw(view*model, proj, viewport, object_scale);
@@ -361,6 +364,7 @@ IGL_INLINE void igl::viewer::ViewerCore::draw(ViewerData& data, OpenGL_state& op
             data.labels_strings[i]);
       textrenderer.EndDraw();
     }
+#endif
 
     glEnable(GL_DEPTH_TEST);
   }
@@ -505,10 +509,14 @@ IGL_INLINE igl::viewer::ViewerCore::ViewerCore()
 
 IGL_INLINE void igl::viewer::ViewerCore::init()
 {
+#ifdef IGL_VIEWER_WITH_NANOGUI
   textrenderer.Init();
+#endif
 }
 
 IGL_INLINE void igl::viewer::ViewerCore::shut()
 {
+#ifdef IGL_VIEWER_WITH_NANOGUI
   textrenderer.Shut();
+#endif
 }

+ 4 - 0
include/igl/viewer/ViewerCore.h

@@ -8,7 +8,9 @@
 #ifndef IGL_VIEWER_VIEWER_CORE_H
 #define IGL_VIEWER_VIEWER_CORE_H
 
+#ifdef IGL_VIEWER_WITH_NANOGUI
 #include <igl/viewer/TextRenderer.h>
+#endif
 #include <igl/viewer/ViewerData.h>
 #include <igl/viewer/OpenGL_state.h>
 
@@ -80,8 +82,10 @@ public:
 
   // ------------------- Properties
 
+#ifdef IGL_VIEWER_WITH_NANOGUI
   // Text rendering helper
   TextRenderer textrenderer;
+#endif
 
   // Shape material
   float shininess;

+ 11 - 0
tutorial/106_ViewerMenu/main.cpp

@@ -1,3 +1,13 @@
+#ifndef IGL_VIEWER_WITH_NANOGUI
+#include <iostream>
+int main()
+{
+  std::cerr<<
+    "Error: recompile with IGL_VIEWER_WITH_NANOGUI defined."<<std::endl;
+  return EXIT_FAILURE;
+}
+#else
+
 #include <igl/readOFF.h>
 #include <igl/viewer/Viewer.h>
 #include <nanogui/formhelper.h>
@@ -54,3 +64,4 @@ int main(int argc, char *argv[])
   viewer.data.set_mesh(V, F);
   viewer.launch();
 }
+#endif

+ 25 - 44
tutorial/CMakeLists.shared

@@ -8,13 +8,13 @@ remove_cxx_flag("-stdlib=libc++")
 if(NOT CMAKELISTS_SHARED_INCLUDED)
 set(CMAKELISTS_SHARED_INCLUDED TRUE)
 
-IF(MSVC)
+if(MSVC)
 ### Enable parallel compilation for Visual Studio
-  SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP")
-ELSE(MSVC)
+  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP")
+else(MSVC)
 #### Libigl requires a modern C++ compiler that supports c++11
-  SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
-ENDIF(MSVC)
+  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
+endif(MSVC)
 
 find_package(OpenMP)
 if (OPENMP_FOUND AND NOT WIN32)
@@ -22,7 +22,7 @@ if (OPENMP_FOUND AND NOT WIN32)
   set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
 endif()
 
-SET(CMAKE_VERBOSE_MAKEFILE ON)
+set(CMAKE_VERBOSE_MAKEFILE ON)
 
 set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/../cmake ${PROJECT_SOURCE_DIR}/cmake)
 set(CMAKE_COLOR_MAKEFILE ON)
@@ -34,79 +34,60 @@ set(CMAKE_COLOR_MAKEFILE ON)
 find_package(OpenGL REQUIRED)
 find_package(EIGEN REQUIRED)
 find_package(GLFWH REQUIRED)
-#find_package(LIBIGL REQUIRED)
-#find_package(NANOGUI REQUIRED)
 
 if(NOT APPLE)
-	find_package(GLEW REQUIRED)
+  find_package(GLEW REQUIRED)
 endif(NOT APPLE)
 
 if(APPLE)
-	set(CMAKE_CXX_LINK_FLAGS "-framework OpenGL -framework Cocoa -framework IOKit -framework CoreVideo")
-         set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse4.2")
-endif (APPLE) #APPLE
+  set(CMAKE_CXX_LINK_FLAGS "-framework OpenGL -framework Cocoa -framework IOKit -framework CoreVideo")
+  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native")
+endif (APPLE)
 
 if(UNIX AND NOT APPLE)
   set(CMAKE_CXX_LINK_EXECUTABLE "${CMAKE_CXX_LINK_EXECUTABLE} -lGL -lGLU -lrt -lX11 -lXxf86vm -lXrandr -lpthread -lXi  -lXcursor -lXinerama ")
-  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mavx")
+  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native")
 endif(UNIX AND NOT APPLE)
 
-#include_directories( ${NANOGUI_INCLUDE_DIRS} )
-
-
 if(NOT APPLE)
-	include_directories( ${GLEW_INCLUDE_DIR} )
+  include_directories( ${GLEW_INCLUDE_DIR} )
 endif(NOT APPLE)
 
 include_directories( ${EIGEN_INCLUDE_DIR})
-#include_directories( ${LIBIGL_INCLUDE_DIRS})
 include_directories( ${GLFW_INCLUDE_DIR})
 include_directories(
-	/usr/local/include
-	/opt/local/include
-    ${PROJECT_SOURCE_DIR}
-    ${OPENGL_INCLUDE_DIR}
+  /usr/local/include
+  /opt/local/include
+  ${PROJECT_SOURCE_DIR}
+  ${OPENGL_INCLUDE_DIR}
 )
 
 link_directories(
-	/usr/local/lib
-	${EIGEN_DIRS}
+  /usr/local/lib
+  ${EIGEN_DIRS}
 )
 
-#set(CMAKE_CXX_FLAGS -Wall -W -pedantic -std=c99)
-
 # Disable deprecated opengl code from libigl
 add_definitions(-DIGL_OPENGL_4)
 
 IF(CMAKE_BUILD_TYPE MATCHES RELEASE)
-    add_definitions(-DNDEBUG)
+  add_definitions(-DNDEBUG)
 ENDIF(CMAKE_BUILD_TYPE MATCHES RELEASE)
 
-#add_definitions(-DENABLE_XML_SERIALIZATION)
-
-
-
 if (${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang" OR ${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU")
-	set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
-	set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated-register")
+  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
+  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated-register")
 endif()
 
-# set(SHARED_SOURCES ${LIBIGL_SOURCES})
 
 if(NOT APPLE)
-	set(SHARED_SOURCES ${SHARED_SOURCES} ${GLEW_SOURCES})
+  set(SHARED_SOURCES ${SHARED_SOURCES} ${GLEW_SOURCES})
 endif(NOT APPLE)
 
-# message(FATAL_ERROR ${LIBIGL_SOURCES})
-
-
 set(SHARED_LIBRARIES
-#		${LIBIGL_LIBRARIES}
-		${OPENGL_LIBRARIES}
-#		${NANOGUI_LIBRARY}
-		${EIGEN_LIBRARIES}
-		${GLEW_LIBRARIES}
-#		${GLFW_LIBRARIES}
+  ${OPENGL_LIBRARIES}
+  ${EIGEN_LIBRARIES}
+  ${GLEW_LIBRARIES}
 )
 
 endif(NOT CMAKELISTS_SHARED_INCLUDED)

+ 33 - 21
tutorial/CMakeLists.txt

@@ -4,6 +4,7 @@ project(libigl_tutorials)
 message("Generated with config types: ${CMAKE_CONFIGURATION_TYPES}")
 
 option(LIBIGL_USE_STATIC_LIBRARY "Use static library" OFF)
+option(LIBIGL_VIEWER_WITH_NANOGUI "Enable nanogui " OFF)
 
 if(LIBIGL_USE_STATIC_LIBRARY)
   add_definitions(-DIGL_STATIC_LIBRARY)
@@ -12,13 +13,15 @@ endif(LIBIGL_USE_STATIC_LIBRARY)
 SET(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
 
 IF(MSVC)
-  SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP /bigobj /w") ### Enable parallel compilation for Visual Studio
+  # Enable parallel compilation for Visual Studio
+  SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP /bigobj /w") 
 
   SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR} )
   SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR} )
 
 ELSE(MSVC)
-  SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") #### Libigl requires a modern C++ compiler that supports c++11
+  # Libigl requires a modern C++ compiler that supports c++11
+  SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
   SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY "../" )
 ENDIF(MSVC)
 
@@ -48,36 +51,45 @@ include_directories("../include")
 option(ENABLE_ISPC_SUPPORT " " OFF)
 option(RTCORE_TASKING_SYSTEM " " INTERNAL)
 
-IF(NOT MSVC) # embree static build is broken on visual studio
-	option(ENABLE_STATIC_LIB " " ON)
-	set(ENABLE_STATIC_LIB ON CACHE BOOL "force static build of embree" FORCE)
+# embree static build is broken on visual studio
+IF(NOT MSVC) 
+  option(ENABLE_STATIC_LIB " " ON)
+  set(ENABLE_STATIC_LIB ON CACHE BOOL "force static build of embree" FORCE)
 ENDIF(NOT MSVC)
 
 IF(MSVC)
-	option(USE_STATIC_RUNTIME " " OFF)
-	set(USE_STATIC_RUNTIME OFF CACHE BOOL "disable changes in the runtime for VS" FORCE)
+  option(USE_STATIC_RUNTIME " " OFF)
+  set(USE_STATIC_RUNTIME OFF CACHE BOOL "disable changes in the runtime for VS" FORCE)
 ENDIF(MSVC)
 
 option(ENABLE_TUTORIALS " " OFF)
 
 IF(EMBREE_FOUND)
-  add_subdirectory("../external/embree/" "embree")		
-  include_directories("../external/embree/include")		
-  list(APPEND SHARED_LIBRARIES "embree")		
+  add_subdirectory("../external/embree/" "embree")    
+  include_directories("../external/embree/include")    
+  list(APPEND SHARED_LIBRARIES "embree")    
 ENDIF(EMBREE_FOUND)
 
-# endif(True)
-
-# if(True)
 #Compile nanogui
-set(NANOGUI_BUILD_PYTHON OFF CACHE BOOL " " FORCE)
-set(NANOGUI_BUILD_EXAMPLE OFF CACHE BOOL " " FORCE)
-set(NANOGUI_BUILD_SHARED OFF CACHE BOOL " " FORCE)
-
-add_subdirectory("../external/nanogui/" "nanogui")
-include_directories("../external/nanogui/include")
-include_directories("../external/nanogui/ext/nanovg/src")
-list(APPEND SHARED_LIBRARIES "nanogui")
+if(LIBIGL_VIEWER_WITH_NANOGUI)
+  set(NANOGUI_BUILD_PYTHON OFF CACHE BOOL " " FORCE)
+  set(NANOGUI_BUILD_EXAMPLE OFF CACHE BOOL " " FORCE)
+  set(NANOGUI_BUILD_SHARED OFF CACHE BOOL " " FORCE)
+  add_definitions(-DIGL_VIEWER_WITH_NANOGUI)
+  add_subdirectory("../external/nanogui/" "nanogui")
+  include_directories("../external/nanogui/include")
+  include_directories("../external/nanogui/ext/nanovg/src")
+  list(APPEND SHARED_LIBRARIES "nanogui")
+else()
+  # still need to build GLFW
+  set(GLFW_BUILD_EXAMPLES OFF CACHE BOOL " " FORCE)
+  set(GLFW_BUILD_TESTS OFF CACHE BOOL " " FORCE)
+  set(GLFW_BUILD_DOCS OFF CACHE BOOL " " FORCE)
+  set(GLFW_BUILD_INSTALL OFF CACHE BOOL " " FORCE)
+  add_subdirectory("${GLFW_INCLUDE_DIR}/../" "glfw")
+  list(APPEND SHARED_LIBRARIES "glfw")
+
+endif()
 
 
 #Compile CoMISo (if found)