Эх сурвалжийг харах

rm shader, tutorial uses new viewer refactor

Former-commit-id: fdd42ecfb2a40bc8895ccbff0a32fe0cd7471c4e
Alec Jacobson 8 жил өмнө
parent
commit
0b5ba6ee21
78 өөрчлөгдсөн 316 нэмэгдсэн , 4341 устгасан
  1. 0 173
      include/igl/opengl/Shader.cpp
  2. 0 98
      include/igl/opengl/Shader.h
  3. 43 23
      include/igl/opengl/State.cpp
  4. 3 4
      include/igl/opengl/State.h
  5. 22 21
      include/igl/opengl/ViewerCore.cpp
  6. 24 0
      include/igl/opengl/bind_vertex_attrib_array.cpp
  7. 32 0
      include/igl/opengl/bind_vertex_attrib_array.h
  8. 0 0
      include/igl/opengl/glfw/TextRenderer_fonts.cpp.REMOVED.git-id
  9. 0 1
      include/igl/opengl/glfw/Viewer.h
  10. 9 2
      include/igl/opengl/load_shader.cpp
  11. 6 1
      include/igl/opengl/load_shader.h
  12. 0 173
      include/igl/viewer/OpenGL_shader.cpp
  13. 0 98
      include/igl/viewer/OpenGL_shader.h
  14. 0 488
      include/igl/viewer/OpenGL_state.cpp
  15. 0 117
      include/igl/viewer/OpenGL_state.h
  16. 0 33
      include/igl/viewer/TODOs.txt
  17. 0 94
      include/igl/viewer/TextRenderer.cpp
  18. 0 56
      include/igl/viewer/TextRenderer.h
  19. 0 38
      include/igl/viewer/TextRenderer_fonts.h
  20. 0 1031
      include/igl/viewer/Viewer.cpp
  21. 0 167
      include/igl/viewer/Viewer.h
  22. 0 449
      include/igl/viewer/ViewerCore.cpp
  23. 0 246
      include/igl/viewer/ViewerCore.h
  24. 0 422
      include/igl/viewer/ViewerData.cpp
  25. 0 254
      include/igl/viewer/ViewerData.h
  26. 0 176
      include/igl/viewer/ViewerPlugin.h
  27. 2 2
      tutorial/102_DrawMesh/main.cpp
  28. 3 3
      tutorial/103_Events/main.cpp
  29. 2 2
      tutorial/104_Colors/main.cpp
  30. 2 2
      tutorial/105_Overlays/main.cpp
  31. 3 3
      tutorial/106_ViewerMenu/main.cpp
  32. 3 3
      tutorial/201_Normals/main.cpp
  33. 2 2
      tutorial/202_GaussianCurvature/main.cpp
  34. 2 2
      tutorial/203_CurvatureDirections/main.cpp
  35. 2 2
      tutorial/204_Gradient/main.cpp
  36. 3 3
      tutorial/205_Laplacian/main.cpp
  37. 2 2
      tutorial/301_Slice/main.cpp
  38. 2 2
      tutorial/302_Sort/main.cpp
  39. 2 2
      tutorial/303_LaplaceEquation/main.cpp
  40. 3 3
      tutorial/304_LinearEqualityConstraints/main.cpp
  41. 4 4
      tutorial/305_QuadraticProgramming/main.cpp
  42. 3 3
      tutorial/306_EigenDecomposition/main.cpp
  43. 4 4
      tutorial/401_BiharmonicDeformation/main.cpp
  44. 4 4
      tutorial/402_PolyharmonicDeformation/main.cpp
  45. 5 5
      tutorial/403_BoundedBiharmonicWeights/main.cpp
  46. 4 4
      tutorial/404_DualQuaternionSkinning/main.cpp
  47. 4 4
      tutorial/405_AsRigidAsPossible/main.cpp
  48. 4 4
      tutorial/406_FastAutomaticSkinningTransformations/main.cpp
  49. 6 5
      tutorial/407_BiharmonicCoordinates/main.cpp
  50. 3 3
      tutorial/501_HarmonicParam/main.cpp
  51. 3 3
      tutorial/502_LSCMParam/main.cpp
  52. 3 3
      tutorial/503_ARAPParam/main.cpp
  53. 4 4
      tutorial/504_NRosyDesign/main.cpp
  54. 3 3
      tutorial/505_MIQ/main.cpp
  55. 3 3
      tutorial/506_FrameField/main.cpp
  56. 3 3
      tutorial/507_PolyVectorField/main.cpp
  57. 3 3
      tutorial/508_ConjugateField/main.cpp
  58. 3 3
      tutorial/509_Planarization/main.cpp
  59. 7 7
      tutorial/510_Integrable/main.cpp
  60. 3 3
      tutorial/511_PolyVectorFieldGeneral/main.cpp
  61. 4 4
      tutorial/602_Matlab/main.cpp
  62. 2 2
      tutorial/604_Triangle/main.cpp
  63. 3 3
      tutorial/605_Tetgen/main.cpp
  64. 3 3
      tutorial/606_AmbientOcclusion/main.cpp
  65. 3 3
      tutorial/607_ScreenCapture/main.cpp
  66. 3 3
      tutorial/608_LIM/main.cpp
  67. 4 4
      tutorial/609_Boolean/main.cpp
  68. 3 3
      tutorial/610_CSGTree/main.cpp
  69. 4 4
      tutorial/702_WindingNumber/main.cpp
  70. 4 4
      tutorial/703_Decimation/main.cpp
  71. 4 4
      tutorial/704_SignedDistance/main.cpp
  72. 3 3
      tutorial/705_MarchingCubes/main.cpp
  73. 3 3
      tutorial/706_FacetOrientation/main.cpp
  74. 4 4
      tutorial/707_SweptVolume/main.cpp
  75. 3 3
      tutorial/708_Picking/main.cpp
  76. 4 4
      tutorial/709_VectorFieldVisualizer/main.cpp
  77. 11 11
      tutorial/710_SLIM/main.cpp
  78. 3 3
      tutorial/711_Subdivision/main.cpp

+ 0 - 173
include/igl/opengl/Shader.cpp

@@ -1,173 +0,0 @@
-// This file is part of libigl, a simple c++ geometry processing library.
-//
-// Copyright (C) 2014 Wenzel Jacob <wenzel@inf.ethz.ch>
-//
-// 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/.
-
-#include "Shader.h"
-
-#include <iostream>
-#include <fstream>
-
-IGL_INLINE bool igl::opengl::Shader::init_from_files(
-  const std::string &vertex_shader_filename,
-  const std::string &fragment_shader_filename,
-  const std::string &fragment_data_name,
-  const std::string &geometry_shader_filename,
-  int geometry_shader_max_vertices)
-{
-  auto file_to_string = [](const std::string &filename)->std::string
-  {
-    std::ifstream t(filename);
-    return std::string((std::istreambuf_iterator<char>(t)),
-                        std::istreambuf_iterator<char>());
-  };
-
-  return init(
-    file_to_string(vertex_shader_filename),
-    file_to_string(fragment_shader_filename),
-    fragment_data_name,
-    file_to_string(geometry_shader_filename),
-    geometry_shader_max_vertices
- );
-}
-
-IGL_INLINE bool igl::opengl::Shader::init(
-  const std::string &vertex_shader_string,
-  const std::string &fragment_shader_string,
-  const std::string &fragment_data_name,
-  const std::string &geometry_shader_string,
-  int geometry_shader_max_vertices)
-{
-  using namespace std;
-  vertex_shader = create_shader_helper(GL_VERTEX_SHADER, vertex_shader_string);
-  geometry_shader = create_shader_helper(GL_GEOMETRY_SHADER, geometry_shader_string);
-  fragment_shader = create_shader_helper(GL_FRAGMENT_SHADER, fragment_shader_string);
-
-  if (!vertex_shader || !fragment_shader)
-    return false;
-
-  program_shader = glCreateProgram();
-
-  glAttachShader(program_shader, vertex_shader);
-  glAttachShader(program_shader, fragment_shader);
-
-  if (geometry_shader)
-  {
-    glAttachShader(program_shader, geometry_shader);
-
-    /* This covers only basic cases and may need to be modified */
-    glProgramParameteri(program_shader, GL_GEOMETRY_INPUT_TYPE, GL_TRIANGLES);
-    glProgramParameteri(program_shader, GL_GEOMETRY_OUTPUT_TYPE, GL_TRIANGLES);
-    glProgramParameteri(program_shader, GL_GEOMETRY_VERTICES_OUT, geometry_shader_max_vertices);
-  }
-
-  glBindFragDataLocation(program_shader, 0, fragment_data_name.c_str());
-  glLinkProgram(program_shader);
-
-  GLint status;
-  glGetProgramiv(program_shader, GL_LINK_STATUS, &status);
-
-  if (status != GL_TRUE)
-  {
-    char buffer[512];
-    glGetProgramInfoLog(program_shader, 512, NULL, buffer);
-    cerr << "Linker error: " << endl << buffer << endl;
-    program_shader = 0;
-    return false;
-  }
-
-  return true;
-}
-
-IGL_INLINE void igl::opengl::Shader::bind()
-{
-  glUseProgram(program_shader);
-}
-
-IGL_INLINE GLint igl::opengl::Shader::attrib(const std::string &name) const
-{
-  return glGetAttribLocation(program_shader, name.c_str());
-}
-
-IGL_INLINE GLint igl::opengl::Shader::uniform(const std::string &name) const
-{
-  return glGetUniformLocation(program_shader, name.c_str());
-}
-
-IGL_INLINE GLint igl::opengl::Shader::bindVertexAttribArray(
-  const std::string &name, GLuint bufferID, const Eigen::MatrixXf &M, bool refresh) const
-{
-  GLint id = attrib(name);
-  if (id < 0)
-    return id;
-  if (M.size() == 0)
-  {
-    glDisableVertexAttribArray(id);
-    return id;
-  }
-  glBindBuffer(GL_ARRAY_BUFFER, bufferID);
-  if (refresh)
-    glBufferData(GL_ARRAY_BUFFER, sizeof(float)*M.size(), M.data(), GL_DYNAMIC_DRAW);
-  glVertexAttribPointer(id, M.rows(), GL_FLOAT, GL_FALSE, 0, 0);
-  glEnableVertexAttribArray(id);
-  return id;
-}
-
-IGL_INLINE void igl::opengl::Shader::free()
-{
-  if (program_shader)
-  {
-    glDeleteProgram(program_shader);
-    program_shader = 0;
-  }
-  if (vertex_shader)
-  {
-    glDeleteShader(vertex_shader);
-    vertex_shader = 0;
-  }
-  if (fragment_shader)
-  {
-    glDeleteShader(fragment_shader);
-    fragment_shader = 0;
-  }
-  if (geometry_shader)
-  {
-    glDeleteShader(geometry_shader);
-    geometry_shader = 0;
-  }
-}
-
-IGL_INLINE GLuint igl::opengl::Shader::create_shader_helper(GLint type, const std::string &shader_string)
-{
-  using namespace std;
-  if (shader_string.empty())
-    return (GLuint) 0;
-
-  GLuint id = glCreateShader(type);
-  const char *shader_string_const = shader_string.c_str();
-  glShaderSource(id, 1, &shader_string_const, NULL);
-  glCompileShader(id);
-
-  GLint status;
-  glGetShaderiv(id, GL_COMPILE_STATUS, &status);
-
-  if (status != GL_TRUE)
-  {
-    char buffer[512];
-    if (type == GL_VERTEX_SHADER)
-      cerr << "Vertex shader:" << endl;
-    else if (type == GL_FRAGMENT_SHADER)
-      cerr << "Fragment shader:" << endl;
-    else if (type == GL_GEOMETRY_SHADER)
-      cerr << "Geometry shader:" << endl;
-    cerr << shader_string << endl << endl;
-    glGetShaderInfoLog(id, 512, NULL, buffer);
-    cerr << "Error: " << endl << buffer << endl;
-    return (GLuint) 0;
-  }
-
-  return id;
-}

+ 0 - 98
include/igl/opengl/Shader.h

@@ -1,98 +0,0 @@
-// This file is part of libigl, a simple c++ geometry processing library.
-//
-// Copyright (C) 2014 Wenzel Jacob <wenzel@inf.ethz.ch>
-//
-// 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/.
-
-#ifndef IGL_OPENGL_SHADER_H
-#define IGL_OPENGL_SHADER_H
-
-#include <igl/igl_inline.h>
-#include <string>
-#include <Eigen/Core>
-
-#ifdef _WIN32
-#  include <windows.h>
-#  undef max
-#  undef min
-#  undef DrawText
-#endif
-
-#ifndef __APPLE__
-#  define GLEW_STATIC
-#  include <GL/glew.h>
-#endif
-
-#ifdef __APPLE__
-#   include <OpenGL/gl3.h>
-#   define __gl_h_ /* Prevent inclusion of the old gl.h */
-#else
-#   include <GL/gl.h>
-#endif
-
-namespace igl
-{
-namespace opengl
-{
-
-// This class wraps an OpenGL program composed of three shaders
-// TODO: write documentation
-
-class Shader
-{
-public:
-  typedef unsigned int GLuint;
-  typedef int GLint;
-
-  GLuint vertex_shader;
-  GLuint fragment_shader;
-  GLuint geometry_shader;
-  GLuint program_shader;
-
-  IGL_INLINE Shader() : vertex_shader(0), fragment_shader(0),
-    geometry_shader(0), program_shader(0) { }
-
-  // Create a new shader from the specified source strings
-  IGL_INLINE bool init(const std::string &vertex_shader_string,
-    const std::string &fragment_shader_string,
-    const std::string &fragment_data_name,
-    const std::string &geometry_shader_string = "",
-    int geometry_shader_max_vertices = 3);
-
-  // Create a new shader from the specified files on disk
-  IGL_INLINE bool init_from_files(const std::string &vertex_shader_filename,
-    const std::string &fragment_shader_filename,
-    const std::string &fragment_data_name,
-    const std::string &geometry_shader_filename = "",
-    int geometry_shader_max_vertices = 3);
-
-  // Select this shader for subsequent draw calls
-  IGL_INLINE void bind();
-
-  // Release all OpenGL objects
-  IGL_INLINE void free();
-
-  // Return the OpenGL handle of a named shader attribute (-1 if it does not exist)
-  IGL_INLINE GLint attrib(const std::string &name) const;
-
-  // Return the OpenGL handle of a uniform attribute (-1 if it does not exist)
-  IGL_INLINE GLint uniform(const std::string &name) const;
-
-  // Bind a per-vertex array attribute and refresh its contents from an Eigen amtrix
-  IGL_INLINE GLint bindVertexAttribArray(const std::string &name, GLuint bufferID,
-    const Eigen::MatrixXf &M, bool refresh) const;
-
-  IGL_INLINE GLuint create_shader_helper(GLint type, const std::string &shader_string);
-
-};
-
-}
-}
-
-#ifndef IGL_STATIC_LIBRARY
-#  include "Shader.cpp"
-#endif
-
-#endif

+ 43 - 23
include/igl/opengl/State.cpp

@@ -7,7 +7,10 @@
 // obtain one at http://mozilla.org/MPL/2.0/.
 // obtain one at http://mozilla.org/MPL/2.0/.
 
 
 #include "State.h"
 #include "State.h"
+#include "bind_vertex_attrib_array.h"
 #include "../ViewerData.h"
 #include "../ViewerData.h"
+#include "create_shader_program.h"
+#include "destroy_shader_program.h"
 
 
 IGL_INLINE void igl::opengl::State::init_buffers()
 IGL_INLINE void igl::opengl::State::init_buffers()
 {
 {
@@ -275,13 +278,13 @@ IGL_INLINE void igl::opengl::State::set_data(const igl::ViewerData &data, bool i
 IGL_INLINE void igl::opengl::State::bind_mesh()
 IGL_INLINE void igl::opengl::State::bind_mesh()
 {
 {
   glBindVertexArray(vao_mesh);
   glBindVertexArray(vao_mesh);
-  shader_mesh.bind();
-  shader_mesh.bindVertexAttribArray("position", vbo_V, V_vbo, dirty & ViewerData::DIRTY_POSITION);
-  shader_mesh.bindVertexAttribArray("normal", vbo_V_normals, V_normals_vbo, dirty & ViewerData::DIRTY_NORMAL);
-  shader_mesh.bindVertexAttribArray("Ka", vbo_V_ambient, V_ambient_vbo, dirty & ViewerData::DIRTY_AMBIENT);
-  shader_mesh.bindVertexAttribArray("Kd", vbo_V_diffuse, V_diffuse_vbo, dirty & ViewerData::DIRTY_DIFFUSE);
-  shader_mesh.bindVertexAttribArray("Ks", vbo_V_specular, V_specular_vbo, dirty & ViewerData::DIRTY_SPECULAR);
-  shader_mesh.bindVertexAttribArray("texcoord", vbo_V_uv, V_uv_vbo, dirty & ViewerData::DIRTY_UV);
+  glUseProgram(shader_mesh);
+  bind_vertex_attrib_array(shader_mesh,"position", vbo_V, V_vbo, dirty & ViewerData::DIRTY_POSITION);
+  bind_vertex_attrib_array(shader_mesh,"normal", vbo_V_normals, V_normals_vbo, dirty & ViewerData::DIRTY_NORMAL);
+  bind_vertex_attrib_array(shader_mesh,"Ka", vbo_V_ambient, V_ambient_vbo, dirty & ViewerData::DIRTY_AMBIENT);
+  bind_vertex_attrib_array(shader_mesh,"Kd", vbo_V_diffuse, V_diffuse_vbo, dirty & ViewerData::DIRTY_DIFFUSE);
+  bind_vertex_attrib_array(shader_mesh,"Ks", vbo_V_specular, V_specular_vbo, dirty & ViewerData::DIRTY_SPECULAR);
+  bind_vertex_attrib_array(shader_mesh,"texcoord", vbo_V_uv, V_uv_vbo, dirty & ViewerData::DIRTY_UV);
 
 
   glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vbo_F);
   glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vbo_F);
   if (dirty & ViewerData::DIRTY_FACE)
   if (dirty & ViewerData::DIRTY_FACE)
@@ -298,7 +301,7 @@ IGL_INLINE void igl::opengl::State::bind_mesh()
     glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
     glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
     glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tex_u, tex_v, 0, GL_RGBA, GL_UNSIGNED_BYTE, tex.data());
     glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tex_u, tex_v, 0, GL_RGBA, GL_UNSIGNED_BYTE, tex.data());
   }
   }
-  glUniform1i(shader_mesh.uniform("tex"), 0);
+  glUniform1i(glGetUniformLocation(shader_mesh,"tex"), 0);
   dirty &= ~ViewerData::DIRTY_MESH;
   dirty &= ~ViewerData::DIRTY_MESH;
 }
 }
 
 
@@ -307,9 +310,9 @@ IGL_INLINE void igl::opengl::State::bind_overlay_lines()
   bool is_dirty = dirty & ViewerData::DIRTY_OVERLAY_LINES;
   bool is_dirty = dirty & ViewerData::DIRTY_OVERLAY_LINES;
 
 
   glBindVertexArray(vao_overlay_lines);
   glBindVertexArray(vao_overlay_lines);
-  shader_overlay_lines.bind();
-  shader_overlay_lines.bindVertexAttribArray("position", vbo_lines_V, lines_V_vbo, is_dirty);
-  shader_overlay_lines.bindVertexAttribArray("color", vbo_lines_V_colors, lines_V_colors_vbo, is_dirty);
+  glUseProgram(shader_overlay_lines);
+ bind_vertex_attrib_array(shader_overlay_lines,"position", vbo_lines_V, lines_V_vbo, is_dirty);
+ bind_vertex_attrib_array(shader_overlay_lines,"color", vbo_lines_V_colors, lines_V_colors_vbo, is_dirty);
 
 
   glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vbo_lines_F);
   glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vbo_lines_F);
   if (is_dirty)
   if (is_dirty)
@@ -323,9 +326,9 @@ IGL_INLINE void igl::opengl::State::bind_overlay_points()
   bool is_dirty = dirty & ViewerData::DIRTY_OVERLAY_POINTS;
   bool is_dirty = dirty & ViewerData::DIRTY_OVERLAY_POINTS;
 
 
   glBindVertexArray(vao_overlay_points);
   glBindVertexArray(vao_overlay_points);
-  shader_overlay_points.bind();
-  shader_overlay_points.bindVertexAttribArray("position", vbo_points_V, points_V_vbo, is_dirty);
-  shader_overlay_points.bindVertexAttribArray("color", vbo_points_V_colors, points_V_colors_vbo, is_dirty);
+  glUseProgram(shader_overlay_points);
+ bind_vertex_attrib_array(shader_overlay_points,"position", vbo_points_V, points_V_vbo, is_dirty);
+ bind_vertex_attrib_array(shader_overlay_points,"color", vbo_points_V_colors, points_V_colors_vbo, is_dirty);
 
 
   glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vbo_points_F);
   glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vbo_points_F);
   if (is_dirty)
   if (is_dirty)
@@ -471,18 +474,35 @@ IGL_INLINE void igl::opengl::State::init()
   "}";
   "}";
 
 
   init_buffers();
   init_buffers();
-  shader_mesh.init(mesh_vertex_shader_string,
-      mesh_fragment_shader_string, "outColor");
-  shader_overlay_lines.init(overlay_vertex_shader_string,
-      overlay_fragment_shader_string, "outColor");
-  shader_overlay_points.init(overlay_vertex_shader_string,
-      overlay_point_fragment_shader_string, "outColor");
+  create_shader_program(
+    mesh_vertex_shader_string,
+    mesh_fragment_shader_string,
+    {},
+    shader_mesh);
+  create_shader_program(
+    overlay_vertex_shader_string,
+    overlay_fragment_shader_string,
+    {},
+    shader_overlay_lines);
+  create_shader_program(
+    overlay_vertex_shader_string,
+    overlay_point_fragment_shader_string,
+    {},
+    shader_overlay_points);
 }
 }
 
 
 IGL_INLINE void igl::opengl::State::free()
 IGL_INLINE void igl::opengl::State::free()
 {
 {
-  shader_mesh.free();
-  shader_overlay_lines.free();
-  shader_overlay_points.free();
+  const auto free = [](GLuint & id)
+  {
+    if(id)
+    {
+      destroy_shader_program(id);
+      id = 0;
+    }
+  };
+  free(shader_mesh);
+  free(shader_overlay_lines);
+  free(shader_overlay_points);
   free_buffers();
   free_buffers();
 }
 }

+ 3 - 4
include/igl/opengl/State.h

@@ -17,7 +17,6 @@
 // appropriate.
 // appropriate.
 
 
 #include <igl/igl_inline.h>
 #include <igl/igl_inline.h>
-#include "Shader.h"
 #include "../ViewerData.h"
 #include "../ViewerData.h"
 
 
 namespace igl
 namespace igl
@@ -33,9 +32,9 @@ public:
   GLuint vao_mesh;
   GLuint vao_mesh;
   GLuint vao_overlay_lines;
   GLuint vao_overlay_lines;
   GLuint vao_overlay_points;
   GLuint vao_overlay_points;
-  Shader shader_mesh;
-  Shader shader_overlay_lines;
-  Shader shader_overlay_points;
+  GLuint shader_mesh;
+  GLuint shader_overlay_lines;
+  GLuint shader_overlay_points;
 
 
   GLuint vbo_V; // Vertices of the current mesh (#V x 3)
   GLuint vbo_V; // Vertices of the current mesh (#V x 3)
   GLuint vbo_V_uv; // UV coordinates for the current mesh (#V x 2)
   GLuint vbo_V_uv; // UV coordinates for the current mesh (#V x 2)

+ 22 - 21
include/igl/opengl/ViewerCore.cpp

@@ -7,13 +7,14 @@
 // obtain one at http://mozilla.org/MPL/2.0/.
 // obtain one at http://mozilla.org/MPL/2.0/.
 
 
 #include "ViewerCore.h"
 #include "ViewerCore.h"
-#include <igl/quat_to_mat.h>
-#include <igl/snap_to_fixed_up.h>
-#include <igl/look_at.h>
-#include <igl/frustum.h>
-#include <igl/ortho.h>
-#include <igl/massmatrix.h>
-#include <igl/barycenter.h>
+#include "gl.h"
+#include "../quat_to_mat.h"
+#include "../snap_to_fixed_up.h"
+#include "../look_at.h"
+#include "../frustum.h"
+#include "../ortho.h"
+#include "../massmatrix.h"
+#include "../barycenter.h"
 #include <Eigen/Geometry>
 #include <Eigen/Geometry>
 #include <iostream>
 #include <iostream>
 
 
@@ -161,19 +162,19 @@ IGL_INLINE void igl::opengl::ViewerCore::draw(
   }
   }
 
 
   // Send transformations to the GPU
   // Send transformations to the GPU
-  GLint modeli = opengl.shader_mesh.uniform("model");
-  GLint viewi  = opengl.shader_mesh.uniform("view");
-  GLint proji  = opengl.shader_mesh.uniform("proj");
+  GLint modeli = glGetUniformLocation(opengl.shader_mesh,"model");
+  GLint viewi  = glGetUniformLocation(opengl.shader_mesh,"view");
+  GLint proji  = glGetUniformLocation(opengl.shader_mesh,"proj");
   glUniformMatrix4fv(modeli, 1, GL_FALSE, model.data());
   glUniformMatrix4fv(modeli, 1, GL_FALSE, model.data());
   glUniformMatrix4fv(viewi, 1, GL_FALSE, view.data());
   glUniformMatrix4fv(viewi, 1, GL_FALSE, view.data());
   glUniformMatrix4fv(proji, 1, GL_FALSE, proj.data());
   glUniformMatrix4fv(proji, 1, GL_FALSE, proj.data());
 
 
   // Light parameters
   // Light parameters
-  GLint specular_exponenti    = opengl.shader_mesh.uniform("specular_exponent");
-  GLint light_position_worldi = opengl.shader_mesh.uniform("light_position_world");
-  GLint lighting_factori      = opengl.shader_mesh.uniform("lighting_factor");
-  GLint fixed_colori          = opengl.shader_mesh.uniform("fixed_color");
-  GLint texture_factori       = opengl.shader_mesh.uniform("texture_factor");
+  GLint specular_exponenti    = glGetUniformLocation(opengl.shader_mesh,"specular_exponent");
+  GLint light_position_worldi = glGetUniformLocation(opengl.shader_mesh,"light_position_world");
+  GLint lighting_factori      = glGetUniformLocation(opengl.shader_mesh,"lighting_factor");
+  GLint fixed_colori          = glGetUniformLocation(opengl.shader_mesh,"fixed_color");
+  GLint texture_factori       = glGetUniformLocation(opengl.shader_mesh,"texture_factor");
 
 
   glUniform1f(specular_exponenti, shininess);
   glUniform1f(specular_exponenti, shininess);
   Vector3f rev_light = -1.*light_position;
   Vector3f rev_light = -1.*light_position;
@@ -239,9 +240,9 @@ IGL_INLINE void igl::opengl::ViewerCore::draw(
     if (data.lines.rows() > 0)
     if (data.lines.rows() > 0)
     {
     {
       opengl.bind_overlay_lines();
       opengl.bind_overlay_lines();
-      modeli = opengl.shader_overlay_lines.uniform("model");
-      viewi  = opengl.shader_overlay_lines.uniform("view");
-      proji  = opengl.shader_overlay_lines.uniform("proj");
+      modeli = glGetUniformLocation(opengl.shader_overlay_lines,"model");
+      viewi  = glGetUniformLocation(opengl.shader_overlay_lines,"view");
+      proji  = glGetUniformLocation(opengl.shader_overlay_lines,"proj");
 
 
       glUniformMatrix4fv(modeli, 1, GL_FALSE, model.data());
       glUniformMatrix4fv(modeli, 1, GL_FALSE, model.data());
       glUniformMatrix4fv(viewi, 1, GL_FALSE, view.data());
       glUniformMatrix4fv(viewi, 1, GL_FALSE, view.data());
@@ -256,9 +257,9 @@ IGL_INLINE void igl::opengl::ViewerCore::draw(
     if (data.points.rows() > 0)
     if (data.points.rows() > 0)
     {
     {
       opengl.bind_overlay_points();
       opengl.bind_overlay_points();
-      modeli = opengl.shader_overlay_points.uniform("model");
-      viewi  = opengl.shader_overlay_points.uniform("view");
-      proji  = opengl.shader_overlay_points.uniform("proj");
+      modeli = glGetUniformLocation(opengl.shader_overlay_points,"model");
+      viewi  = glGetUniformLocation(opengl.shader_overlay_points,"view");
+      proji  = glGetUniformLocation(opengl.shader_overlay_points,"proj");
 
 
       glUniformMatrix4fv(modeli, 1, GL_FALSE, model.data());
       glUniformMatrix4fv(modeli, 1, GL_FALSE, model.data());
       glUniformMatrix4fv(viewi, 1, GL_FALSE, view.data());
       glUniformMatrix4fv(viewi, 1, GL_FALSE, view.data());

+ 24 - 0
include/igl/opengl/bind_vertex_attrib_array.cpp

@@ -0,0 +1,24 @@
+#include "bind_vertex_attrib_array.h"
+
+IGL_INLINE GLint igl::opengl::bind_vertex_attrib_array(
+  const GLuint program_shader,
+  const std::string &name, 
+  GLuint bufferID, 
+  const Eigen::MatrixXf &M, 
+  bool refresh)
+{
+  GLint id = glGetAttribLocation(program_shader, name.c_str());
+  if (id < 0)
+    return id;
+  if (M.size() == 0)
+  {
+    glDisableVertexAttribArray(id);
+    return id;
+  }
+  glBindBuffer(GL_ARRAY_BUFFER, bufferID);
+  if (refresh)
+    glBufferData(GL_ARRAY_BUFFER, sizeof(float)*M.size(), M.data(), GL_DYNAMIC_DRAW);
+  glVertexAttribPointer(id, M.rows(), GL_FLOAT, GL_FALSE, 0, 0);
+  glEnableVertexAttribArray(id);
+  return id;
+}

+ 32 - 0
include/igl/opengl/bind_vertex_attrib_array.h

@@ -0,0 +1,32 @@
+#ifndef IGL_OPENGL_BIND_VERTEX_ATTRIB_ARRAY_H
+#define IGL_OPENGL_BIND_VERTEX_ATTRIB_ARRAY_H
+#include "gl.h"
+#include "../igl_inline.h"
+#include <Eigen/Core>
+#include <string>
+namespace igl
+{
+  namespace opengl
+  {
+    // Bind a per-vertex array attribute and refresh its contents from an Eigen
+    // matrix
+    //
+    // Inputs:
+    //   program_shader  id of shader program
+    //   name  name of attribute in vertex shader
+    //   bufferID  id of buffer to bind to
+    //   M  #V by dim matrix of per-vertex data
+    //   refresh  whether to actually call glBufferData or just bind the buffer
+    // Returns id of named attribute in shader
+    IGL_INLINE GLint bind_vertex_attrib_array(
+        const GLuint program_shader,
+        const std::string &name, 
+        GLuint bufferID, 
+        const Eigen::MatrixXf &M, 
+        bool refresh);
+  }
+}
+#ifndef IGL_STATIC_LIBRARY
+#include "bind_vertex_attrib_array.cpp"
+#endif
+#endif

+ 0 - 0
include/igl/viewer/TextRenderer_fonts.cpp.REMOVED.git-id → include/igl/opengl/glfw/TextRenderer_fonts.cpp.REMOVED.git-id


+ 0 - 1
include/igl/opengl/glfw/Viewer.h

@@ -21,7 +21,6 @@
 
 
 #include <igl/igl_inline.h>
 #include <igl/igl_inline.h>
 
 
-#include "../Shader.h"
 #include "../State.h"
 #include "../State.h"
 #include "../ViewerCore.h"
 #include "../ViewerCore.h"
 #include "../../ViewerData.h"
 #include "../../ViewerData.h"

+ 9 - 2
include/igl/opengl/load_shader.cpp

@@ -10,8 +10,14 @@
 // Copyright Denis Kovacs 4/10/08
 // Copyright Denis Kovacs 4/10/08
 #include "print_shader_info_log.h"
 #include "print_shader_info_log.h"
 #include <cstdio>
 #include <cstdio>
-IGL_INLINE GLuint igl::opengl::load_shader(const char *src,const GLenum type)
+IGL_INLINE GLuint igl::opengl::load_shader(
+  const std::string & src,const GLenum type)
 {
 {
+  if(src.empty())
+  {
+    return (GLuint) 0;
+  }
+
   GLuint s = glCreateShader(type);
   GLuint s = glCreateShader(type);
   if(s == 0)
   if(s == 0)
   {
   {
@@ -19,7 +25,8 @@ IGL_INLINE GLuint igl::opengl::load_shader(const char *src,const GLenum type)
     return 0;
     return 0;
   }
   }
   // Pass shader source string
   // Pass shader source string
-  glShaderSource(s, 1, &src, NULL);
+  const char *c = src.c_str();
+  glShaderSource(s, 1, &c, NULL);
   glCompileShader(s);
   glCompileShader(s);
   // Print info log (if any)
   // Print info log (if any)
   igl::opengl::print_shader_info_log(s);
   igl::opengl::print_shader_info_log(s);

+ 6 - 1
include/igl/opengl/load_shader.h

@@ -9,12 +9,14 @@
 #define IGL_OPENGL_LOAD_SHADER_H
 #define IGL_OPENGL_LOAD_SHADER_H
 #include "../igl_inline.h" 
 #include "../igl_inline.h" 
 #include "gl.h"
 #include "gl.h"
+#include <string>
 
 
 namespace igl
 namespace igl
 {
 {
   namespace opengl
   namespace opengl
   {
   {
     // Creates and compiles a shader from a given string
     // Creates and compiles a shader from a given string
+    //
     // Inputs:
     // Inputs:
     //   src  string containing GLSL shader code
     //   src  string containing GLSL shader code
     //   type  GLSL type of shader, one of:
     //   type  GLSL type of shader, one of:
@@ -22,7 +24,10 @@ namespace igl
     //     GL_FRAGMENT_SHADER
     //     GL_FRAGMENT_SHADER
     //     GL_GEOMETRY_SHADER
     //     GL_GEOMETRY_SHADER
     // Returns  index id of the newly created shader, 0 on error
     // Returns  index id of the newly created shader, 0 on error
-    IGL_INLINE GLuint load_shader(const char *src,const GLenum type);
+    // 
+    // Will immediately return 0 if src is empty.
+    IGL_INLINE GLuint load_shader(
+      const std::string & src,const GLenum type);
   }
   }
 }
 }
 
 

+ 0 - 173
include/igl/viewer/OpenGL_shader.cpp

@@ -1,173 +0,0 @@
-// This file is part of libigl, a simple c++ geometry processing library.
-//
-// Copyright (C) 2014 Wenzel Jacob <wenzel@inf.ethz.ch>
-//
-// 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/.
-
-#include "OpenGL_shader.h"
-
-#include <iostream>
-#include <fstream>
-
-IGL_INLINE bool igl::viewer::OpenGL_shader::init_from_files(
-  const std::string &vertex_shader_filename,
-  const std::string &fragment_shader_filename,
-  const std::string &fragment_data_name,
-  const std::string &geometry_shader_filename,
-  int geometry_shader_max_vertices)
-{
-  auto file_to_string = [](const std::string &filename)->std::string
-  {
-    std::ifstream t(filename);
-    return std::string((std::istreambuf_iterator<char>(t)),
-                        std::istreambuf_iterator<char>());
-  };
-
-  return init(
-    file_to_string(vertex_shader_filename),
-    file_to_string(fragment_shader_filename),
-    fragment_data_name,
-    file_to_string(geometry_shader_filename),
-    geometry_shader_max_vertices
- );
-}
-
-IGL_INLINE bool igl::viewer::OpenGL_shader::init(
-  const std::string &vertex_shader_string,
-  const std::string &fragment_shader_string,
-  const std::string &fragment_data_name,
-  const std::string &geometry_shader_string,
-  int geometry_shader_max_vertices)
-{
-  using namespace std;
-  vertex_shader = create_shader_helper(GL_VERTEX_SHADER, vertex_shader_string);
-  geometry_shader = create_shader_helper(GL_GEOMETRY_SHADER, geometry_shader_string);
-  fragment_shader = create_shader_helper(GL_FRAGMENT_SHADER, fragment_shader_string);
-
-  if (!vertex_shader || !fragment_shader)
-    return false;
-
-  program_shader = glCreateProgram();
-
-  glAttachShader(program_shader, vertex_shader);
-  glAttachShader(program_shader, fragment_shader);
-
-  if (geometry_shader)
-  {
-    glAttachShader(program_shader, geometry_shader);
-
-    /* This covers only basic cases and may need to be modified */
-    glProgramParameteri(program_shader, GL_GEOMETRY_INPUT_TYPE, GL_TRIANGLES);
-    glProgramParameteri(program_shader, GL_GEOMETRY_OUTPUT_TYPE, GL_TRIANGLES);
-    glProgramParameteri(program_shader, GL_GEOMETRY_VERTICES_OUT, geometry_shader_max_vertices);
-  }
-
-  glBindFragDataLocation(program_shader, 0, fragment_data_name.c_str());
-  glLinkProgram(program_shader);
-
-  GLint status;
-  glGetProgramiv(program_shader, GL_LINK_STATUS, &status);
-
-  if (status != GL_TRUE)
-  {
-    char buffer[512];
-    glGetProgramInfoLog(program_shader, 512, NULL, buffer);
-    cerr << "Linker error: " << endl << buffer << endl;
-    program_shader = 0;
-    return false;
-  }
-
-  return true;
-}
-
-IGL_INLINE void igl::viewer::OpenGL_shader::bind()
-{
-  glUseProgram(program_shader);
-}
-
-IGL_INLINE GLint igl::viewer::OpenGL_shader::attrib(const std::string &name) const
-{
-  return glGetAttribLocation(program_shader, name.c_str());
-}
-
-IGL_INLINE GLint igl::viewer::OpenGL_shader::uniform(const std::string &name) const
-{
-  return glGetUniformLocation(program_shader, name.c_str());
-}
-
-IGL_INLINE GLint igl::viewer::OpenGL_shader::bindVertexAttribArray(
-  const std::string &name, GLuint bufferID, const Eigen::MatrixXf &M, bool refresh) const
-{
-  GLint id = attrib(name);
-  if (id < 0)
-    return id;
-  if (M.size() == 0)
-  {
-    glDisableVertexAttribArray(id);
-    return id;
-  }
-  glBindBuffer(GL_ARRAY_BUFFER, bufferID);
-  if (refresh)
-    glBufferData(GL_ARRAY_BUFFER, sizeof(float)*M.size(), M.data(), GL_DYNAMIC_DRAW);
-  glVertexAttribPointer(id, M.rows(), GL_FLOAT, GL_FALSE, 0, 0);
-  glEnableVertexAttribArray(id);
-  return id;
-}
-
-IGL_INLINE void igl::viewer::OpenGL_shader::free()
-{
-  if (program_shader)
-  {
-    glDeleteProgram(program_shader);
-    program_shader = 0;
-  }
-  if (vertex_shader)
-  {
-    glDeleteShader(vertex_shader);
-    vertex_shader = 0;
-  }
-  if (fragment_shader)
-  {
-    glDeleteShader(fragment_shader);
-    fragment_shader = 0;
-  }
-  if (geometry_shader)
-  {
-    glDeleteShader(geometry_shader);
-    geometry_shader = 0;
-  }
-}
-
-IGL_INLINE GLuint igl::viewer::OpenGL_shader::create_shader_helper(GLint type, const std::string &shader_string)
-{
-  using namespace std;
-  if (shader_string.empty())
-    return (GLuint) 0;
-
-  GLuint id = glCreateShader(type);
-  const char *shader_string_const = shader_string.c_str();
-  glShaderSource(id, 1, &shader_string_const, NULL);
-  glCompileShader(id);
-
-  GLint status;
-  glGetShaderiv(id, GL_COMPILE_STATUS, &status);
-
-  if (status != GL_TRUE)
-  {
-    char buffer[512];
-    if (type == GL_VERTEX_SHADER)
-      cerr << "Vertex shader:" << endl;
-    else if (type == GL_FRAGMENT_SHADER)
-      cerr << "Fragment shader:" << endl;
-    else if (type == GL_GEOMETRY_SHADER)
-      cerr << "Geometry shader:" << endl;
-    cerr << shader_string << endl << endl;
-    glGetShaderInfoLog(id, 512, NULL, buffer);
-    cerr << "Error: " << endl << buffer << endl;
-    return (GLuint) 0;
-  }
-
-  return id;
-}

+ 0 - 98
include/igl/viewer/OpenGL_shader.h

@@ -1,98 +0,0 @@
-// This file is part of libigl, a simple c++ geometry processing library.
-//
-// Copyright (C) 2014 Wenzel Jacob <wenzel@inf.ethz.ch>
-//
-// 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/.
-
-#ifndef IGL_VIEWER_OPENGL_SHADER_H
-#define IGL_VIEWER_OPENGL_SHADER_H
-
-#include <igl/igl_inline.h>
-#include <string>
-#include <Eigen/Core>
-
-#ifdef _WIN32
-#  include <windows.h>
-#  undef max
-#  undef min
-#  undef DrawText
-#endif
-
-#ifndef __APPLE__
-#  define GLEW_STATIC
-#  include <GL/glew.h>
-#endif
-
-#ifdef __APPLE__
-#   include <OpenGL/gl3.h>
-#   define __gl_h_ /* Prevent inclusion of the old gl.h */
-#else
-#   include <GL/gl.h>
-#endif
-
-namespace igl
-{
-namespace viewer
-{
-
-// This class wraps an OpenGL program composed of three shaders
-// TODO: write documentation
-
-class OpenGL_shader
-{
-public:
-  typedef unsigned int GLuint;
-  typedef int GLint;
-
-  GLuint vertex_shader;
-  GLuint fragment_shader;
-  GLuint geometry_shader;
-  GLuint program_shader;
-
-  IGL_INLINE OpenGL_shader() : vertex_shader(0), fragment_shader(0),
-    geometry_shader(0), program_shader(0) { }
-
-  // Create a new shader from the specified source strings
-  IGL_INLINE bool init(const std::string &vertex_shader_string,
-    const std::string &fragment_shader_string,
-    const std::string &fragment_data_name,
-    const std::string &geometry_shader_string = "",
-    int geometry_shader_max_vertices = 3);
-
-  // Create a new shader from the specified files on disk
-  IGL_INLINE bool init_from_files(const std::string &vertex_shader_filename,
-    const std::string &fragment_shader_filename,
-    const std::string &fragment_data_name,
-    const std::string &geometry_shader_filename = "",
-    int geometry_shader_max_vertices = 3);
-
-  // Select this shader for subsequent draw calls
-  IGL_INLINE void bind();
-
-  // Release all OpenGL objects
-  IGL_INLINE void free();
-
-  // Return the OpenGL handle of a named shader attribute (-1 if it does not exist)
-  IGL_INLINE GLint attrib(const std::string &name) const;
-
-  // Return the OpenGL handle of a uniform attribute (-1 if it does not exist)
-  IGL_INLINE GLint uniform(const std::string &name) const;
-
-  // Bind a per-vertex array attribute and refresh its contents from an Eigen amtrix
-  IGL_INLINE GLint bindVertexAttribArray(const std::string &name, GLuint bufferID,
-    const Eigen::MatrixXf &M, bool refresh) const;
-
-  IGL_INLINE GLuint create_shader_helper(GLint type, const std::string &shader_string);
-
-};
-
-}
-}
-
-#ifndef IGL_STATIC_LIBRARY
-#  include "OpenGL_shader.cpp"
-#endif
-
-#endif

+ 0 - 488
include/igl/viewer/OpenGL_state.cpp

@@ -1,488 +0,0 @@
-// This file is part of libigl, a simple c++ geometry processing library.
-//
-// Copyright (C) 2014 Daniele Panozzo <daniele.panozzo@gmail.com>
-//
-// 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/.
-
-#include "OpenGL_state.h"
-#include "ViewerData.h"
-
-IGL_INLINE void igl::viewer::OpenGL_state::init_buffers()
-{
-  // Mesh: Vertex Array Object & Buffer objects
-  glGenVertexArrays(1, &vao_mesh);
-  glBindVertexArray(vao_mesh);
-  glGenBuffers(1, &vbo_V);
-  glGenBuffers(1, &vbo_V_normals);
-  glGenBuffers(1, &vbo_V_ambient);
-  glGenBuffers(1, &vbo_V_diffuse);
-  glGenBuffers(1, &vbo_V_specular);
-  glGenBuffers(1, &vbo_V_uv);
-  glGenBuffers(1, &vbo_F);
-  glGenTextures(1, &vbo_tex);
-
-  // Line overlay
-  glGenVertexArrays(1, &vao_overlay_lines);
-  glBindVertexArray(vao_overlay_lines);
-  glGenBuffers(1, &vbo_lines_F);
-  glGenBuffers(1, &vbo_lines_V);
-  glGenBuffers(1, &vbo_lines_V_colors);
-
-  // Point overlay
-  glGenVertexArrays(1, &vao_overlay_points);
-  glBindVertexArray(vao_overlay_points);
-  glGenBuffers(1, &vbo_points_F);
-  glGenBuffers(1, &vbo_points_V);
-  glGenBuffers(1, &vbo_points_V_colors);
-
-  dirty = ViewerData::DIRTY_ALL;
-}
-
-IGL_INLINE void igl::viewer::OpenGL_state::free_buffers()
-{
-  glDeleteVertexArrays(1, &vao_mesh);
-  glDeleteVertexArrays(1, &vao_overlay_lines);
-  glDeleteVertexArrays(1, &vao_overlay_points);
-
-  glDeleteBuffers(1, &vbo_V);
-  glDeleteBuffers(1, &vbo_V_normals);
-  glDeleteBuffers(1, &vbo_V_ambient);
-  glDeleteBuffers(1, &vbo_V_diffuse);
-  glDeleteBuffers(1, &vbo_V_specular);
-  glDeleteBuffers(1, &vbo_V_uv);
-  glDeleteBuffers(1, &vbo_F);
-  glDeleteBuffers(1, &vbo_lines_F);
-  glDeleteBuffers(1, &vbo_lines_V);
-  glDeleteBuffers(1, &vbo_lines_V_colors);
-  glDeleteBuffers(1, &vbo_points_F);
-  glDeleteBuffers(1, &vbo_points_V);
-  glDeleteBuffers(1, &vbo_points_V_colors);
-
-  glDeleteTextures(1, &vbo_tex);
-}
-
-IGL_INLINE void igl::viewer::OpenGL_state::set_data(const igl::viewer::ViewerData &data, bool invert_normals)
-{
-  bool per_corner_uv = (data.F_uv.rows() == data.F.rows());
-  bool per_corner_normals = (data.F_normals.rows() == 3 * data.F.rows());
-
-  dirty |= data.dirty;
-
-  if (!data.face_based)
-  {
-    if (!per_corner_uv)
-    {
-      // Vertex positions
-      if (dirty & ViewerData::DIRTY_POSITION)
-        V_vbo = (data.V.transpose()).cast<float>();
-
-      // Vertex normals
-      if (dirty & ViewerData::DIRTY_NORMAL)
-      {
-        V_normals_vbo = (data.V_normals.transpose()).cast<float>();
-        if (invert_normals)
-          V_normals_vbo = -V_normals_vbo;
-      }
-
-      // Per-vertex material settings
-      if (dirty & ViewerData::DIRTY_AMBIENT)
-        V_ambient_vbo = (data.V_material_ambient.transpose()).cast<float>();
-      if (dirty & ViewerData::DIRTY_DIFFUSE)
-        V_diffuse_vbo = (data.V_material_diffuse.transpose()).cast<float>();
-      if (dirty & ViewerData::DIRTY_SPECULAR)
-        V_specular_vbo = (data.V_material_specular.transpose()).cast<float>();
-
-      // Face indices
-      if (dirty & ViewerData::DIRTY_FACE)
-        F_vbo = (data.F.transpose()).cast<unsigned>();
-
-      // Texture coordinates
-      if (dirty & ViewerData::DIRTY_UV)
-        V_uv_vbo = (data.V_uv.transpose()).cast<float>();
-    }
-    else
-    {
-      // Per vertex properties with per corner UVs
-      if (dirty & ViewerData::DIRTY_POSITION)
-      {
-        V_vbo.resize(3,data.F.rows()*3);
-        for (unsigned i=0; i<data.F.rows();++i)
-          for (unsigned j=0;j<3;++j)
-            V_vbo.col(i*3+j) = data.V.row(data.F(i,j)).transpose().cast<float>();
-      }
-
-      if (dirty & ViewerData::DIRTY_AMBIENT)
-      {
-        V_ambient_vbo.resize(3,data.F.rows()*3);
-        for (unsigned i=0; i<data.F.rows();++i)
-          for (unsigned j=0;j<3;++j)
-            V_ambient_vbo.col (i*3+j) = data.V_material_ambient.row(data.F(i,j)).transpose().cast<float>();
-      }
-
-      if (dirty & ViewerData::DIRTY_DIFFUSE)
-      {
-        V_diffuse_vbo.resize(3,data.F.rows()*3);
-        for (unsigned i=0; i<data.F.rows();++i)
-          for (unsigned j=0;j<3;++j)
-            V_diffuse_vbo.col (i*3+j) = data.V_material_diffuse.row(data.F(i,j)).transpose().cast<float>();
-      }
-
-      if (dirty & ViewerData::DIRTY_SPECULAR)
-      {
-        V_specular_vbo.resize(3,data.F.rows()*3);
-        for (unsigned i=0; i<data.F.rows();++i)
-          for (unsigned j=0;j<3;++j)
-            V_specular_vbo.col(i*3+j) = data.V_material_specular.row(data.F(i,j)).transpose().cast<float>();
-      }
-
-      if (dirty & ViewerData::DIRTY_NORMAL)
-      {
-        V_normals_vbo.resize(3,data.F.rows()*3);
-        for (unsigned i=0; i<data.F.rows();++i)
-          for (unsigned j=0;j<3;++j)
-            V_normals_vbo.col (i*3+j) = data.V_normals.row(data.F(i,j)).transpose().cast<float>();
-
-        if (invert_normals)
-          V_normals_vbo = -V_normals_vbo;
-      }
-
-      if (dirty & ViewerData::DIRTY_FACE)
-      {
-        F_vbo.resize(3,data.F.rows());
-        for (unsigned i=0; i<data.F.rows();++i)
-          F_vbo.col(i) << i*3+0, i*3+1, i*3+2;
-      }
-
-      if (dirty & ViewerData::DIRTY_UV)
-      {
-        V_uv_vbo.resize(2,data.F.rows()*3);
-        for (unsigned i=0; i<data.F.rows();++i)
-          for (unsigned j=0;j<3;++j)
-            V_uv_vbo.col(i*3+j) = data.V_uv.row(data.F(i,j)).transpose().cast<float>();
-      }
-    }
-  }
-  else
-  {
-    if (dirty & ViewerData::DIRTY_POSITION)
-    {
-      V_vbo.resize(3,data.F.rows()*3);
-      for (unsigned i=0; i<data.F.rows();++i)
-        for (unsigned j=0;j<3;++j)
-          V_vbo.col(i*3+j) = data.V.row(data.F(i,j)).transpose().cast<float>();
-    }
-
-    if (dirty & ViewerData::DIRTY_AMBIENT)
-    {
-      V_ambient_vbo.resize(4,data.F.rows()*3);
-      for (unsigned i=0; i<data.F.rows();++i)
-        for (unsigned j=0;j<3;++j)
-          V_ambient_vbo.col (i*3+j) = data.F_material_ambient.row(i).transpose().cast<float>();
-    }
-
-    if (dirty & ViewerData::DIRTY_DIFFUSE)
-    {
-      V_diffuse_vbo.resize(4,data.F.rows()*3);
-      for (unsigned i=0; i<data.F.rows();++i)
-        for (unsigned j=0;j<3;++j)
-          V_diffuse_vbo.col (i*3+j) = data.F_material_diffuse.row(i).transpose().cast<float>();
-    }
-
-    if (dirty & ViewerData::DIRTY_SPECULAR)
-    {
-      V_specular_vbo.resize(4,data.F.rows()*3);
-      for (unsigned i=0; i<data.F.rows();++i)
-        for (unsigned j=0;j<3;++j)
-          V_specular_vbo.col(i*3+j) = data.F_material_specular.row(i).transpose().cast<float>();
-    }
-
-    if (dirty & ViewerData::DIRTY_NORMAL)
-    {
-      V_normals_vbo.resize(3,data.F.rows()*3);
-      for (unsigned i=0; i<data.F.rows();++i)
-        for (unsigned j=0;j<3;++j)
-          V_normals_vbo.col (i*3+j) =
-             per_corner_normals ?
-               data.F_normals.row(i*3+j).transpose().cast<float>() :
-               data.F_normals.row(i).transpose().cast<float>();
-
-      if (invert_normals)
-        V_normals_vbo = -V_normals_vbo;
-    }
-
-    if (dirty & ViewerData::DIRTY_FACE)
-    {
-      F_vbo.resize(3,data.F.rows());
-      for (unsigned i=0; i<data.F.rows();++i)
-        F_vbo.col(i) << i*3+0, i*3+1, i*3+2;
-    }
-
-    if (dirty & ViewerData::DIRTY_UV)
-    {
-        V_uv_vbo.resize(2,data.F.rows()*3);
-        for (unsigned i=0; i<data.F.rows();++i)
-          for (unsigned j=0;j<3;++j)
-            V_uv_vbo.col(i*3+j) = data.V_uv.row(per_corner_uv ? data.F_uv(i,j) : data.F(i,j)).transpose().cast<float>();
-    }
-  }
-
-  if (dirty & ViewerData::DIRTY_TEXTURE)
-  {
-    tex_u = data.texture_R.rows();
-    tex_v = data.texture_R.cols();
-    tex.resize(data.texture_R.size()*4);
-    for (unsigned i=0;i<data.texture_R.size();++i)
-    {
-      tex(i*4+0) = data.texture_R(i);
-      tex(i*4+1) = data.texture_G(i);
-      tex(i*4+2) = data.texture_B(i);
-      tex(i*4+3) = data.texture_A(i);
-    }
-  }
-
-  if (dirty & ViewerData::DIRTY_OVERLAY_LINES)
-  {
-    lines_V_vbo.resize(3, data.lines.rows()*2);
-    lines_V_colors_vbo.resize(3, data.lines.rows()*2);
-    lines_F_vbo.resize(1, data.lines.rows()*2);
-    for (unsigned i=0; i<data.lines.rows();++i)
-    {
-      lines_V_vbo.col(2*i+0) = data.lines.block<1, 3>(i, 0).transpose().cast<float>();
-      lines_V_vbo.col(2*i+1) = data.lines.block<1, 3>(i, 3).transpose().cast<float>();
-      lines_V_colors_vbo.col(2*i+0) = data.lines.block<1, 3>(i, 6).transpose().cast<float>();
-      lines_V_colors_vbo.col(2*i+1) = data.lines.block<1, 3>(i, 6).transpose().cast<float>();
-      lines_F_vbo(2*i+0) = 2*i+0;
-      lines_F_vbo(2*i+1) = 2*i+1;
-    }
-  }
-
-  if (dirty & ViewerData::DIRTY_OVERLAY_POINTS)
-  {
-    points_V_vbo.resize(3, data.points.rows());
-    points_V_colors_vbo.resize(3, data.points.rows());
-    points_F_vbo.resize(1, data.points.rows());
-    for (unsigned i=0; i<data.points.rows();++i)
-    {
-      points_V_vbo.col(i) = data.points.block<1, 3>(i, 0).transpose().cast<float>();
-      points_V_colors_vbo.col(i) = data.points.block<1, 3>(i, 3).transpose().cast<float>();
-      points_F_vbo(i) = i;
-    }
-  }
-}
-
-IGL_INLINE void igl::viewer::OpenGL_state::bind_mesh()
-{
-  glBindVertexArray(vao_mesh);
-  shader_mesh.bind();
-  shader_mesh.bindVertexAttribArray("position", vbo_V, V_vbo, dirty & ViewerData::DIRTY_POSITION);
-  shader_mesh.bindVertexAttribArray("normal", vbo_V_normals, V_normals_vbo, dirty & ViewerData::DIRTY_NORMAL);
-  shader_mesh.bindVertexAttribArray("Ka", vbo_V_ambient, V_ambient_vbo, dirty & ViewerData::DIRTY_AMBIENT);
-  shader_mesh.bindVertexAttribArray("Kd", vbo_V_diffuse, V_diffuse_vbo, dirty & ViewerData::DIRTY_DIFFUSE);
-  shader_mesh.bindVertexAttribArray("Ks", vbo_V_specular, V_specular_vbo, dirty & ViewerData::DIRTY_SPECULAR);
-  shader_mesh.bindVertexAttribArray("texcoord", vbo_V_uv, V_uv_vbo, dirty & ViewerData::DIRTY_UV);
-
-  glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vbo_F);
-  if (dirty & ViewerData::DIRTY_FACE)
-    glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(unsigned)*F_vbo.size(), F_vbo.data(), GL_DYNAMIC_DRAW);
-
-  glActiveTexture(GL_TEXTURE0);
-  glBindTexture(GL_TEXTURE_2D, vbo_tex);
-  if (dirty & ViewerData::DIRTY_TEXTURE)
-  {
-    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
-    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
-    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
-    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
-    glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
-    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tex_u, tex_v, 0, GL_RGBA, GL_UNSIGNED_BYTE, tex.data());
-  }
-  glUniform1i(shader_mesh.uniform("tex"), 0);
-  dirty &= ~ViewerData::DIRTY_MESH;
-}
-
-IGL_INLINE void igl::viewer::OpenGL_state::bind_overlay_lines()
-{
-  bool is_dirty = dirty & ViewerData::DIRTY_OVERLAY_LINES;
-
-  glBindVertexArray(vao_overlay_lines);
-  shader_overlay_lines.bind();
-  shader_overlay_lines.bindVertexAttribArray("position", vbo_lines_V, lines_V_vbo, is_dirty);
-  shader_overlay_lines.bindVertexAttribArray("color", vbo_lines_V_colors, lines_V_colors_vbo, is_dirty);
-
-  glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vbo_lines_F);
-  if (is_dirty)
-    glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(unsigned)*lines_F_vbo.size(), lines_F_vbo.data(), GL_DYNAMIC_DRAW);
-
-  dirty &= ~ViewerData::DIRTY_OVERLAY_LINES;
-}
-
-IGL_INLINE void igl::viewer::OpenGL_state::bind_overlay_points()
-{
-  bool is_dirty = dirty & ViewerData::DIRTY_OVERLAY_POINTS;
-
-  glBindVertexArray(vao_overlay_points);
-  shader_overlay_points.bind();
-  shader_overlay_points.bindVertexAttribArray("position", vbo_points_V, points_V_vbo, is_dirty);
-  shader_overlay_points.bindVertexAttribArray("color", vbo_points_V_colors, points_V_colors_vbo, is_dirty);
-
-  glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vbo_points_F);
-  if (is_dirty)
-    glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(unsigned)*points_F_vbo.size(), points_F_vbo.data(), GL_DYNAMIC_DRAW);
-
-  dirty &= ~ViewerData::DIRTY_OVERLAY_POINTS;
-}
-
-IGL_INLINE void igl::viewer::OpenGL_state::draw_mesh(bool solid)
-{
-  glPolygonMode(GL_FRONT_AND_BACK, solid ? GL_FILL : GL_LINE);
-
-  /* Avoid Z-buffer fighting between filled triangles & wireframe lines */
-  if (solid)
-  {
-    glEnable(GL_POLYGON_OFFSET_FILL);
-    glPolygonOffset(1.0, 1.0);
-  }
-  glDrawElements(GL_TRIANGLES, 3*F_vbo.cols(), GL_UNSIGNED_INT, 0);
-
-  glDisable(GL_POLYGON_OFFSET_FILL);
-  glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
-}
-
-IGL_INLINE void igl::viewer::OpenGL_state::draw_overlay_lines()
-{
-  glDrawElements(GL_LINES, lines_F_vbo.cols(), GL_UNSIGNED_INT, 0);
-}
-
-IGL_INLINE void igl::viewer::OpenGL_state::draw_overlay_points()
-{
-  glDrawElements(GL_POINTS, points_F_vbo.cols(), GL_UNSIGNED_INT, 0);
-}
-
-IGL_INLINE void igl::viewer::OpenGL_state::init()
-{
-  std::string mesh_vertex_shader_string =
-  "#version 150\n"
-  "uniform mat4 model;"
-  "uniform mat4 view;"
-  "uniform mat4 proj;"
-  "in vec3 position;"
-  "in vec3 normal;"
-  "out vec3 position_eye;"
-  "out vec3 normal_eye;"
-  "in vec4 Ka;"
-  "in vec4 Kd;"
-  "in vec4 Ks;"
-  "in vec2 texcoord;"
-  "out vec2 texcoordi;"
-  "out vec4 Kai;"
-  "out vec4 Kdi;"
-  "out vec4 Ksi;"
-
-  "void main()"
-  "{"
-  "  position_eye = vec3 (view * model * vec4 (position, 1.0));"
-  "  normal_eye = vec3 (view * model * vec4 (normal, 0.0));"
-  "  normal_eye = normalize(normal_eye);"
-  "  gl_Position = proj * vec4 (position_eye, 1.0);" //proj * view * model * vec4(position, 1.0);"
-  "  Kai = Ka;"
-  "  Kdi = Kd;"
-  "  Ksi = Ks;"
-  "  texcoordi = texcoord;"
-  "}";
-
-  std::string mesh_fragment_shader_string =
-  "#version 150\n"
-  "uniform mat4 model;"
-  "uniform mat4 view;"
-  "uniform mat4 proj;"
-  "uniform vec4 fixed_color;"
-  "in vec3 position_eye;"
-  "in vec3 normal_eye;"
-  "uniform vec3 light_position_world;"
-  "vec3 Ls = vec3 (1, 1, 1);"
-  "vec3 Ld = vec3 (1, 1, 1);"
-  "vec3 La = vec3 (1, 1, 1);"
-  "in vec4 Ksi;"
-  "in vec4 Kdi;"
-  "in vec4 Kai;"
-  "in vec2 texcoordi;"
-  "uniform sampler2D tex;"
-  "uniform float specular_exponent;"
-  "uniform float lighting_factor;"
-  "uniform float texture_factor;"
-  "out vec4 outColor;"
-  "void main()"
-  "{"
-  "vec3 Ia = La * vec3(Kai);"    // ambient intensity
-
-  "vec3 light_position_eye = vec3 (view * vec4 (light_position_world, 1.0));"
-  "vec3 vector_to_light_eye = light_position_eye - position_eye;"
-  "vec3 direction_to_light_eye = normalize (vector_to_light_eye);"
-  "float dot_prod = dot (direction_to_light_eye, normal_eye);"
-  "float clamped_dot_prod = max (dot_prod, 0.0);"
-  "vec3 Id = Ld * vec3(Kdi) * clamped_dot_prod;"    // Diffuse intensity
-
-  "vec3 reflection_eye = reflect (-direction_to_light_eye, normal_eye);"
-  "vec3 surface_to_viewer_eye = normalize (-position_eye);"
-  "float dot_prod_specular = dot (reflection_eye, surface_to_viewer_eye);"
-  "dot_prod_specular = float(abs(dot_prod)==dot_prod) * max (dot_prod_specular, 0.0);"
-  "float specular_factor = pow (dot_prod_specular, specular_exponent);"
-  "vec3 Is = Ls * vec3(Ksi) * specular_factor;"    // specular intensity
-  "vec4 color = vec4(lighting_factor * (Is + Id) + Ia + (1.0-lighting_factor) * vec3(Kdi),(Kai.a+Ksi.a+Kdi.a)/3);"
-  "outColor = mix(vec4(1,1,1,1), texture(tex, texcoordi), texture_factor) * color;"
-  "if (fixed_color != vec4(0.0)) outColor = fixed_color;"
-  "}";
-
-  std::string overlay_vertex_shader_string =
-  "#version 150\n"
-  "uniform mat4 model;"
-  "uniform mat4 view;"
-  "uniform mat4 proj;"
-  "in vec3 position;"
-  "in vec3 color;"
-  "out vec3 color_frag;"
-
-  "void main()"
-  "{"
-  "  gl_Position = proj * view * model * vec4 (position, 1.0);"
-  "  color_frag = color;"
-  "}";
-
-  std::string overlay_fragment_shader_string =
-  "#version 150\n"
-  "in vec3 color_frag;"
-  "out vec4 outColor;"
-  "void main()"
-  "{"
-  "  outColor = vec4(color_frag, 1.0);"
-  "}";
-
-  std::string overlay_point_fragment_shader_string =
-  "#version 150\n"
-  "in vec3 color_frag;"
-  "out vec4 outColor;"
-  "void main()"
-  "{"
-  "  if (length(gl_PointCoord - vec2(0.5)) > 0.5)"
-  "    discard;"
-  "  outColor = vec4(color_frag, 1.0);"
-  "}";
-
-  init_buffers();
-  shader_mesh.init(mesh_vertex_shader_string,
-      mesh_fragment_shader_string, "outColor");
-  shader_overlay_lines.init(overlay_vertex_shader_string,
-      overlay_fragment_shader_string, "outColor");
-  shader_overlay_points.init(overlay_vertex_shader_string,
-      overlay_point_fragment_shader_string, "outColor");
-}
-
-IGL_INLINE void igl::viewer::OpenGL_state::free()
-{
-  shader_mesh.free();
-  shader_overlay_lines.free();
-  shader_overlay_points.free();
-  free_buffers();
-}

+ 0 - 117
include/igl/viewer/OpenGL_state.h

@@ -1,117 +0,0 @@
-// This file is part of libigl, a simple c++ geometry processing library.
-//
-// Copyright (C) 2014 Daniele Panozzo <daniele.panozzo@gmail.com>
-//
-// 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/.
-#ifndef IGL_VIEWER_OPENGL_STATE_H
-#define IGL_VIEWER_OPENGL_STATE_H
-
-// Coverts mesh data inside a igl::viewer::ViewerData class in an OpenGL compatible format
-// The class includes a shader and the opengl calls to plot the data
-
-#include <igl/igl_inline.h>
-#include <igl/viewer/OpenGL_shader.h>
-#include <igl/viewer/ViewerData.h>
-
-namespace igl
-{
-namespace viewer
-{
-
-class OpenGL_state
-{
-public:
-  typedef unsigned int GLuint;
-
-  GLuint vao_mesh;
-  GLuint vao_overlay_lines;
-  GLuint vao_overlay_points;
-  OpenGL_shader shader_mesh;
-  OpenGL_shader shader_overlay_lines;
-  OpenGL_shader shader_overlay_points;
-
-  GLuint vbo_V; // Vertices of the current mesh (#V x 3)
-  GLuint vbo_V_uv; // UV coordinates for the current mesh (#V x 2)
-  GLuint vbo_V_normals; // Vertices of the current mesh (#V x 3)
-  GLuint vbo_V_ambient; // Ambient material  (#V x 3)
-  GLuint vbo_V_diffuse; // Diffuse material  (#V x 3)
-  GLuint vbo_V_specular; // Specular material  (#V x 3)
-
-  GLuint vbo_F; // Faces of the mesh (#F x 3)
-  GLuint vbo_tex; // Texture
-
-  GLuint vbo_lines_F;         // Indices of the line overlay
-  GLuint vbo_lines_V;         // Vertices of the line overlay
-  GLuint vbo_lines_V_colors;  // Color values of the line overlay
-  GLuint vbo_points_F;        // Indices of the point overlay
-  GLuint vbo_points_V;        // Vertices of the point overlay
-  GLuint vbo_points_V_colors; // Color values of the point overlay
-
-  // Temporary copy of the content of each VBO
-  Eigen::MatrixXf V_vbo;
-  Eigen::MatrixXf V_normals_vbo;
-  Eigen::MatrixXf V_ambient_vbo;
-  Eigen::MatrixXf V_diffuse_vbo;
-  Eigen::MatrixXf V_specular_vbo;
-  Eigen::MatrixXf V_uv_vbo;
-  Eigen::MatrixXf lines_V_vbo;
-  Eigen::MatrixXf lines_V_colors_vbo;
-  Eigen::MatrixXf points_V_vbo;
-  Eigen::MatrixXf points_V_colors_vbo;
-
-  int tex_u;
-  int tex_v;
-  Eigen::Matrix<char,Eigen::Dynamic,1> tex;
-
-  Eigen::Matrix<unsigned, Eigen::Dynamic, Eigen::Dynamic> F_vbo;
-  Eigen::Matrix<unsigned, Eigen::Dynamic, Eigen::Dynamic> lines_F_vbo;
-  Eigen::Matrix<unsigned, Eigen::Dynamic, Eigen::Dynamic> points_F_vbo;
-
-  // Marks dirty buffers that need to be uploaded to OpenGL
-  uint32_t dirty;
-
-  // Initialize shaders and buffers
-  IGL_INLINE void init();
-
-  // Release all resources
-  IGL_INLINE void free();
-
-  // Create a new set of OpenGL buffer objects
-  IGL_INLINE void init_buffers();
-
-  // Update contents from a 'Data' instance
-  IGL_INLINE void set_data(const igl::viewer::ViewerData &data, bool invert_normals);
-
-  // Bind the underlying OpenGL buffer objects for subsequent mesh draw calls
-  IGL_INLINE void bind_mesh();
-
-  /// Draw the currently buffered mesh (either solid or wireframe)
-  IGL_INLINE void draw_mesh(bool solid);
-
-  // Bind the underlying OpenGL buffer objects for subsequent line overlay draw calls
-  IGL_INLINE void bind_overlay_lines();
-
-  /// Draw the currently buffered line overlay
-  IGL_INLINE void draw_overlay_lines();
-
-  // Bind the underlying OpenGL buffer objects for subsequent point overlay draw calls
-  IGL_INLINE void bind_overlay_points();
-
-  /// Draw the currently buffered point overlay
-  IGL_INLINE void draw_overlay_points();
-
-  // Release the OpenGL buffer objects
-  IGL_INLINE void free_buffers();
-
-};
-
-}
-}
-
-#ifndef IGL_STATIC_LIBRARY
-#  include "OpenGL_state.cpp"
-#endif
-
-#endif

+ 0 - 33
include/igl/viewer/TODOs.txt

@@ -1,33 +0,0 @@
-- `align_and_center_object` continues to zoom out on repeated calls
-- trackball_angle should be a quaternion
-- data.lines, data.points should not concatenate colors with coordinates
-- snap to canonical recenters origin but trackball does not
-- rewrite in libigl style
-- separate various class into their own .h/.cpp pairs
-- remove use of double underscores (http://stackoverflow.com/a/224420/148668)
-- document inputs and outputs to all functions
-- document all member fields
-- document all classes
-- light direction is backwards
-- remove global variables (not threadsafe)
-- encapsulate (in igl namespace) and move static/global functions, use lambdas?
-- preface macros with "IGL_"
-- trackball mouseup captured by tweakbar
-- zoom with pan rather than scaling
-- refresh draw while resizing
-- use constructor initializer list rather than complicated constructor
-- support per-element alpha values
-+ snap to canonical view key shortcut is not working
-+ resize TwBar with window
-+ trackball should be able to drag over TwBar
-+ don't zoom on horizontal scale
-+ remove global `using namespace std`
-+ remove `#define IGL_HEADER_ONLY`
-+ guard `#undef max`
-+ fix all -Wsign-compare
-+ missing `#include <iostream>`
-+ missing `#include <fstream>`
-+ fix all -Wunused-but-set-variable
-+ makefile for libiglviewer.a
-+ Viewer.h should include Viewer.cpp
-+ depth test for overlays cannot be disabled

+ 0 - 94
include/igl/viewer/TextRenderer.cpp

@@ -1,94 +0,0 @@
-// This file is part of libigl, a simple c++ geometry processing library.
-//
-// Copyright (C) 2014 Wenzel Jacob <wenzel@inf.ethz.ch>
-//
-// 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>
-
-#include <nanogui/opengl.h>
-#include <nanovg.h>
-
-#include <Eigen/Dense>
-
-#define NANOVG_GL3
-#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);
-}
-#endif

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

@@ -1,56 +0,0 @@
-// This file is part of libigl, a simple c++ geometry processing library.
-//
-// Copyright (C) 2014 Wenzel Jacob <wenzel@inf.ethz.ch>
-//
-// 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/.
-#ifndef IGL_VIEWER_TEXT_RENDERER_H
-#define IGL_VIEWER_TEXT_RENDERER_H
-#ifdef IGL_VIEWER_WITH_NANOGUI
-
-#include <Eigen/Dense>
-
-#include <igl/igl_inline.h>
-#include <map>
-
-struct NVGcontext;
-
-namespace igl
-{
-namespace viewer
-{
-
-  class TextRenderer
-  {
-  public:
-    IGL_INLINE TextRenderer();
-
-    IGL_INLINE virtual int Init();
-    IGL_INLINE virtual int Shut();
-
-    IGL_INLINE void BeginDraw(const Eigen::Matrix4f &view,const Eigen::Matrix4f &proj,
-      const Eigen::Vector4f &_viewport,float _object_scale);
-
-    IGL_INLINE void EndDraw();
-
-    IGL_INLINE void DrawText(Eigen::Vector3d pos,Eigen::Vector3d normal,const std::string &text);
-
-  protected:
-    std::map<std::string,void *> m_textObjects;
-    Eigen::Matrix4f view_matrix,proj_matrix;
-    Eigen::Vector4f viewport;
-    float object_scale;
-    float mPixelRatio;
-    NVGcontext *ctx;
-  };
-
-}
-}
-
-#ifndef IGL_STATIC_LIBRARY
-#  include "TextRenderer.cpp"
-#endif
-
-#endif
-#endif

+ 0 - 38
include/igl/viewer/TextRenderer_fonts.h

@@ -1,38 +0,0 @@
-// This file is part of libigl, a simple c++ geometry processing library.
-//
-// Copyright (C) 2014 Wenzel Jacob <wenzel@inf.ethz.ch>
-//
-// 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/.
-
-#ifndef IGL_TEXT_RENDERER_FONTS_H
-#define IGL_TEXT_RENDERER_FONTS_H
-
-#include <stdint.h>
-
-#ifndef IGL_STATIC_LIBRARY
-namespace
-{
-#endif
-  extern uint8_t igl_entypo_ttf[];
-  extern uint32_t igl_entypo_ttf_size;
-
-  extern uint8_t igl_roboto_bold_ttf[];
-  extern uint32_t igl_roboto_bold_ttf_size;
-
-  extern uint8_t igl_roboto_regular_ttf[];
-  extern uint32_t igl_roboto_regular_ttf_size;
-
-#ifndef IGL_STATIC_LIBRARY
-}
-#endif
-
-#ifndef IGL_STATIC_LIBRARY
-namespace
-{
-  #include "TextRenderer_fonts.cpp"
-}
-#endif
-
-#endif

+ 0 - 1031
include/igl/viewer/Viewer.cpp

@@ -1,1031 +0,0 @@
-// This file is part of libigl, a simple c++ geometry processing library.
-//
-// Copyright (C) 2014 Daniele Panozzo <daniele.panozzo@gmail.com>
-//
-// 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/.
-
-// Must defined this before including Viewer.h
-#define IGL_VIEWER_VIEWER_CPP
-#include "Viewer.h"
-
-#ifdef _WIN32
-#  include <windows.h>
-#  undef max
-#  undef min
-#endif
-
-#include <chrono>
-#include <thread>
-
-#ifndef __APPLE__
-#  define GLEW_STATIC
-#  include <GL/glew.h>
-#endif
-
-#ifdef __APPLE__
-#   include <OpenGL/gl3.h>
-#   define __gl_h_ /* Prevent inclusion of the old gl.h */
-#else
-#   include <GL/gl.h>
-#endif
-
-#include <Eigen/LU>
-
-//#define GLFW_INCLUDE_GLU
-#if defined(__APPLE__)
-#define GLFW_INCLUDE_GLCOREARB
-#else
-#define GL_GLEXT_PROTOTYPES
-#endif
-
-#include <GLFW/glfw3.h>
-
-#include <cmath>
-#include <cstdio>
-#include <sstream>
-#include <iomanip>
-#include <iostream>
-#include <fstream>
-#include <algorithm>
-#include <limits>
-#include <cassert>
-
-#ifdef IGL_VIEWER_WITH_NANOGUI
-#  include <nanogui/formhelper.h>
-#  include <nanogui/screen.h>
-#endif
-
-#include <igl/project.h>
-#include <igl/get_seconds.h>
-#include <igl/readOBJ.h>
-#include <igl/readOFF.h>
-#include <igl/adjacency_list.h>
-#include <igl/writeOBJ.h>
-#include <igl/writeOFF.h>
-#include <igl/massmatrix.h>
-#include <igl/file_dialog_open.h>
-#include <igl/file_dialog_save.h>
-#include <igl/quat_mult.h>
-#include <igl/axis_angle_to_quat.h>
-#include <igl/trackball.h>
-#include <igl/two_axis_valuator_fixed_up.h>
-#include <igl/snap_to_canonical_view_quat.h>
-#include <igl/unproject.h>
-
-#ifdef ENABLE_SERIALIZATION
-#include <igl/serialize.h>
-#endif
-
-// Internal global variables used for glfw event handling
-static igl::viewer::Viewer * __viewer;
-static double highdpi = 1;
-static double scroll_x = 0;
-static double scroll_y = 0;
-
-static void glfw_mouse_press(GLFWwindow* window, int button, int action, int modifier)
-{
-  bool tw_used =
-#ifdef IGL_VIEWER_WITH_NANOGUI
-    __viewer->screen->mouseButtonCallbackEvent(button,action,modifier);
-#else
-    false;
-#endif
-
-  igl::viewer::Viewer::MouseButton mb;
-
-  if (button == GLFW_MOUSE_BUTTON_1)
-    mb = igl::viewer::Viewer::MouseButton::Left;
-  else if (button == GLFW_MOUSE_BUTTON_2)
-    mb = igl::viewer::Viewer::MouseButton::Right;
-  else //if (button == GLFW_MOUSE_BUTTON_3)
-    mb = igl::viewer::Viewer::MouseButton::Middle;
-
-  if (action == GLFW_PRESS)
-  {
-    if(!tw_used)
-    {
-      __viewer->mouse_down(mb,modifier);
-    }
-  } else
-  {
-    // Always call mouse_up on up
-    __viewer->mouse_up(mb,modifier);
-  }
-
-}
-
-static void glfw_error_callback(int error, const char* description)
-{
-  fputs(description, stderr);
-}
-
-static void glfw_char_mods_callback(GLFWwindow* window, unsigned int codepoint, int modifier)
-{
-  // 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);
-  }
-}
-
-static void glfw_key_callback(GLFWwindow* window, int key, int scancode, int action, int modifier)
-{
-  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);
-    else if(action == GLFW_RELEASE)
-      __viewer->key_up(key, modifier);
-  }
-}
-
-static void glfw_window_size(GLFWwindow* window, int width, int height)
-{
-  int w = width*highdpi;
-  int h = height*highdpi;
-
-  __viewer->resize(w, h);
-
-  // TODO: repositioning of the nanogui
-}
-
-static void glfw_mouse_move(GLFWwindow* window, double x, double y)
-{
-  if(
-#ifdef IGL_VIEWER_WITH_NANOGUI
-      __viewer->screen->cursorPosCallbackEvent(x,y) == false &&
-#endif
-      true
-    )
-  {
-    __viewer->mouse_move(x*highdpi, y*highdpi);
-  }
-}
-
-static void glfw_mouse_scroll(GLFWwindow* window, double x, double y)
-{
-  using namespace std;
-  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
-{
-namespace viewer
-{
-  IGL_INLINE void Viewer::init()
-  {
-#ifdef IGL_VIEWER_WITH_NANOGUI
-    using namespace nanogui;
-
-    ngui->setFixedSize(Eigen::Vector2i(60,20));
-
-    // Create nanogui widgets
-    nanogui::Window *window = ngui->addWindow(Eigen::Vector2i(10,10),"libIGL-Viewer");
-
-    // ---------------------- LOADING ----------------------
-
-  #ifdef ENABLE_SERIALIZATION
-    ngui->addGroup("Workspace");
-    ngui->addButton("Load",[&](){this->load_scene();});
-    ngui->addButton("Save",[&](){this->save_scene();});
-  #endif
-
-  #ifdef ENABLE_IO
-    ngui->addGroup("Mesh");
-    ngui->addButton("Load",[&](){this->open_dialog_load_mesh();});
-    ngui->addButton("Save",[&](){this->open_dialog_save_mesh();});
-  #endif
-
-    ngui->addGroup("Viewing Options");
-    ngui->addButton("Center object",[&](){this->core.align_camera_center(this->data.V,this->data.F);});
-    ngui->addButton("Snap canonical view",[&]()
-    {
-      this->snap_to_canonical_quaternion();
-    });
-    ngui->addVariable("Zoom", core.camera_zoom);
-    ngui->addVariable("Orthographic view", core.orthographic);
-
-    ngui->addGroup("Draw options");
-
-    ngui->addVariable<bool>("Face-based", [&](bool checked)
-    {
-      this->data.set_face_based(checked);
-    },[&]()
-    {
-      return this->data.face_based;
-    });
-
-    ngui->addVariable("Show texture",core.show_texture);
-
-    ngui->addVariable<bool>("Invert normals",[&](bool checked)
-    {
-      this->data.dirty |= ViewerData::DIRTY_NORMAL;
-      this->core.invert_normals = checked;
-    },[&]()
-    {
-      return this->core.invert_normals;
-    });
-
-    ngui->addVariable("Show overlay", core.show_overlay);
-    ngui->addVariable("Show overlay depth", core.show_overlay_depth);
-    ngui->addVariable("Background", (nanogui::Color &) core.background_color);
-    ngui->addVariable("Line color", (nanogui::Color &) core.line_color);
-    ngui->addVariable("Shininess", core.shininess);
-
-    ngui->addGroup("Overlays");
-    ngui->addVariable("Wireframe", core.show_lines);
-    ngui->addVariable("Fill", core.show_faces);
-    ngui->addVariable("Show vertex labels", core.show_vertid);
-    ngui->addVariable("Show faces labels", core.show_faceid);
-
-    screen->setVisible(true);
-    screen->performLayout();
-#endif
-
-    core.init();
-
-    if (callback_init)
-      if (callback_init(*this))
-        return;
-
-    init_plugins();
-  }
-
-  IGL_INLINE Viewer::Viewer()
-  {
-#ifdef IGL_VIEWER_WITH_NANOGUI
-    ngui = nullptr;
-    screen = nullptr;
-#endif
-
-    // Temporary variables initialization
-    down = false;
-    hack_never_moved = true;
-    scroll_position = 0.0f;
-
-    // Per face
-    data.set_face_based(false);
-
-    // C-style callbacks
-    callback_init         = nullptr;
-    callback_pre_draw     = nullptr;
-    callback_post_draw    = nullptr;
-    callback_mouse_down   = nullptr;
-    callback_mouse_up     = nullptr;
-    callback_mouse_move   = nullptr;
-    callback_mouse_scroll = nullptr;
-    callback_key_down     = nullptr;
-    callback_key_up       = nullptr;
-
-    callback_init_data          = nullptr;
-    callback_pre_draw_data      = nullptr;
-    callback_post_draw_data     = nullptr;
-    callback_mouse_down_data    = nullptr;
-    callback_mouse_up_data      = nullptr;
-    callback_mouse_move_data    = nullptr;
-    callback_mouse_scroll_data  = nullptr;
-    callback_key_down_data      = nullptr;
-    callback_key_up_data        = nullptr;
-
-#ifndef IGL_VIEWER_VIEWER_QUIET
-    const std::string usage(R"(igl::viewer::Viewer usage:
-  [drag]  Rotate scene
-  A,a     Toggle animation (tight draw loop)
-  F,f     Toggle face based
-  I,i     Toggle invert normals
-  L,l     Toggle wireframe
-  O,o     Toggle orthographic/perspective projection
-  T,t     Toggle filled faces
-  Z       Snap to canonical view
-  [,]     Toggle between rotation control types (e.g. trackball, two-axis
-          valuator with fixed up))"
-#ifdef IGL_VIEWER_WITH_NANOGUI
-		R"(
-  ;       Toggle vertex labels
-  :       Toggle face labels)"
-#endif
-);
-    std::cout<<usage<<std::endl;
-#endif
-  }
-
-  IGL_INLINE void Viewer::init_plugins()
-  {
-    // Init all plugins
-    for (unsigned int i = 0; i<plugins.size(); ++i)
-    {
-      plugins[i]->init(this);
-    }
-  }
-
-  IGL_INLINE Viewer::~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)
-  {
-    std::string mesh_file_name_string = std::string(mesh_file_name);
-
-    // first try to load it with a plugin
-    for (unsigned int i = 0; i<plugins.size(); ++i)
-    {
-      if (plugins[i]->load(mesh_file_name_string))
-      {
-        return true;
-      }
-    }
-
-    data.clear();
-
-    size_t last_dot = mesh_file_name_string.rfind('.');
-    if (last_dot == std::string::npos)
-    {
-      printf("Error: No file extension found in %s\n",mesh_file_name);
-      return false;
-    }
-
-    std::string extension = mesh_file_name_string.substr(last_dot+1);
-
-    if (extension == "off" || extension =="OFF")
-    {
-      Eigen::MatrixXd V;
-      Eigen::MatrixXi F;
-      if (!igl::readOFF(mesh_file_name_string, V, F))
-        return false;
-      data.set_mesh(V,F);
-    }
-    else if (extension == "obj" || extension =="OBJ")
-    {
-      Eigen::MatrixXd corner_normals;
-      Eigen::MatrixXi fNormIndices;
-
-      Eigen::MatrixXd UV_V;
-      Eigen::MatrixXi UV_F;
-      Eigen::MatrixXd V;
-      Eigen::MatrixXi F;
-
-      if (!(
-            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);
-
-    }
-    else
-    {
-      // unrecognized file type
-      printf("Error: %s is not a recognized file type.\n",extension.c_str());
-      return false;
-    }
-
-    data.compute_normals();
-    data.uniform_colors(Eigen::Vector3d(51.0/255.0,43.0/255.0,33.3/255.0),
-                   Eigen::Vector3d(255.0/255.0,228.0/255.0,58.0/255.0),
-                   Eigen::Vector3d(255.0/255.0,235.0/255.0,80.0/255.0));
-    if (data.V_uv.rows() == 0)
-    {
-      data.grid_texture();
-    }
-
-    core.align_camera_center(data.V,data.F);
-
-    for (unsigned int i = 0; i<plugins.size(); ++i)
-      if (plugins[i]->post_load())
-        return true;
-
-    return true;
-  }
-
-  IGL_INLINE bool Viewer::save_mesh_to_file(const char* mesh_file_name)
-  {
-    std::string mesh_file_name_string(mesh_file_name);
-
-    // first try to load it with a plugin
-    for (unsigned int i = 0; i<plugins.size(); ++i)
-      if (plugins[i]->save(mesh_file_name_string))
-        return true;
-
-    size_t last_dot = mesh_file_name_string.rfind('.');
-    if (last_dot == std::string::npos)
-    {
-      // No file type determined
-      printf("Error: No file extension found in %s\n",mesh_file_name);
-      return false;
-    }
-    std::string extension = mesh_file_name_string.substr(last_dot+1);
-    if (extension == "off" || extension =="OFF")
-    {
-      return igl::writeOFF(mesh_file_name_string,data.V,data.F);
-    }
-    else if (extension == "obj" || extension =="OBJ")
-    {
-      Eigen::MatrixXd corner_normals;
-      Eigen::MatrixXi fNormIndices;
-
-      Eigen::MatrixXd UV_V;
-      Eigen::MatrixXi UV_F;
-
-      return igl::writeOBJ(mesh_file_name_string, data.V,
-          data.F, corner_normals, fNormIndices, UV_V, UV_F);
-    }
-    else
-    {
-      // unrecognized file type
-      printf("Error: %s is not a recognized file type.\n",extension.c_str());
-      return false;
-    }
-    return true;
-  }
-
-  IGL_INLINE bool Viewer::key_pressed(unsigned int unicode_key,int modifiers)
-  {
-    if (callback_key_pressed)
-      if (callback_key_pressed(*this,unicode_key,modifiers))
-        return true;
-
-    for (unsigned int i = 0; i<plugins.size(); ++i)
-    {
-      if (plugins[i]->key_pressed(unicode_key, modifiers))
-      {
-        return true;
-      }
-    }
-
-    switch(unicode_key)
-    {
-      case 'A':
-      case 'a':
-      {
-        core.is_animating = !core.is_animating;
-        return true;
-      }
-      case 'F':
-      case 'f':
-      {
-        data.set_face_based(!data.face_based);
-        return true;
-      }
-      case 'I':
-      case 'i':
-      {
-        data.dirty |= ViewerData::DIRTY_NORMAL;
-        core.invert_normals = !core.invert_normals;
-        return true;
-      }
-      case 'L':
-      case 'l':
-      {
-        core.show_lines = !core.show_lines;
-        return true;
-      }
-      case 'O':
-      case 'o':
-      {
-        core.orthographic = !core.orthographic;
-        return true;
-      }
-      case 'T':
-      case 't':
-      {
-        core.show_faces = !core.show_faces;
-        return true;
-      }
-      case 'Z':
-      {
-        snap_to_canonical_quaternion();
-        return true;
-      }
-      case '[':
-      case ']':
-      {
-        if(core.rotation_type == ViewerCore::ROTATION_TYPE_TRACKBALL)
-        {
-          core.set_rotation_type(
-            ViewerCore::ROTATION_TYPE_TWO_AXIS_VALUATOR_FIXED_UP);
-        }else
-        {
-          core.set_rotation_type(ViewerCore::ROTATION_TYPE_TRACKBALL);
-        }
-        return true;
-      }
-#ifdef IGL_VIEWER_WITH_NANOGUI
-      case ';':
-        core.show_vertid = !core.show_vertid;
-        return true;
-      case ':':
-        core.show_faceid = !core.show_faceid;
-        return true;
-#endif
-      default: break;//do nothing
-    }
-    return false;
-  }
-
-  IGL_INLINE bool Viewer::key_down(int key,int modifiers)
-  {
-    if (callback_key_down)
-      if (callback_key_down(*this,key,modifiers))
-        return true;
-    for (unsigned int i = 0; i<plugins.size(); ++i)
-      if (plugins[i]->key_down(key, modifiers))
-        return true;
-    return false;
-  }
-
-  IGL_INLINE bool Viewer::key_up(int key,int modifiers)
-  {
-    if (callback_key_up)
-      if (callback_key_up(*this,key,modifiers))
-        return true;
-
-    for (unsigned int i = 0; i<plugins.size(); ++i)
-      if (plugins[i]->key_up(key, modifiers))
-        return true;
-
-    return false;
-  }
-
-  IGL_INLINE bool Viewer::mouse_down(MouseButton button,int modifier)
-  {
-    // Remember mouse location at down even if used by callback/plugin
-    down_mouse_x = current_mouse_x;
-    down_mouse_y = current_mouse_y;
-
-    if (callback_mouse_down)
-      if (callback_mouse_down(*this,static_cast<int>(button),modifier))
-        return true;
-
-    for (unsigned int i = 0; i<plugins.size(); ++i)
-      if(plugins[i]->mouse_down(static_cast<int>(button),modifier))
-        return true;
-
-    down = true;
-
-    down_translation = core.model_translation;
-
-
-    // Initialization code for the trackball
-    Eigen::RowVector3d center;
-    if (data.V.rows() == 0)
-    {
-      center << 0,0,0;
-    }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);
-    down_mouse_z = coord[2];
-    down_rotation = core.trackball_angle;
-
-    mouse_mode = MouseMode::Rotation;
-
-    switch (button)
-    {
-      case MouseButton::Left:
-        mouse_mode = MouseMode::Rotation;
-        break;
-
-      case MouseButton::Right:
-        mouse_mode = MouseMode::Translation;
-        break;
-
-      default:
-        mouse_mode = MouseMode::None;
-        break;
-    }
-
-    return true;
-  }
-
-  IGL_INLINE bool Viewer::mouse_up(MouseButton button,int modifier)
-  {
-    down = false;
-
-    if (callback_mouse_up)
-      if (callback_mouse_up(*this,static_cast<int>(button),modifier))
-        return true;
-
-    for (unsigned int i = 0; i<plugins.size(); ++i)
-      if(plugins[i]->mouse_up(static_cast<int>(button),modifier))
-          return true;
-
-    mouse_mode = MouseMode::None;
-
-    return true;
-  }
-
-  IGL_INLINE bool Viewer::mouse_move(int mouse_x,int mouse_y)
-  {
-    if(hack_never_moved)
-    {
-      down_mouse_x = mouse_x;
-      down_mouse_y = mouse_y;
-      hack_never_moved = false;
-    }
-    current_mouse_x = mouse_x;
-    current_mouse_y = mouse_y;
-
-    if (callback_mouse_move)
-      if (callback_mouse_move(*this,mouse_x,mouse_y))
-        return true;
-
-    for (unsigned int i = 0; i<plugins.size(); ++i)
-      if (plugins[i]->mouse_move(mouse_x, mouse_y))
-        return true;
-
-    if (down)
-    {
-      switch (mouse_mode)
-      {
-        case MouseMode::Rotation:
-        {
-          switch(core.rotation_type)
-          {
-            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);
-              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);
-              break;
-          }
-          //Eigen::Vector4f snapq = core.trackball_angle;
-
-          break;
-        }
-
-        case MouseMode::Translation:
-        {
-          //translation
-          Eigen::Vector3f pos1 = igl::unproject(Eigen::Vector3f(mouse_x, core.viewport[3] - mouse_y, down_mouse_z), (core.view * core.model).eval(), core.proj, core.viewport);
-          Eigen::Vector3f pos0 = igl::unproject(Eigen::Vector3f(down_mouse_x, core.viewport[3] - down_mouse_y, down_mouse_z), (core.view * core.model).eval(), core.proj, core.viewport);
-
-          Eigen::Vector3f diff = pos1 - pos0;
-          core.model_translation = down_translation + Eigen::Vector3f(diff[0],diff[1],diff[2]);
-
-          break;
-        }
-        case MouseMode::Zoom:
-        {
-          float delta = 0.001f * (mouse_x - down_mouse_x + mouse_y - down_mouse_y);
-          core.camera_zoom *= 1 + delta;
-          down_mouse_x = mouse_x;
-          down_mouse_y = mouse_y;
-          break;
-        }
-
-        default:
-          break;
-      }
-    }
-    return true;
-  }
-
-  IGL_INLINE bool Viewer::mouse_scroll(float delta_y)
-  {
-    scroll_position += delta_y;
-
-    if (callback_mouse_scroll)
-      if (callback_mouse_scroll(*this,delta_y))
-        return true;
-
-    for (unsigned int i = 0; i<plugins.size(); ++i)
-      if (plugins[i]->mouse_scroll(delta_y))
-        return true;
-
-    // Only zoom if there's actually a change
-    if(delta_y != 0)
-    {
-      float mult = (1.0+((delta_y>0)?1.:-1.)*0.05);
-      const float min_zoom = 0.1f;
-      core.camera_zoom = (core.camera_zoom * mult > min_zoom ? core.camera_zoom * mult : min_zoom);
-    }
-    return true;
-  }
-
-  IGL_INLINE void Viewer::draw()
-  {
-    using namespace std;
-    using namespace Eigen;
-
-    core.clear_framebuffers();
-
-    if (callback_pre_draw)
-      if (callback_pre_draw(*this))
-        return;
-
-    for (unsigned int i = 0; i<plugins.size(); ++i)
-      if (plugins[i]->pre_draw())
-        return;
-
-    core.draw(data,opengl);
-
-    if (callback_post_draw)
-      if (callback_post_draw(*this))
-        return;
-
-    for (unsigned int i = 0; i<plugins.size(); ++i)
-      if (plugins[i]->post_draw())
-        break;
-
-#ifdef IGL_VIEWER_WITH_NANOGUI
-	screen->drawContents();
-	screen->drawWidgets();
-#endif
-  }
-
-  IGL_INLINE bool Viewer::save_scene()
-  {
-    std::string fname = igl::file_dialog_save();
-    if (fname.length() == 0)
-      return false;
-
-#ifdef ENABLE_SERIALIZATION
-
-    igl::serialize(core,"Core",fname.c_str(),true);
-
-#ifndef ENABLE_SERIALIZATION_CORE_ONLY
-    igl::serialize(data,"Data",fname.c_str());
-    for(unsigned int i = 0; i <plugins.size(); ++i)
-      igl::serialize(*plugins[i],plugins[i]->plugin_name,fname.c_str());
-#endif
-
-#endif
-
-    return true;
-  }
-
-  IGL_INLINE bool Viewer::load_scene()
-  {
-    std::string fname = igl::file_dialog_open();
-    if(fname.length() == 0)
-      return false;
-
-    return load_scene(fname);
-  }
-
-  IGL_INLINE bool Viewer::load_scene(std::string fname)
-  {
-#ifdef ENABLE_SERIALIZATION
-
-    igl::deserialize(core,"Core",fname.c_str());
-
-#ifndef ENABLE_SERIALIZATION_CORE_ONLY
-    igl::deserialize(data,"Data",fname.c_str());
-    for(unsigned int i = 0; i <plugins.size(); ++i)
-      igl::deserialize(*plugins[i],plugins[i]->plugin_name,fname.c_str());
-#endif
-
-#endif
-
-    return true;
-  }
-
-  IGL_INLINE void Viewer::resize(int w,int h)
-  {
-    core.viewport = Eigen::Vector4f(0,0,w,h);
-  }
-
-  IGL_INLINE void Viewer::snap_to_canonical_quaternion()
-  {
-    Eigen::Quaternionf snapq = this->core.trackball_angle;
-    igl::snap_to_canonical_view_quat(snapq,1.0f,this->core.trackball_angle);
-  }
-
-  IGL_INLINE void Viewer::open_dialog_load_mesh()
-  {
-    std::string fname = igl::file_dialog_open();
-
-    if (fname.length() == 0)
-      return;
-
-    this->load_mesh_from_file(fname.c_str());
-  }
-
-  IGL_INLINE void Viewer::open_dialog_save_mesh()
-  {
-    std::string fname = igl::file_dialog_save();
-
-    if(fname.length() == 0)
-      return;
-
-    this->save_mesh_to_file(fname.c_str());
-  }
-
-
-  IGL_INLINE int  Viewer::launch_init(bool resizable,bool fullscreen)
-  {
-    glfwSetErrorCallback(glfw_error_callback);
-    if (!glfwInit())
-      return EXIT_FAILURE;
-
-    glfwWindowHint(GLFW_SAMPLES, 8);
-    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
-    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
-
-    #ifdef __APPLE__
-      glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
-      glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
-    #endif
-
-    if(fullscreen)
-    {
-      GLFWmonitor *monitor = glfwGetPrimaryMonitor();
-      const GLFWvidmode *mode = glfwGetVideoMode(monitor);
-      window = glfwCreateWindow(mode->width,mode->height,"libigl viewer",monitor,nullptr);
-    }
-    else
-    {
-      window = glfwCreateWindow(1280,800,"libigl viewer",nullptr,nullptr);
-    }
-
-    if (!window)
-    {
-      glfwTerminate();
-      return EXIT_FAILURE;
-    }
-
-    glfwMakeContextCurrent(window);
-
-    #ifndef __APPLE__
-      glewExperimental = true;
-      GLenum err = glewInit();
-      if(GLEW_OK != err)
-      {
-        /* Problem: glewInit failed, something is seriously wrong. */
-       fprintf(stderr, "Error: %s\n", glewGetErrorString(err));
-      }
-      glGetError(); // pull and savely ignonre unhandled errors like GL_INVALID_ENUM
-      fprintf(stdout, "Status: Using GLEW %s\n", glewGetString(GLEW_VERSION));
-    #endif
-
-    #if defined(DEBUG) || defined(_DEBUG)
-      int major, minor, rev;
-      major = glfwGetWindowAttrib(window, GLFW_CONTEXT_VERSION_MAJOR);
-      minor = glfwGetWindowAttrib(window, GLFW_CONTEXT_VERSION_MINOR);
-      rev = glfwGetWindowAttrib(window, GLFW_CONTEXT_REVISION);
-      printf("OpenGL version recieved: %d.%d.%d\n", major, minor, rev);
-      printf("Supported OpenGL is %s\n", (const char*)glGetString(GL_VERSION));
-      printf("Supported GLSL is %s\n", (const char*)glGetString(GL_SHADING_LANGUAGE_VERSION));
-    #endif
-
-    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;
-
-    // Register callbacks
-    glfwSetKeyCallback(window, glfw_key_callback);
-    glfwSetCursorPosCallback(window,glfw_mouse_move);
-    glfwSetWindowSizeCallback(window,glfw_window_size);
-    glfwSetMouseButtonCallback(window,glfw_mouse_press);
-    glfwSetScrollCallback(window,glfw_mouse_scroll);
-    glfwSetCharModsCallback(window,glfw_char_mods_callback);
-    glfwSetDropCallback(window,glfw_drop_callback);
-
-    // Handle retina displays (windows and mac)
-    int width, height;
-    glfwGetFramebufferSize(window, &width, &height);
-
-    int width_window, height_window;
-    glfwGetWindowSize(window, &width_window, &height_window);
-
-    highdpi = width/width_window;
-
-    glfw_window_size(window,width_window,height_window);
-
-    opengl.init();
-
-    core.align_camera_center(data.V,data.F);
-
-    // Initialize IGL viewer
-    init();
-    return EXIT_SUCCESS;
-  }
-
-  IGL_INLINE bool Viewer::launch_rendering(bool loop)
-  {
-    // glfwMakeContextCurrent(window);
-
-    // Rendering loop
-    while (!glfwWindowShouldClose(window))
-    {
-      double tic = get_seconds();
-      draw();
-
-      glfwSwapBuffers(window);
-      if(core.is_animating)
-      {
-        glfwPollEvents();
-        // In microseconds
-        double duration = 1000000.*(get_seconds()-tic);
-        const double min_duration = 1000000./core.animation_max_fps;
-        if(duration<min_duration)
-        {
-          std::this_thread::sleep_for(std::chrono::microseconds((int)(min_duration-duration)));
-        }
-      }
-      else
-      {
-        glfwWaitEvents();
-      }
-
-      if (!loop)
-        return !glfwWindowShouldClose(window);
-    }
-    return EXIT_SUCCESS;
-  }
-
-  IGL_INLINE void Viewer::launch_shut()
-  {
-    opengl.free();
-    core.shut();
-
-    shutdown_plugins();
-#ifdef IGL_VIEWER_WITH_NANOGUI
-    delete ngui;
-    //delete screen;
-    screen = nullptr;
-    ngui = nullptr;
-#endif
-
-    glfwDestroyWindow(window);
-    glfwTerminate();
-    return;
-  }
-
-  IGL_INLINE int Viewer::launch(bool resizable,bool fullscreen)
-  {
-    // TODO return values are being ignored...
-    launch_init(resizable,fullscreen);
-    launch_rendering(true);
-    launch_shut();
-    return EXIT_SUCCESS;
-  }
-} // end namespace
-}

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

@@ -1,167 +0,0 @@
-// This file is part of libigl, a simple c++ geometry processing library.
-//
-// Copyright (C) 2014 Daniele Panozzo <daniele.panozzo@gmail.com>
-//
-// 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/.
-#ifndef IGL_VIEWER_VIEWER_H
-#define IGL_VIEWER_VIEWER_H
-
-#ifndef IGL_OPENGL_4
-#define IGL_OPENGL_4
-#endif
-
-#include <vector>
-#include <string>
-#include <cstdint>
-
-#include <Eigen/Core>
-#include <Eigen/Geometry>
-
-#include <igl/igl_inline.h>
-
-#include "OpenGL_shader.h"
-#include "OpenGL_state.h"
-#include "ViewerCore.h"
-#include "ViewerData.h"
-#include "ViewerPlugin.h"
-
-#define IGL_MOD_SHIFT           0x0001
-#define IGL_MOD_CONTROL         0x0002
-#define IGL_MOD_ALT             0x0004
-#define IGL_MOD_SUPER           0x0008
-
-#ifdef IGL_VIEWER_WITH_NANOGUI
-namespace nanogui { class FormHelper; class Screen; }
-#endif
-
-class GLFWwindow;
-
-namespace igl
-{
-namespace viewer
-{
-  // GLFW-based mesh viewer
-  class Viewer
-  {
-  public:
-    GLFWwindow* window;
-
-    IGL_INLINE int launch(bool resizable = true,bool fullscreen = false);
-    IGL_INLINE int launch_init(bool resizable = true,bool fullscreen = false);
-    IGL_INLINE bool launch_rendering(bool loop = true);
-    IGL_INLINE void launch_shut();
-
-    IGL_INLINE void init();
-
-    // Stores all the viewing options
-    ViewerCore core;
-
-    // Stores all the data that should be visualized
-    ViewerData data;
-
-    // Stores the vbos indices and opengl related settings
-    OpenGL_state opengl;
-
-    // List of registered plugins
-    std::vector<ViewerPlugin*> plugins;
-    IGL_INLINE void init_plugins();
-    IGL_INLINE void shutdown_plugins();
-
-    // Temporary data stored when the mouse button is pressed
-    Eigen::Quaternionf down_rotation;
-    int current_mouse_x;
-    int current_mouse_y;
-    int down_mouse_x;
-    int down_mouse_y;
-    float down_mouse_z;
-    Eigen::Vector3f down_translation;
-    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;
-
-    // UI Enumerations
-    enum class MouseButton {Left, Middle, Right};
-    enum class MouseMode { None, Rotation, Zoom, Pan, Translation} mouse_mode;
-
-    Viewer();
-    ~Viewer();
-
-    // Mesh IO
-    IGL_INLINE bool load_mesh_from_file(const char* mesh_file_name);
-    IGL_INLINE bool save_mesh_to_file(const char* mesh_file_name);
-
-    // Callbacks
-    IGL_INLINE bool key_pressed(unsigned int unicode_key,int modifier);
-    IGL_INLINE bool key_down(int key,int modifier);
-    IGL_INLINE bool key_up(int key,int modifier);
-
-    IGL_INLINE bool mouse_down(MouseButton button,int modifier);
-    IGL_INLINE bool mouse_up(MouseButton button,int modifier);
-
-    IGL_INLINE bool mouse_move(int mouse_x,int mouse_y);
-    IGL_INLINE bool mouse_scroll(float delta_y);
-
-    // Scene IO
-    IGL_INLINE bool load_scene();
-    IGL_INLINE bool load_scene(std::string fname);
-    IGL_INLINE bool save_scene();
-
-    // Draw everything
-    IGL_INLINE void draw();
-
-    // OpenGL context resize
-    IGL_INLINE void resize(int w,int h);
-
-    // Helper functions
-    IGL_INLINE void snap_to_canonical_quaternion();
-    IGL_INLINE void open_dialog_load_mesh();
-    IGL_INLINE void open_dialog_save_mesh();
-
-    // C++-style functions
-    //
-    // Returns **true** if action should be cancelled.
-    std::function<bool(Viewer& viewer)> callback_init;
-    std::function<bool(Viewer& viewer)> callback_pre_draw;
-    std::function<bool(Viewer& viewer)> callback_post_draw;
-    std::function<bool(Viewer& viewer, int button, int modifier)> callback_mouse_down;
-    std::function<bool(Viewer& viewer, int button, int modifier)> callback_mouse_up;
-    std::function<bool(Viewer& viewer, int mouse_x, int mouse_y)> callback_mouse_move;
-    std::function<bool(Viewer& viewer, float delta_y)> callback_mouse_scroll;
-    std::function<bool(Viewer& viewer, unsigned int key, int modifiers)> callback_key_pressed;
-    // THESE SHOULD BE DEPRECATED:
-    std::function<bool(Viewer& viewer, unsigned char key, int modifiers)> callback_key_down;
-    std::function<bool(Viewer& viewer, unsigned char key, int modifiers)> callback_key_up;
-
-    // Pointers to per-callback data
-    void* callback_init_data;
-    void* callback_pre_draw_data;
-    void* callback_post_draw_data;
-    void* callback_mouse_down_data;
-    void* callback_mouse_up_data;
-    void* callback_mouse_move_data;
-    void* callback_mouse_scroll_data;
-    void* callback_key_pressed_data;
-    void* callback_key_down_data;
-    void* callback_key_up_data;
-
-  public:
-      EIGEN_MAKE_ALIGNED_OPERATOR_NEW
-  };
-
-} // end namespace
-} // end namespace
-
-#ifndef IGL_STATIC_LIBRARY
-#  include "Viewer.cpp"
-#endif
-
-#endif

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

@@ -1,449 +0,0 @@
-// This file is part of libigl, a simple c++ geometry processing library.
-//
-// Copyright (C) 2014 Daniele Panozzo <daniele.panozzo@gmail.com>
-//
-// 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/.
-
-#include "ViewerCore.h"
-#include <igl/quat_to_mat.h>
-#include <igl/snap_to_fixed_up.h>
-#include <igl/look_at.h>
-#include <igl/frustum.h>
-#include <igl/ortho.h>
-#include <igl/massmatrix.h>
-#include <igl/barycenter.h>
-#include <Eigen/Geometry>
-#include <iostream>
-
-IGL_INLINE void igl::viewer::ViewerCore::align_camera_center(
-  const Eigen::MatrixXd& V,
-  const Eigen::MatrixXi& F)
-{
-  if(V.rows() == 0)
-    return;
-
-  get_scale_and_shift_to_fit_mesh(V,F,model_zoom,model_translation);
-  // Rather than crash on empty mesh...
-  if(V.size() > 0)
-  {
-    object_scale = (V.colwise().maxCoeff() - V.colwise().minCoeff()).norm();
-  }
-}
-
-IGL_INLINE void igl::viewer::ViewerCore::get_scale_and_shift_to_fit_mesh(
-  const Eigen::MatrixXd& V,
-  const Eigen::MatrixXi& F,
-  float& zoom,
-  Eigen::Vector3f& shift)
-{
-  if (V.rows() == 0)
-    return;
-
-  Eigen::MatrixXd BC;
-  if (F.rows() <= 1)
-  {
-    BC = V;
-  } else
-  {
-    igl::barycenter(V,F,BC);
-  }
-  return get_scale_and_shift_to_fit_mesh(BC,zoom,shift);
-}
-
-IGL_INLINE void igl::viewer::ViewerCore::align_camera_center(
-  const Eigen::MatrixXd& V)
-{
-  if(V.rows() == 0)
-    return;
-
-  get_scale_and_shift_to_fit_mesh(V,model_zoom,model_translation);
-  // Rather than crash on empty mesh...
-  if(V.size() > 0)
-  {
-    object_scale = (V.colwise().maxCoeff() - V.colwise().minCoeff()).norm();
-  }
-}
-
-IGL_INLINE void igl::viewer::ViewerCore::get_scale_and_shift_to_fit_mesh(
-  const Eigen::MatrixXd& V,
-  float& zoom,
-  Eigen::Vector3f& shift)
-{
-  if (V.rows() == 0)
-    return;
-
-  auto min_point = V.colwise().minCoeff();
-  auto max_point = V.colwise().maxCoeff();
-  auto centroid  = (0.5*(min_point + max_point)).eval();
-  shift.setConstant(0);
-  shift.head(centroid.size()) = -centroid.cast<float>();
-  zoom = 2.0 / (max_point-min_point).array().abs().maxCoeff();
-}
-
-
-IGL_INLINE void igl::viewer::ViewerCore::clear_framebuffers()
-{
-  glClearColor(background_color[0],
-               background_color[1],
-               background_color[2],
-               1.0f);
-  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
-}
-
-IGL_INLINE void igl::viewer::ViewerCore::draw(
-  ViewerData& data,
-  OpenGL_state& opengl,
-  bool update_matrices)
-{
-  using namespace std;
-  using namespace Eigen;
-
-  if (depth_test)
-    glEnable(GL_DEPTH_TEST);
-  else
-    glDisable(GL_DEPTH_TEST);
-
-  glEnable(GL_BLEND);
-  glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
-
-  /* Bind and potentially refresh mesh/line/point data */
-  if (data.dirty)
-  {
-    opengl.set_data(data, invert_normals);
-    data.dirty = ViewerData::DIRTY_NONE;
-  }
-  opengl.bind_mesh();
-
-  // Initialize uniform
-  glViewport(viewport(0), viewport(1), viewport(2), viewport(3));
-
-  if(update_matrices)
-  {
-    model = Eigen::Matrix4f::Identity();
-    view  = Eigen::Matrix4f::Identity();
-    proj  = Eigen::Matrix4f::Identity();
-
-    // Set view
-    look_at( camera_eye, camera_center, camera_up, view);
-
-    float width  = viewport(2);
-    float height = viewport(3);
-
-    // Set projection
-    if (orthographic)
-    {
-      float length = (camera_eye - camera_center).norm();
-      float h = tan(camera_view_angle/360.0 * M_PI) * (length);
-      ortho(-h*width/height, h*width/height, -h, h, camera_dnear, camera_dfar,proj);
-    }
-    else
-    {
-      float fH = tan(camera_view_angle / 360.0 * M_PI) * camera_dnear;
-      float fW = fH * (double)width/(double)height;
-      frustum(-fW, fW, -fH, fH, camera_dnear, camera_dfar,proj);
-    }
-    // end projection
-
-    // Set model transformation
-    float mat[16];
-    igl::quat_to_mat(trackball_angle.coeffs().data(), mat);
-
-    for (unsigned i=0;i<4;++i)
-      for (unsigned j=0;j<4;++j)
-        model(i,j) = mat[i+4*j];
-
-    // Why not just use Eigen::Transform<double,3,Projective> for model...?
-    model.topLeftCorner(3,3)*=camera_zoom;
-    model.topLeftCorner(3,3)*=model_zoom;
-    model.col(3).head(3) += model.topLeftCorner(3,3)*model_translation;
-  }
-
-  // Send transformations to the GPU
-  GLint modeli = opengl.shader_mesh.uniform("model");
-  GLint viewi  = opengl.shader_mesh.uniform("view");
-  GLint proji  = opengl.shader_mesh.uniform("proj");
-  glUniformMatrix4fv(modeli, 1, GL_FALSE, model.data());
-  glUniformMatrix4fv(viewi, 1, GL_FALSE, view.data());
-  glUniformMatrix4fv(proji, 1, GL_FALSE, proj.data());
-
-  // Light parameters
-  GLint specular_exponenti    = opengl.shader_mesh.uniform("specular_exponent");
-  GLint light_position_worldi = opengl.shader_mesh.uniform("light_position_world");
-  GLint lighting_factori      = opengl.shader_mesh.uniform("lighting_factor");
-  GLint fixed_colori          = opengl.shader_mesh.uniform("fixed_color");
-  GLint texture_factori       = opengl.shader_mesh.uniform("texture_factor");
-
-  glUniform1f(specular_exponenti, shininess);
-  Vector3f rev_light = -1.*light_position;
-  glUniform3fv(light_position_worldi, 1, rev_light.data());
-  glUniform1f(lighting_factori, lighting_factor); // enables lighting
-  glUniform4f(fixed_colori, 0.0, 0.0, 0.0, 0.0);
-
-  if (data.V.rows()>0)
-  {
-    // Render fill
-    if (show_faces)
-    {
-      // Texture
-      glUniform1f(texture_factori, show_texture ? 1.0f : 0.0f);
-      opengl.draw_mesh(true);
-      glUniform1f(texture_factori, 0.0f);
-    }
-
-    // Render wireframe
-    if (show_lines)
-    {
-      glLineWidth(line_width);
-      glUniform4f(fixed_colori, line_color[0], line_color[1],
-        line_color[2], 1.0f);
-      opengl.draw_mesh(false);
-      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);
-      for (int i=0; i<data.V.rows(); ++i)
-        textrenderer.DrawText(data.V.row(i),data.V_normals.row(i),to_string(i));
-      textrenderer.EndDraw();
-    }
-
-    if (show_faceid)
-    {
-      textrenderer.BeginDraw(view*model, proj, viewport, object_scale);
-
-      for (int i=0; i<data.F.rows(); ++i)
-      {
-        Eigen::RowVector3d p = Eigen::RowVector3d::Zero();
-        for (int j=0;j<data.F.cols();++j)
-          p += data.V.row(data.F(i,j));
-        p /= data.F.cols();
-
-        textrenderer.DrawText(p, data.F_normals.row(i), to_string(i));
-      }
-      textrenderer.EndDraw();
-    }
-#endif
-  }
-
-  if (show_overlay)
-  {
-    if (show_overlay_depth)
-      glEnable(GL_DEPTH_TEST);
-    else
-      glDisable(GL_DEPTH_TEST);
-
-    if (data.lines.rows() > 0)
-    {
-      opengl.bind_overlay_lines();
-      modeli = opengl.shader_overlay_lines.uniform("model");
-      viewi  = opengl.shader_overlay_lines.uniform("view");
-      proji  = opengl.shader_overlay_lines.uniform("proj");
-
-      glUniformMatrix4fv(modeli, 1, GL_FALSE, model.data());
-      glUniformMatrix4fv(viewi, 1, GL_FALSE, view.data());
-      glUniformMatrix4fv(proji, 1, GL_FALSE, proj.data());
-      // This must be enabled, otherwise glLineWidth has no effect
-      glEnable(GL_LINE_SMOOTH);
-      glLineWidth(line_width);
-
-      opengl.draw_overlay_lines();
-    }
-
-    if (data.points.rows() > 0)
-    {
-      opengl.bind_overlay_points();
-      modeli = opengl.shader_overlay_points.uniform("model");
-      viewi  = opengl.shader_overlay_points.uniform("view");
-      proji  = opengl.shader_overlay_points.uniform("proj");
-
-      glUniformMatrix4fv(modeli, 1, GL_FALSE, model.data());
-      glUniformMatrix4fv(viewi, 1, GL_FALSE, view.data());
-      glUniformMatrix4fv(proji, 1, GL_FALSE, proj.data());
-      glPointSize(point_size);
-
-      opengl.draw_overlay_points();
-    }
-
-#ifdef IGL_VIEWER_WITH_NANOGUI
-    if (data.labels_positions.rows() > 0)
-    {
-      textrenderer.BeginDraw(view*model, proj, viewport, object_scale);
-      for (int i=0; i<data.labels_positions.rows(); ++i)
-        textrenderer.DrawText(data.labels_positions.row(i), Eigen::Vector3d(0.0,0.0,0.0),
-            data.labels_strings[i]);
-      textrenderer.EndDraw();
-    }
-#endif
-
-    glEnable(GL_DEPTH_TEST);
-  }
-
-}
-
-IGL_INLINE void igl::viewer::ViewerCore::draw_buffer(ViewerData& data,
-  OpenGL_state& opengl,
-  bool update_matrices,
-  Eigen::Matrix<unsigned char,Eigen::Dynamic,Eigen::Dynamic>& R,
-  Eigen::Matrix<unsigned char,Eigen::Dynamic,Eigen::Dynamic>& G,
-  Eigen::Matrix<unsigned char,Eigen::Dynamic,Eigen::Dynamic>& B,
-  Eigen::Matrix<unsigned char,Eigen::Dynamic,Eigen::Dynamic>& A)
-{
-  assert(R.rows() == G.rows() && G.rows() == B.rows() && B.rows() == A.rows());
-  assert(R.cols() == G.cols() && G.cols() == B.cols() && B.cols() == A.cols());
-
-  unsigned x = R.rows();
-  unsigned y = R.cols();
-
-  // Create frame buffer
-  GLuint frameBuffer;
-  glGenFramebuffers(1, &frameBuffer);
-  glBindFramebuffer(GL_FRAMEBUFFER, frameBuffer);
-
-  // Create texture to hold color buffer
-  GLuint texColorBuffer;
-  glGenTextures(1, &texColorBuffer);
-  glBindTexture(GL_TEXTURE_2D, texColorBuffer);
-
-  glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, x, y, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
-
-  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
-  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
-
-  glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texColorBuffer, 0);
-
-  // Create Renderbuffer Object to hold depth and stencil buffers
-  GLuint rboDepthStencil;
-  glGenRenderbuffers(1, &rboDepthStencil);
-  glBindRenderbuffer(GL_RENDERBUFFER, rboDepthStencil);
-  glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, x, y);
-  glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, rboDepthStencil);
-
-  assert(glCheckFramebufferStatus(GL_FRAMEBUFFER) == GL_FRAMEBUFFER_COMPLETE);
-
-  glBindFramebuffer(GL_FRAMEBUFFER, frameBuffer);
-
-  // Clear the buffer
-  glClearColor(background_color(0), background_color(1), background_color(2), 0.f);
-  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
-
-  // Save old viewport
-  Eigen::Vector4f viewport_ori = viewport;
-  viewport << 0,0,x,y;
-
-  // Draw
-  draw(data,opengl,update_matrices);
-
-  // Restore viewport
-  viewport = viewport_ori;
-
-  // Copy back in the given Eigen matrices
-  GLubyte* pixels = (GLubyte*)calloc(x*y*4,sizeof(GLubyte));
-  glReadPixels
-  (
-   0, 0,
-   x, y,
-   GL_RGBA, GL_UNSIGNED_BYTE, pixels
-   );
-
-  int count = 0;
-  for (unsigned j=0; j<y; ++j)
-  {
-    for (unsigned i=0; i<x; ++i)
-    {
-      R(i,j) = pixels[count*4+0];
-      G(i,j) = pixels[count*4+1];
-      B(i,j) = pixels[count*4+2];
-      A(i,j) = pixels[count*4+3];
-      ++count;
-    }
-  }
-
-  // Clean up
-  free(pixels);
-  glBindFramebuffer(GL_FRAMEBUFFER, 0);
-  glDeleteRenderbuffers(1, &rboDepthStencil);
-  glDeleteTextures(1, &texColorBuffer);
-  glDeleteFramebuffers(1, &frameBuffer);
-}
-
-IGL_INLINE void igl::viewer::ViewerCore::set_rotation_type(
-  const igl::viewer::ViewerCore::RotationType & value)
-{
-  using namespace Eigen;
-  using namespace std;
-  const RotationType old_rotation_type = rotation_type;
-  rotation_type = value;
-  if(rotation_type == ROTATION_TYPE_TWO_AXIS_VALUATOR_FIXED_UP &&
-    old_rotation_type != ROTATION_TYPE_TWO_AXIS_VALUATOR_FIXED_UP)
-  {
-    snap_to_fixed_up(Quaternionf(trackball_angle),trackball_angle);
-  }
-}
-
-
-IGL_INLINE igl::viewer::ViewerCore::ViewerCore()
-{
-  // Default shininess
-  shininess = 35.0f;
-
-  // Default colors
-  background_color << 0.3f, 0.3f, 0.5f, 1.0f;
-  line_color << 0.0f, 0.0f, 0.0f, 1.0f;
-
-  // Default lights settings
-  light_position << 0.0f, -0.30f, -5.0f;
-  lighting_factor = 1.0f; //on
-
-  // Default trackball
-  trackball_angle = Eigen::Quaternionf::Identity();
-  set_rotation_type(ViewerCore::ROTATION_TYPE_TWO_AXIS_VALUATOR_FIXED_UP);
-
-  // Defalut model viewing parameters
-  model_zoom = 1.0f;
-  model_translation << 0,0,0;
-
-  // Camera parameters
-  camera_zoom = 1.0f;
-  orthographic = false;
-  camera_view_angle = 45.0;
-  camera_dnear = 1.0;
-  camera_dfar = 100.0;
-  camera_eye << 0, 0, 5;
-  camera_center << 0, 0, 0;
-  camera_up << 0, 1, 0;
-
-  // Default visualization options
-  show_faces = true;
-  show_lines = true;
-  invert_normals = false;
-  show_overlay = true;
-  show_overlay_depth = true;
-  show_vertid = false;
-  show_faceid = false;
-  show_texture = false;
-  depth_test = true;
-
-  // Default point size / line width
-  point_size = 30;
-  line_width = 0.5f;
-  is_animating = false;
-  animation_max_fps = 30.;
-}
-
-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
-}

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

@@ -1,246 +0,0 @@
-// This file is part of libigl, a simple c++ geometry processing library.
-//
-// Copyright (C) 2014 Daniele Panozzo <daniele.panozzo@gmail.com>
-//
-// 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/.
-#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>
-
-#include <igl/igl_inline.h>
-#include <Eigen/Geometry>
-#include <Eigen/Core>
-
-namespace igl
-{
-namespace viewer
-{
-
-// Basic class of the 3D mesh viewer
-// TODO: write documentation
-
-class ViewerCore
-{
-public:
-  IGL_INLINE ViewerCore();
-
-  // Initialization
-  IGL_INLINE void init();
-
-  // Shutdown
-  IGL_INLINE void shut();
-
-  // Serialization code
-  IGL_INLINE void InitSerialization();
-
-
-  // ------------------- Camera control functions
-
-  // Adjust the view to see the entire model
-  IGL_INLINE void align_camera_center(
-    const Eigen::MatrixXd& V,
-    const Eigen::MatrixXi& F);
-
-  // Determines how much to zoom and shift such that the mesh fills the unit
-  // box (centered at the origin)
-  IGL_INLINE void get_scale_and_shift_to_fit_mesh(
-    const Eigen::MatrixXd& V,
-    const Eigen::MatrixXi& F,
-    float & zoom,
-    Eigen::Vector3f& shift);
-
-    // Adjust the view to see the entire model
-    IGL_INLINE void align_camera_center(
-      const Eigen::MatrixXd& V);
-
-    // Determines how much to zoom and shift such that the mesh fills the unit
-    // box (centered at the origin)
-    IGL_INLINE void get_scale_and_shift_to_fit_mesh(
-      const Eigen::MatrixXd& V,
-      float & zoom,
-      Eigen::Vector3f& shift);
-
-  // ------------------- Drawing functions
-
-  // Clear the frame buffers
-  IGL_INLINE void clear_framebuffers();
-
-  // Draw everything
-  IGL_INLINE void draw(ViewerData& data, OpenGL_state& opengl, bool update_matrices = true);
-  IGL_INLINE void draw_buffer(
-    ViewerData& data,
-    OpenGL_state& opengl,
-    bool update_matrices,
-    Eigen::Matrix<unsigned char,Eigen::Dynamic,Eigen::Dynamic>& R,
-    Eigen::Matrix<unsigned char,Eigen::Dynamic,Eigen::Dynamic>& G,
-    Eigen::Matrix<unsigned char,Eigen::Dynamic,Eigen::Dynamic>& B,
-    Eigen::Matrix<unsigned char,Eigen::Dynamic,Eigen::Dynamic>& A);
-
-  // Trackball angle (quaternion)
-  enum RotationType
-  {
-    ROTATION_TYPE_TRACKBALL = 0,
-    ROTATION_TYPE_TWO_AXIS_VALUATOR_FIXED_UP = 1,
-    NUM_ROTATION_TYPES = 2
-  };
-  IGL_INLINE void set_rotation_type(const RotationType & value);
-
-  // ------------------- Properties
-
-#ifdef IGL_VIEWER_WITH_NANOGUI
-  // Text rendering helper
-  TextRenderer textrenderer;
-#endif
-
-  // Shape material
-  float shininess;
-
-  // Colors
-  Eigen::Vector4f background_color;
-  Eigen::Vector4f line_color;
-
-  // Lighting
-  Eigen::Vector3f light_position;
-  float lighting_factor;
-
-  RotationType rotation_type;
-
-  Eigen::Quaternionf trackball_angle;
-
-  // Model viewing parameters
-  float model_zoom;
-  Eigen::Vector3f model_translation;
-
-  // Model viewing paramters (uv coordinates)
-  float model_zoom_uv;
-  Eigen::Vector3f model_translation_uv;
-
-  // Camera parameters
-  float camera_zoom;
-  bool orthographic;
-  Eigen::Vector3f camera_eye;
-  Eigen::Vector3f camera_up;
-  Eigen::Vector3f camera_center;
-  float camera_view_angle;
-  float camera_dnear;
-  float camera_dfar;
-
-  // Visualization options
-  bool show_overlay;
-  bool show_overlay_depth;
-  bool show_texture;
-  bool show_faces;
-  bool show_lines;
-  bool show_vertid;
-  bool show_faceid;
-  bool invert_normals;
-  bool depth_test;
-
-  // Point size / line width
-  float point_size;
-  float line_width;
-
-  // Animation
-  bool is_animating;
-  double animation_max_fps;
-
-  // Caches the two-norm between the min/max point of the bounding box
-  float object_scale;
-
-  // Viewport size
-  Eigen::Vector4f viewport;
-
-  // Save the OpenGL transformation matrices used for the previous rendering pass
-  Eigen::Matrix4f view;
-  Eigen::Matrix4f model;
-  Eigen::Matrix4f proj;
-  public:
-      EIGEN_MAKE_ALIGNED_OPERATOR_NEW
-};
-
-}
-}
-
-#ifdef ENABLE_SERIALIZATION
-#include <igl/serialize.h>
-namespace igl {
-	namespace serialization {
-
-		inline void serialization(bool s, igl::viewer::ViewerCore& obj, std::vector<char>& buffer)
-		{
-			SERIALIZE_MEMBER(shininess);
-
-			SERIALIZE_MEMBER(background_color);
-			SERIALIZE_MEMBER(line_color);
-
-			SERIALIZE_MEMBER(light_position);
-			SERIALIZE_MEMBER(lighting_factor);
-
-			SERIALIZE_MEMBER(trackball_angle);
-			SERIALIZE_MEMBER(rotation_type);
-
-			SERIALIZE_MEMBER(model_zoom);
-			SERIALIZE_MEMBER(model_translation);
-
-			SERIALIZE_MEMBER(model_zoom_uv);
-			SERIALIZE_MEMBER(model_translation_uv);
-
-			SERIALIZE_MEMBER(camera_zoom);
-			SERIALIZE_MEMBER(orthographic);
-			SERIALIZE_MEMBER(camera_view_angle);
-			SERIALIZE_MEMBER(camera_dnear);
-			SERIALIZE_MEMBER(camera_dfar);
-			SERIALIZE_MEMBER(camera_eye);
-			SERIALIZE_MEMBER(camera_center);
-			SERIALIZE_MEMBER(camera_up);
-
-			SERIALIZE_MEMBER(show_faces);
-			SERIALIZE_MEMBER(show_lines);
-			SERIALIZE_MEMBER(invert_normals);
-			SERIALIZE_MEMBER(show_overlay);
-			SERIALIZE_MEMBER(show_overlay_depth);
-			SERIALIZE_MEMBER(show_vertid);
-			SERIALIZE_MEMBER(show_faceid);
-			SERIALIZE_MEMBER(show_texture);
-			SERIALIZE_MEMBER(depth_test);
-
-			SERIALIZE_MEMBER(point_size);
-			SERIALIZE_MEMBER(line_width);
-			SERIALIZE_MEMBER(is_animating);
-			SERIALIZE_MEMBER(animation_max_fps);
-
-			SERIALIZE_MEMBER(object_scale);
-
-			SERIALIZE_MEMBER(viewport);
-			SERIALIZE_MEMBER(view);
-			SERIALIZE_MEMBER(model);
-			SERIALIZE_MEMBER(proj);
-		}
-
-		template<>
-		inline void serialize(const igl::viewer::ViewerCore& obj, std::vector<char>& buffer)
-		{
-			serialization(true, const_cast<igl::viewer::ViewerCore&>(obj), buffer);
-		}
-
-		template<>
-		inline void deserialize(igl::viewer::ViewerCore& obj, const std::vector<char>& buffer)
-		{
-			serialization(false, obj, const_cast<std::vector<char>&>(buffer));
-		}
-  }
-}
-#endif
-
-#ifndef IGL_STATIC_LIBRARY
-#  include "ViewerCore.cpp"
-#endif
-
-#endif

+ 0 - 422
include/igl/viewer/ViewerData.cpp

@@ -1,422 +0,0 @@
-// This file is part of libigl, a simple c++ geometry processing library.
-//
-// Copyright (C) 2014 Daniele Panozzo <daniele.panozzo@gmail.com>
-//
-// 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/.
-
-#include "ViewerData.h"
-
-#include <iostream>
-
-#include <igl/per_face_normals.h>
-#include <igl/material_colors.h>
-#include <igl/parula.h>
-#include <igl/per_vertex_normals.h>
-
-IGL_INLINE igl::viewer::ViewerData::ViewerData()
-: dirty(DIRTY_ALL)
-{
-  clear();
-};
-
-IGL_INLINE void igl::viewer::ViewerData::set_face_based(bool newvalue)
-{
-  if (face_based != newvalue)
-  {
-    face_based = newvalue;
-    dirty = DIRTY_ALL;
-  }
-}
-
-// Helpers that draws the most common meshes
-IGL_INLINE void igl::viewer::ViewerData::set_mesh(const Eigen::MatrixXd& _V, const Eigen::MatrixXi& _F)
-{
-  using namespace std;
-
-  Eigen::MatrixXd V_temp;
-
-  // If V only has two columns, pad with a column of zeros
-  if (_V.cols() == 2)
-  {
-    V_temp = Eigen::MatrixXd::Zero(_V.rows(),3);
-    V_temp.block(0,0,_V.rows(),2) = _V;
-  }
-  else
-    V_temp = _V;
-
-  if (V.rows() == 0 && F.rows() == 0)
-  {
-    V = V_temp;
-    F = _F;
-
-    compute_normals();
-    uniform_colors(
-      Eigen::Vector3d(GOLD_AMBIENT[0], GOLD_AMBIENT[1], GOLD_AMBIENT[2]),
-      Eigen::Vector3d(GOLD_DIFFUSE[0], GOLD_DIFFUSE[1], GOLD_DIFFUSE[2]),
-      Eigen::Vector3d(GOLD_SPECULAR[0], GOLD_SPECULAR[1], GOLD_SPECULAR[2]));
-
-    grid_texture();
-  }
-  else
-  {
-    if (_V.rows() == V.rows() && _F.rows() == F.rows())
-    {
-      V = V_temp;
-      F = _F;
-    }
-    else
-      cerr << "ERROR (set_mesh): The new mesh has a different number of vertices/faces. Please clear the mesh before plotting."<<endl;
-  }
-  dirty |= DIRTY_FACE | DIRTY_POSITION;
-}
-
-IGL_INLINE void igl::viewer::ViewerData::set_vertices(const Eigen::MatrixXd& _V)
-{
-  V = _V;
-  assert(F.size() == 0 || F.maxCoeff() < V.rows());
-  dirty |= DIRTY_POSITION;
-}
-
-IGL_INLINE void igl::viewer::ViewerData::set_normals(const Eigen::MatrixXd& N)
-{
-  using namespace std;
-  if (N.rows() == V.rows())
-  {
-    set_face_based(false);
-    V_normals = N;
-  }
-  else if (N.rows() == F.rows() || N.rows() == F.rows()*3)
-  {
-    set_face_based(true);
-    F_normals = N;
-  }
-  else
-    cerr << "ERROR (set_normals): Please provide a normal per face, per corner or per vertex."<<endl;
-  dirty |= DIRTY_NORMAL;
-}
-
-IGL_INLINE void igl::viewer::ViewerData::set_colors(const Eigen::MatrixXd &C)
-{
-  using namespace std;
-  using namespace Eigen;
-  if(C.rows()>0 && C.cols() == 1)
-  {
-    Eigen::MatrixXd C3;
-    igl::parula(C,true,C3);
-    return set_colors(C3);
-  }
-  // Ambient color should be darker color
-  const auto ambient = [](const MatrixXd & C)->MatrixXd
-  {
-    MatrixXd T = 0.1*C;
-    T.col(3) = C.col(3);
-    return T;
-  };
-  // Specular color should be a less saturated and darker color: dampened
-  // highlights
-  const auto specular = [](const MatrixXd & C)->MatrixXd
-  {
-    const double grey = 0.3;
-    MatrixXd T = grey+0.1*(C.array()-grey);
-    T.col(3) = C.col(3);
-    return T;
-  };
-  if (C.rows() == 1)
-  {
-    for (unsigned i=0;i<V_material_diffuse.rows();++i)
-    {
-      V_material_diffuse.row(i) << C.row(0),1;
-    }
-    V_material_ambient = ambient(V_material_diffuse);
-    V_material_specular = specular(V_material_diffuse);
-
-    for (unsigned i=0;i<F_material_diffuse.rows();++i)
-    {
-      F_material_diffuse.row(i) << C.row(0),1;
-    }
-    F_material_ambient = ambient(F_material_diffuse);
-    F_material_specular = specular(F_material_diffuse);
-  }
-  else if (C.rows() == V.rows())
-  {
-    set_face_based(false);
-    for (unsigned i=0;i<V_material_diffuse.rows();++i)
-    {
-      V_material_diffuse.row(i) << C.row(i),1;
-    }
-    V_material_ambient = ambient(V_material_diffuse);
-    V_material_specular = specular(V_material_diffuse);
-  }
-  else if (C.rows() == F.rows())
-  {
-    set_face_based(true);
-    for (unsigned i=0;i<F_material_diffuse.rows();++i)
-    {
-      F_material_diffuse.row(i) << C.row(i),1;
-    }
-    F_material_ambient = ambient(F_material_diffuse);
-    F_material_specular = specular(F_material_diffuse);
-  }
-  else
-    cerr << "ERROR (set_colors): Please provide a single color, or a color per face or per vertex."<<endl;;
-  dirty |= DIRTY_DIFFUSE;
-
-}
-
-IGL_INLINE void igl::viewer::ViewerData::set_uv(const Eigen::MatrixXd& UV)
-{
-  using namespace std;
-  if (UV.rows() == V.rows())
-  {
-    set_face_based(false);
-    V_uv = UV;
-  }
-  else
-    cerr << "ERROR (set_UV): Please provide uv per vertex."<<endl;;
-  dirty |= DIRTY_UV;
-}
-
-IGL_INLINE void igl::viewer::ViewerData::set_uv(const Eigen::MatrixXd& UV_V, const Eigen::MatrixXi& UV_F)
-{
-  set_face_based(true);
-  V_uv = UV_V.block(0,0,UV_V.rows(),2);
-  F_uv = UV_F;
-  dirty |= DIRTY_UV;
-}
-
-
-IGL_INLINE void igl::viewer::ViewerData::set_texture(
-  const Eigen::Matrix<unsigned char,Eigen::Dynamic,Eigen::Dynamic>& R,
-  const Eigen::Matrix<unsigned char,Eigen::Dynamic,Eigen::Dynamic>& G,
-  const Eigen::Matrix<unsigned char,Eigen::Dynamic,Eigen::Dynamic>& B)
-{
-  texture_R = R;
-  texture_G = G;
-  texture_B = B;
-  texture_A = Eigen::Matrix<unsigned char,Eigen::Dynamic,Eigen::Dynamic>::Constant(R.rows(),R.cols(),255);
-  dirty |= DIRTY_TEXTURE;
-}
-
-IGL_INLINE void igl::viewer::ViewerData::set_texture(
-  const Eigen::Matrix<unsigned char,Eigen::Dynamic,Eigen::Dynamic>& R,
-  const Eigen::Matrix<unsigned char,Eigen::Dynamic,Eigen::Dynamic>& G,
-  const Eigen::Matrix<unsigned char,Eigen::Dynamic,Eigen::Dynamic>& B,
-  const Eigen::Matrix<unsigned char,Eigen::Dynamic,Eigen::Dynamic>& A)
-{
-  texture_R = R;
-  texture_G = G;
-  texture_B = B;
-  texture_A = A;
-  dirty |= DIRTY_TEXTURE;
-}
-
-IGL_INLINE void igl::viewer::ViewerData::set_points(
-  const Eigen::MatrixXd& P,
-  const Eigen::MatrixXd& C)
-{
-  // clear existing points
-  points.resize(0,0);
-  add_points(P,C);
-}
-
-IGL_INLINE void igl::viewer::ViewerData::add_points(const Eigen::MatrixXd& P,  const Eigen::MatrixXd& C)
-{
-  Eigen::MatrixXd P_temp;
-
-  // If P only has two columns, pad with a column of zeros
-  if (P.cols() == 2)
-  {
-    P_temp = Eigen::MatrixXd::Zero(P.rows(),3);
-    P_temp.block(0,0,P.rows(),2) = P;
-  }
-  else
-    P_temp = P;
-
-  int lastid = points.rows();
-  points.conservativeResize(points.rows() + P_temp.rows(),6);
-  for (unsigned i=0; i<P_temp.rows(); ++i)
-    points.row(lastid+i) << P_temp.row(i), i<C.rows() ? C.row(i) : C.row(C.rows()-1);
-
-  dirty |= DIRTY_OVERLAY_POINTS;
-}
-
-IGL_INLINE void igl::viewer::ViewerData::set_edges(
-  const Eigen::MatrixXd& P,
-  const Eigen::MatrixXi& E,
-  const Eigen::MatrixXd& C)
-{
-  using namespace Eigen;
-  lines.resize(E.rows(),9);
-  assert(C.cols() == 3);
-  for(int e = 0;e<E.rows();e++)
-  {
-    RowVector3d color;
-    if(C.size() == 3)
-    {
-      color<<C;
-    }else if(C.rows() == E.rows())
-    {
-      color<<C.row(e);
-    }
-    lines.row(e)<< P.row(E(e,0)), P.row(E(e,1)), color;
-  }
-  dirty |= DIRTY_OVERLAY_LINES;
-}
-
-IGL_INLINE void igl::viewer::ViewerData::add_edges(const Eigen::MatrixXd& P1, const Eigen::MatrixXd& P2, const Eigen::MatrixXd& C)
-{
-  Eigen::MatrixXd P1_temp,P2_temp;
-
-  // If P1 only has two columns, pad with a column of zeros
-  if (P1.cols() == 2)
-  {
-    P1_temp = Eigen::MatrixXd::Zero(P1.rows(),3);
-    P1_temp.block(0,0,P1.rows(),2) = P1;
-    P2_temp = Eigen::MatrixXd::Zero(P2.rows(),3);
-    P2_temp.block(0,0,P2.rows(),2) = P2;
-  }
-  else
-  {
-    P1_temp = P1;
-    P2_temp = P2;
-  }
-
-  int lastid = lines.rows();
-  lines.conservativeResize(lines.rows() + P1_temp.rows(),9);
-  for (unsigned i=0; i<P1_temp.rows(); ++i)
-    lines.row(lastid+i) << P1_temp.row(i), P2_temp.row(i), i<C.rows() ? C.row(i) : C.row(C.rows()-1);
-
-  dirty |= DIRTY_OVERLAY_LINES;
-}
-
-IGL_INLINE void igl::viewer::ViewerData::add_label(const Eigen::VectorXd& P,  const std::string& str)
-{
-  Eigen::RowVectorXd P_temp;
-
-  // If P only has two columns, pad with a column of zeros
-  if (P.size() == 2)
-  {
-    P_temp = Eigen::RowVectorXd::Zero(3);
-    P_temp << P.transpose(), 0;
-  }
-  else
-    P_temp = P;
-
-  int lastid = labels_positions.rows();
-  labels_positions.conservativeResize(lastid+1, 3);
-  labels_positions.row(lastid) = P_temp;
-  labels_strings.push_back(str);
-}
-
-IGL_INLINE void igl::viewer::ViewerData::clear()
-{
-  V                       = Eigen::MatrixXd (0,3);
-  F                       = Eigen::MatrixXi (0,3);
-
-  F_material_ambient      = Eigen::MatrixXd (0,4);
-  F_material_diffuse      = Eigen::MatrixXd (0,4);
-  F_material_specular     = Eigen::MatrixXd (0,4);
-
-  V_material_ambient      = Eigen::MatrixXd (0,4);
-  V_material_diffuse      = Eigen::MatrixXd (0,4);
-  V_material_specular     = Eigen::MatrixXd (0,4);
-
-  F_normals               = Eigen::MatrixXd (0,3);
-  V_normals               = Eigen::MatrixXd (0,3);
-
-  V_uv                    = Eigen::MatrixXd (0,2);
-  F_uv                    = Eigen::MatrixXi (0,3);
-
-  lines                   = Eigen::MatrixXd (0,9);
-  points                  = Eigen::MatrixXd (0,6);
-  labels_positions        = Eigen::MatrixXd (0,3);
-  labels_strings.clear();
-
-  face_based = false;
-}
-
-IGL_INLINE void igl::viewer::ViewerData::compute_normals()
-{
-  igl::per_face_normals(V, F, F_normals);
-  igl::per_vertex_normals(V, F, F_normals, V_normals);
-  dirty |= DIRTY_NORMAL;
-}
-
-IGL_INLINE void igl::viewer::ViewerData::uniform_colors(Eigen::Vector3d ambient, Eigen::Vector3d diffuse, Eigen::Vector3d specular)
-{
-  Eigen::Vector4d ambient4;
-  Eigen::Vector4d diffuse4;
-  Eigen::Vector4d specular4;
-
-  ambient4 << ambient, 1;
-  diffuse4 << diffuse, 1;
-  specular4 << specular, 1;
-
-  uniform_colors(ambient4,diffuse4,specular4);
-}
-
-IGL_INLINE void igl::viewer::ViewerData::uniform_colors(Eigen::Vector4d ambient, Eigen::Vector4d diffuse, Eigen::Vector4d specular)
-{
-  V_material_ambient.resize(V.rows(),4);
-  V_material_diffuse.resize(V.rows(),4);
-  V_material_specular.resize(V.rows(),4);
-
-  for (unsigned i=0; i<V.rows();++i)
-  {
-    V_material_ambient.row(i) = ambient;
-    V_material_diffuse.row(i) = diffuse;
-    V_material_specular.row(i) = specular;
-  }
-
-  F_material_ambient.resize(F.rows(),4);
-  F_material_diffuse.resize(F.rows(),4);
-  F_material_specular.resize(F.rows(),4);
-
-  for (unsigned i=0; i<F.rows();++i)
-  {
-    F_material_ambient.row(i) = ambient;
-    F_material_diffuse.row(i) = diffuse;
-    F_material_specular.row(i) = specular;
-  }
-  dirty |= DIRTY_SPECULAR | DIRTY_DIFFUSE | DIRTY_AMBIENT;
-}
-
-IGL_INLINE void igl::viewer::ViewerData::grid_texture()
-{
-  // Don't do anything for an empty mesh
-  if(V.rows() == 0)
-  {
-    V_uv.resize(V.rows(),2);
-    return;
-  }
-  if (V_uv.rows() == 0)
-  {
-    V_uv = V.block(0, 0, V.rows(), 2);
-    V_uv.col(0) = V_uv.col(0).array() - V_uv.col(0).minCoeff();
-    V_uv.col(0) = V_uv.col(0).array() / V_uv.col(0).maxCoeff();
-    V_uv.col(1) = V_uv.col(1).array() - V_uv.col(1).minCoeff();
-    V_uv.col(1) = V_uv.col(1).array() / V_uv.col(1).maxCoeff();
-    V_uv = V_uv.array() * 10;
-    dirty |= DIRTY_TEXTURE;
-  }
-
-  unsigned size = 128;
-  unsigned size2 = size/2;
-  texture_R.resize(size, size);
-  for (unsigned i=0; i<size; ++i)
-  {
-    for (unsigned j=0; j<size; ++j)
-    {
-      texture_R(i,j) = 0;
-      if ((i<size2 && j<size2) || (i>=size2 && j>=size2))
-        texture_R(i,j) = 255;
-    }
-  }
-
-  texture_G = texture_R;
-  texture_B = texture_R;
-  texture_A = Eigen::Matrix<unsigned char,Eigen::Dynamic,Eigen::Dynamic>::Constant(texture_R.rows(),texture_R.cols(),255);
-  dirty |= DIRTY_TEXTURE;
-}

+ 0 - 254
include/igl/viewer/ViewerData.h

@@ -1,254 +0,0 @@
-// This file is part of libigl, a simple c++ geometry processing library.
-//
-// Copyright (C) 2014 Daniele Panozzo <daniele.panozzo@gmail.com>
-//
-// 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/.
-#ifndef IGL_VIEWER_VIEWER_DATA_H
-#define IGL_VIEWER_VIEWER_DATA_H
-
-#include <cstdint>
-#include <vector>
-
-#include <Eigen/Core>
-
-#include <igl/igl_inline.h>
-
-namespace igl
-{
-namespace viewer
-{
-
-// TODO: write documentation
-
-class ViewerData
-{
-public:
-  ViewerData();
-
-  enum DirtyFlags
-  {
-    DIRTY_NONE           = 0x0000,
-    DIRTY_POSITION       = 0x0001,
-    DIRTY_UV             = 0x0002,
-    DIRTY_NORMAL         = 0x0004,
-    DIRTY_AMBIENT        = 0x0008,
-    DIRTY_DIFFUSE        = 0x0010,
-    DIRTY_SPECULAR       = 0x0020,
-    DIRTY_TEXTURE        = 0x0040,
-    DIRTY_FACE           = 0x0080,
-    DIRTY_MESH           = 0x00FF,
-    DIRTY_OVERLAY_LINES  = 0x0100,
-    DIRTY_OVERLAY_POINTS = 0x0200,
-    DIRTY_ALL            = 0x03FF
-  };
-
-  // Empy all fields
-  IGL_INLINE void clear();
-
-  // Change the visualization mode, invalidating the cache if necessary
-  IGL_INLINE void set_face_based(bool newvalue);
-
-  // Helpers that can draw the most common meshes
-  IGL_INLINE void set_mesh(const Eigen::MatrixXd& V, const Eigen::MatrixXi& F);
-  IGL_INLINE void set_vertices(const Eigen::MatrixXd& V);
-  IGL_INLINE void set_normals(const Eigen::MatrixXd& N);
-
-  // Set the color of the mesh
-  //
-  // Inputs:
-  //   C  #V|#F|1 by 3 list of colors
-  IGL_INLINE void set_colors(const Eigen::MatrixXd &C);
-  // Set per-vertex UV coordinates
-  //
-  // Inputs:
-  //   UV  #V by 2 list of UV coordinates (indexed by F)
-  IGL_INLINE void set_uv(const Eigen::MatrixXd& UV);
-  // Set per-corner UV coordinates
-  //
-  // Inputs:
-  //   UV_V  #UV by 2 list of UV coordinates
-  //   UV_F  #F by 3 list of UV indices into UV_V
-  IGL_INLINE void set_uv(const Eigen::MatrixXd& UV_V, const Eigen::MatrixXi& UV_F);
-  // Set the texture associated with the mesh.
-  //
-  // Inputs:
-  //   R  width by height image matrix of red channel
-  //   G  width by height image matrix of green channel
-  //   B  width by height image matrix of blue channel
-  //
-  IGL_INLINE void set_texture(
-    const Eigen::Matrix<unsigned char,Eigen::Dynamic,Eigen::Dynamic>& R,
-    const Eigen::Matrix<unsigned char,Eigen::Dynamic,Eigen::Dynamic>& G,
-    const Eigen::Matrix<unsigned char,Eigen::Dynamic,Eigen::Dynamic>& B);
-
-  // Set the texture associated with the mesh.
-  //
-  // Inputs:
-  //   R  width by height image matrix of red channel
-  //   G  width by height image matrix of green channel
-  //   B  width by height image matrix of blue channel
-  //   A  width by height image matrix of alpha channel
-  //
-  IGL_INLINE void set_texture(
-    const Eigen::Matrix<unsigned char,Eigen::Dynamic,Eigen::Dynamic>& R,
-    const Eigen::Matrix<unsigned char,Eigen::Dynamic,Eigen::Dynamic>& G,
-    const Eigen::Matrix<unsigned char,Eigen::Dynamic,Eigen::Dynamic>& B,
-    const Eigen::Matrix<unsigned char,Eigen::Dynamic,Eigen::Dynamic>& A);
-
-  // Sets points given a list of point vertices. In constrast to `set_points`
-  // this will (purposefully) clober existing points.
-  //
-  // Inputs:
-  //   P  #P by 3 list of vertex positions
-  //   C  #P|1 by 3 color(s)
-  IGL_INLINE void set_points(
-    const Eigen::MatrixXd& P,
-    const Eigen::MatrixXd& C);
-  IGL_INLINE void add_points(const Eigen::MatrixXd& P,  const Eigen::MatrixXd& C);
-  // Sets edges given a list of edge vertices and edge indices. In constrast
-  // to `add_edges` this will (purposefully) clober existing edges.
-  //
-  // Inputs:
-  //   P  #P by 3 list of vertex positions
-  //   E  #E by 2 list of edge indices into P
-  //   C  #E|1 by 3 color(s)
-  IGL_INLINE void set_edges (const Eigen::MatrixXd& P, const Eigen::MatrixXi& E, const Eigen::MatrixXd& C);
-  IGL_INLINE void add_edges (const Eigen::MatrixXd& P1, const Eigen::MatrixXd& P2, const Eigen::MatrixXd& C);
-  IGL_INLINE void add_label (const Eigen::VectorXd& P,  const std::string& str);
-
-  // Computes the normals of the mesh
-  IGL_INLINE void compute_normals();
-
-  // Assigns uniform colors to all faces/vertices
-  IGL_INLINE void uniform_colors(
-    Eigen::Vector3d ambient,
-    Eigen::Vector3d diffuse,
-    Eigen::Vector3d specular);
-
-  // Assigns uniform colors to all faces/vertices
-  IGL_INLINE void uniform_colors(
-    Eigen::Vector4d ambient,
-    Eigen::Vector4d diffuse,
-    Eigen::Vector4d specular);
-
-  // Generates a default grid texture
-  IGL_INLINE void grid_texture();
-
-  Eigen::MatrixXd V; // Vertices of the current mesh (#V x 3)
-  Eigen::MatrixXi F; // Faces of the mesh (#F x 3)
-
-  // Per face attributes
-  Eigen::MatrixXd F_normals; // One normal per face
-
-  Eigen::MatrixXd F_material_ambient; // Per face ambient color
-  Eigen::MatrixXd F_material_diffuse; // Per face diffuse color
-  Eigen::MatrixXd F_material_specular; // Per face specular color
-
-  // Per vertex attributes
-  Eigen::MatrixXd V_normals; // One normal per vertex
-
-  Eigen::MatrixXd V_material_ambient; // Per vertex ambient color
-  Eigen::MatrixXd V_material_diffuse; // Per vertex diffuse color
-  Eigen::MatrixXd V_material_specular; // Per vertex specular color
-
-  // UV parametrization
-  Eigen::MatrixXd V_uv; // UV vertices
-  Eigen::MatrixXi F_uv; // optional faces for UVs
-
-  // Texture
-  Eigen::Matrix<unsigned char,Eigen::Dynamic,Eigen::Dynamic> texture_R;
-  Eigen::Matrix<unsigned char,Eigen::Dynamic,Eigen::Dynamic> texture_G;
-  Eigen::Matrix<unsigned char,Eigen::Dynamic,Eigen::Dynamic> texture_B;
-  Eigen::Matrix<unsigned char,Eigen::Dynamic,Eigen::Dynamic> texture_A;
-
-  // Overlays
-
-  // Lines plotted over the scene
-  // (Every row contains 9 doubles in the following format S_x, S_y, S_z, T_x, T_y, T_z, C_r, C_g, C_b),
-  // with S and T the coordinates of the two vertices of the line in global coordinates, and C the color in floating point rgb format
-  Eigen::MatrixXd lines;
-
-  // Points plotted over the scene
-  // (Every row contains 6 doubles in the following format P_x, P_y, P_z, C_r, C_g, C_b),
-  // with P the position in global coordinates of the center of the point, and C the color in floating point rgb format
-  Eigen::MatrixXd points;
-
-  // Text labels plotted over the scene
-  // Textp contains, in the i-th row, the position in global coordinates where the i-th label should be anchored
-  // Texts contains in the i-th position the text of the i-th label
-  Eigen::MatrixXd           labels_positions;
-  std::vector<std::string>  labels_strings;
-
-  // Marks dirty buffers that need to be uploaded to OpenGL
-  uint32_t dirty;
-
-  // Enable per-face or per-vertex properties
-  bool face_based;
-  /*********************************/
-};
-
-}
-}
-
-#ifdef ENABLE_SERIALIZATION
-#include <igl/serialize.h>
-namespace igl {
-	namespace serialization {
-
-		inline void serialization(bool s, igl::viewer::ViewerData& obj, std::vector<char>& buffer)
-		{
-			SERIALIZE_MEMBER(V);
-			SERIALIZE_MEMBER(F);
-
-			SERIALIZE_MEMBER(F_normals);
-			SERIALIZE_MEMBER(F_material_ambient);
-			SERIALIZE_MEMBER(F_material_diffuse);
-			SERIALIZE_MEMBER(F_material_specular);
-
-			SERIALIZE_MEMBER(V_normals);
-			SERIALIZE_MEMBER(V_material_ambient);
-			SERIALIZE_MEMBER(V_material_diffuse);
-			SERIALIZE_MEMBER(V_material_specular);
-
-			SERIALIZE_MEMBER(V_uv);
-			SERIALIZE_MEMBER(F_uv);
-
-			SERIALIZE_MEMBER(texture_R);
-			SERIALIZE_MEMBER(texture_G);
-			SERIALIZE_MEMBER(texture_B);
-      SERIALIZE_MEMBER(texture_A);
-
-			SERIALIZE_MEMBER(lines);
-			SERIALIZE_MEMBER(points);
-
-			SERIALIZE_MEMBER(labels_positions);
-			SERIALIZE_MEMBER(labels_strings);
-
-			SERIALIZE_MEMBER(dirty);
-
-			SERIALIZE_MEMBER(face_based);
-		}
-
-		template<>
-		inline void serialize(const igl::viewer::ViewerData& obj, std::vector<char>& buffer)
-		{
-			serialization(true, const_cast<igl::viewer::ViewerData&>(obj), buffer);
-		}
-
-		template<>
-		inline void deserialize(igl::viewer::ViewerData& obj, const std::vector<char>& buffer)
-		{
-			serialization(false, obj, const_cast<std::vector<char>&>(buffer));
-			obj.dirty = igl::viewer::ViewerData::DIRTY_ALL;
-		}
-	}
-}
-#endif
-
-#ifndef IGL_STATIC_LIBRARY
-#  include "ViewerData.cpp"
-#endif
-
-#endif

+ 0 - 176
include/igl/viewer/ViewerPlugin.h

@@ -1,176 +0,0 @@
-// This file is part of libigl, a simple c++ geometry processing library.
-//
-// Copyright (C) 2014 Daniele Panozzo <daniele.panozzo@gmail.com>
-//
-// 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/.
-#ifndef IGL_VIEWER_VIEWER_PLUGIN_H
-#define IGL_VIEWER_VIEWER_PLUGIN_H
-
-// TODO:
-// * create plugins/skeleton.h
-// * pass time in draw function
-// * remove Preview3D from comments
-// * clean comments
-#include <string>
-#include <igl/igl_inline.h>
-#include <vector>
-
-namespace igl
-{
-namespace viewer
-{
-
-// Abstract class for plugins
-// All plugins MUST have this class as their parent and may implement any/all
-// the callbacks marked `virtual` here.
-//
-// /////For an example of a basic plugins see plugins/skeleton.h
-//
-// Return value of callbacks: returning true to any of the callbacks tells
-// Viewer that the event has been handled and that it should not be passed to
-// other plugins or to other internal functions of Viewer
-
-// Forward declaration of the viewer
-class Viewer;
-
-class ViewerPlugin
-{
-public:
-  IGL_INLINE ViewerPlugin()
-  {plugin_name = "dummy";}
-
-  virtual ~ViewerPlugin(){}
-
-  // This function is called when the viewer is initialized (no mesh will be loaded at this stage)
-  IGL_INLINE virtual void init(Viewer *_viewer)
-  {
-    viewer = _viewer;
-  }
-
-  // This function is called before shutdown
-  IGL_INLINE virtual void shutdown()
-  {
-  }
-
-  // This function is called before a mesh is loaded
-  IGL_INLINE virtual bool load(std::string filename)
-  {
-    return false;
-  }
-
-  // This function is called before a mesh is saved
-  IGL_INLINE virtual bool save(std::string filename)
-  {
-    return false;
-  }
-
-  // This function is called when the scene is serialized
-  IGL_INLINE virtual bool serialize(std::vector<char>& buffer) const
-  {
-    return false;
-  }
-
-  // This function is called when the scene is deserialized
-  IGL_INLINE virtual bool deserialize(const std::vector<char>& buffer)
-  {
-    return false;
-  }
-
-  // Runs immediately after a new mesh has been loaded.
-  IGL_INLINE virtual bool post_load()
-  {
-    return false;
-  }
-
-  // This function is called before the draw procedure of Preview3D
-  IGL_INLINE virtual bool pre_draw()
-  {
-    return false;
-  }
-
-  // This function is called after the draw procedure of Preview3D
-  IGL_INLINE virtual bool post_draw()
-  {
-    return false;
-  }
-
-  // This function is called when the mouse button is pressed
-  // - button can be GLUT_LEFT_BUTTON, GLUT_MIDDLE_BUTTON or GLUT_RIGHT_BUTTON
-  // - modifiers is a bitfield that might one or more of the following bits Preview3D::NO_KEY, Preview3D::SHIFT, Preview3D::CTRL, Preview3D::ALT;
-  IGL_INLINE virtual bool mouse_down(int button, int modifier)
-  {
-    return false;
-  }
-
-  // This function is called when the mouse button is released
-  // - button can be GLUT_LEFT_BUTTON, GLUT_MIDDLE_BUTTON or GLUT_RIGHT_BUTTON
-  // - modifiers is a bitfield that might one or more of the following bits Preview3D::NO_KEY, Preview3D::SHIFT, Preview3D::CTRL, Preview3D::ALT;
-  IGL_INLINE virtual bool mouse_up(int button, int modifier)
-  {
-    return false;
-  }
-
-  // This function is called every time the mouse is moved
-  // - mouse_x and mouse_y are the new coordinates of the mouse pointer in screen coordinates
-  IGL_INLINE virtual bool mouse_move(int mouse_x, int mouse_y)
-  {
-    return false;
-  }
-
-  // This function is called every time the scroll wheel is moved
-  // Note: this callback is not working with every glut implementation
-  IGL_INLINE virtual bool mouse_scroll(float delta_y)
-  {
-    return false;
-  }
-
-  // This function is called when a keyboard key is pressed. Unlike key_down
-  // this will reveal the actual character being sent (not just the physical
-  // key)
-  // - modifiers is a bitfield that might one or more of the following bits Preview3D::NO_KEY, Preview3D::SHIFT, Preview3D::CTRL, Preview3D::ALT;
-  IGL_INLINE virtual bool key_pressed(unsigned int key, int modifiers)
-  {
-    return false;
-  }
-
-  // This function is called when a keyboard key is down
-  // - modifiers is a bitfield that might one or more of the following bits Preview3D::NO_KEY, Preview3D::SHIFT, Preview3D::CTRL, Preview3D::ALT;
-  IGL_INLINE virtual bool key_down(int key, int modifiers)
-  {
-    return false;
-  }
-
-  // This function is called when a keyboard key is release
-  // - modifiers is a bitfield that might one or more of the following bits Preview3D::NO_KEY, Preview3D::SHIFT, Preview3D::CTRL, Preview3D::ALT;
-  IGL_INLINE virtual bool key_up(int key, int modifiers)
-  {
-    return false;
-  }
-
-  std::string plugin_name;
-protected:
-  // Pointer to the main Viewer class
-  Viewer *viewer;
-};
-
-#ifdef ENABLE_SERIALIZATION
-namespace serialization
-{
-  inline void serialize(const ViewerPlugin& obj,std::vector<char>& buffer)
-  {
-    obj.serialize(buffer);
-  }
-
-  inline void deserialize(ViewerPlugin& obj,const std::vector<char>& buffer)
-  {
-    obj.deserialize(buffer);
-  }
-}
-#endif
-
-}
-}
-
-#endif

+ 2 - 2
tutorial/102_DrawMesh/main.cpp

@@ -1,5 +1,5 @@
 #include <igl/readOFF.h>
 #include <igl/readOFF.h>
-#include <igl/viewer/Viewer.h>
+#include <igl/opengl/glfw/Viewer.h>
 #include "tutorial_shared_path.h"
 #include "tutorial_shared_path.h"
 
 
 Eigen::MatrixXd V;
 Eigen::MatrixXd V;
@@ -11,7 +11,7 @@ int main(int argc, char *argv[])
   igl::readOFF(TUTORIAL_SHARED_PATH "/bunny.off", V, F);
   igl::readOFF(TUTORIAL_SHARED_PATH "/bunny.off", V, F);
 
 
   // Plot the mesh
   // Plot the mesh
-  igl::viewer::Viewer viewer;
+  igl::opengl::glfw::Viewer viewer;
   viewer.data.set_mesh(V, F);
   viewer.data.set_mesh(V, F);
   viewer.launch();
   viewer.launch();
 }
 }

+ 3 - 3
tutorial/103_Events/main.cpp

@@ -1,5 +1,5 @@
 #include <igl/readOFF.h>
 #include <igl/readOFF.h>
-#include <igl/viewer/Viewer.h>
+#include <igl/opengl/glfw/Viewer.h>
 #include <iostream>
 #include <iostream>
 #include "tutorial_shared_path.h"
 #include "tutorial_shared_path.h"
 
 
@@ -7,7 +7,7 @@ Eigen::MatrixXd V1,V2;
 Eigen::MatrixXi F1,F2;
 Eigen::MatrixXi F1,F2;
 
 
 // This function is called every time a keyboard button is pressed
 // This function is called every time a keyboard button is pressed
-bool key_down(igl::viewer::Viewer& viewer, unsigned char key, int modifier)
+bool key_down(igl::opengl::glfw::Viewer& viewer, unsigned char key, int modifier)
 {
 {
   std::cout<<"Key: "<<key<<" "<<(unsigned int)key<<std::endl;
   std::cout<<"Key: "<<key<<" "<<(unsigned int)key<<std::endl;
   if (key == '1')
   if (key == '1')
@@ -41,7 +41,7 @@ int main(int argc, char *argv[])
 2 Switch to fertility mesh
 2 Switch to fertility mesh
     )";
     )";
 
 
-  igl::viewer::Viewer viewer;
+  igl::opengl::glfw::Viewer viewer;
   // Register a keyboard callback that allows to switch between
   // Register a keyboard callback that allows to switch between
   // the two loaded meshes
   // the two loaded meshes
   viewer.callback_key_down = &key_down;
   viewer.callback_key_down = &key_down;

+ 2 - 2
tutorial/104_Colors/main.cpp

@@ -1,5 +1,5 @@
 #include <igl/readOFF.h>
 #include <igl/readOFF.h>
-#include <igl/viewer/Viewer.h>
+#include <igl/opengl/glfw/Viewer.h>
 #include <igl/jet.h>
 #include <igl/jet.h>
 #include "tutorial_shared_path.h"
 #include "tutorial_shared_path.h"
 
 
@@ -13,7 +13,7 @@ int main(int argc, char *argv[])
   igl::readOFF(TUTORIAL_SHARED_PATH "/screwdriver.off", V, F);
   igl::readOFF(TUTORIAL_SHARED_PATH "/screwdriver.off", V, F);
 
 
   // Plot the mesh
   // Plot the mesh
-  igl::viewer::Viewer viewer;
+  igl::opengl::glfw::Viewer viewer;
   viewer.data.set_mesh(V, F);
   viewer.data.set_mesh(V, F);
 
 
   // Use the z coordinate as a scalar field over the surface
   // Use the z coordinate as a scalar field over the surface

+ 2 - 2
tutorial/105_Overlays/main.cpp

@@ -1,5 +1,5 @@
 #include <igl/readOFF.h>
 #include <igl/readOFF.h>
-#include <igl/viewer/Viewer.h>
+#include <igl/opengl/glfw/Viewer.h>
 #include <sstream>
 #include <sstream>
 #include "tutorial_shared_path.h"
 #include "tutorial_shared_path.h"
 
 
@@ -44,7 +44,7 @@ int main(int argc, char *argv[])
   7 ,3;
   7 ,3;
 
 
   // Plot the mesh
   // Plot the mesh
-  igl::viewer::Viewer viewer;
+  igl::opengl::glfw::Viewer viewer;
   viewer.data.set_mesh(V, F);
   viewer.data.set_mesh(V, F);
 
 
   // Plot the corners of the bounding box as points
   // Plot the corners of the bounding box as points

+ 3 - 3
tutorial/106_ViewerMenu/main.cpp

@@ -9,7 +9,7 @@ int main()
 #else
 #else
 
 
 #include <igl/readOFF.h>
 #include <igl/readOFF.h>
-#include <igl/viewer/Viewer.h>
+#include <igl/opengl/glfw/Viewer.h>
 #include <nanogui/formhelper.h>
 #include <nanogui/formhelper.h>
 #include <nanogui/screen.h>
 #include <nanogui/screen.h>
 #include <iostream>
 #include <iostream>
@@ -28,10 +28,10 @@ int main(int argc, char *argv[])
   igl::readOFF(TUTORIAL_SHARED_PATH "/bunny.off", V, F);
   igl::readOFF(TUTORIAL_SHARED_PATH "/bunny.off", V, F);
 
 
   // Init the viewer
   // Init the viewer
-  igl::viewer::Viewer viewer;
+  igl::opengl::glfw::Viewer viewer;
 
 
   // Extend viewer menu
   // Extend viewer menu
-  viewer.callback_init = [&](igl::viewer::Viewer& viewer)
+  viewer.callback_init = [&](igl::opengl::glfw::Viewer& viewer)
   {
   {
     // Add new group
     // Add new group
     viewer.ngui->addGroup("New Group");
     viewer.ngui->addGroup("New Group");

+ 3 - 3
tutorial/201_Normals/main.cpp

@@ -1,5 +1,5 @@
 #include <igl/readOFF.h>
 #include <igl/readOFF.h>
-#include <igl/viewer/Viewer.h>
+#include <igl/opengl/glfw/Viewer.h>
 #include <igl/per_vertex_normals.h>
 #include <igl/per_vertex_normals.h>
 #include <igl/per_face_normals.h>
 #include <igl/per_face_normals.h>
 #include <igl/per_corner_normals.h>
 #include <igl/per_corner_normals.h>
@@ -15,7 +15,7 @@ Eigen::MatrixXd N_corners;
 
 
 
 
 // This function is called every time a keyboard button is pressed
 // This function is called every time a keyboard button is pressed
-bool key_down(igl::viewer::Viewer& viewer, unsigned char key, int modifier)
+bool key_down(igl::opengl::glfw::Viewer& viewer, unsigned char key, int modifier)
 {
 {
   switch(key)
   switch(key)
   {
   {
@@ -48,7 +48,7 @@ int main(int argc, char *argv[])
   igl::per_corner_normals(V,F,20,N_corners);
   igl::per_corner_normals(V,F,20,N_corners);
 
 
   // Plot the mesh
   // Plot the mesh
-  igl::viewer::Viewer viewer;
+  igl::opengl::glfw::Viewer viewer;
   viewer.callback_key_down = &key_down;
   viewer.callback_key_down = &key_down;
   viewer.core.show_lines = false;
   viewer.core.show_lines = false;
   viewer.data.set_mesh(V, F);
   viewer.data.set_mesh(V, F);

+ 2 - 2
tutorial/202_GaussianCurvature/main.cpp

@@ -2,7 +2,7 @@
 #include <igl/massmatrix.h>
 #include <igl/massmatrix.h>
 #include <igl/invert_diag.h>
 #include <igl/invert_diag.h>
 #include <igl/readOFF.h>
 #include <igl/readOFF.h>
-#include <igl/viewer/Viewer.h>
+#include <igl/opengl/glfw/Viewer.h>
 #include <igl/jet.h>
 #include <igl/jet.h>
 #include "tutorial_shared_path.h"
 #include "tutorial_shared_path.h"
 
 
@@ -29,7 +29,7 @@ int main(int argc, char *argv[])
   igl::jet(K,true,C);
   igl::jet(K,true,C);
 
 
   // Plot the mesh with pseudocolors
   // Plot the mesh with pseudocolors
-  igl::viewer::Viewer viewer;
+  igl::opengl::glfw::Viewer viewer;
   viewer.data.set_mesh(V, F);
   viewer.data.set_mesh(V, F);
   viewer.data.set_colors(C);
   viewer.data.set_colors(C);
   viewer.launch();
   viewer.launch();

+ 2 - 2
tutorial/203_CurvatureDirections/main.cpp

@@ -8,7 +8,7 @@
 #include <igl/per_vertex_normals.h>
 #include <igl/per_vertex_normals.h>
 #include <igl/principal_curvature.h>
 #include <igl/principal_curvature.h>
 #include <igl/read_triangle_mesh.h>
 #include <igl/read_triangle_mesh.h>
-#include <igl/viewer/Viewer.h>
+#include <igl/opengl/glfw/Viewer.h>
 #include "tutorial_shared_path.h"
 #include "tutorial_shared_path.h"
 
 
 Eigen::MatrixXd V;
 Eigen::MatrixXd V;
@@ -43,7 +43,7 @@ int main(int argc, char *argv[])
   // mean curvature
   // mean curvature
   H = 0.5*(PV1+PV2);
   H = 0.5*(PV1+PV2);
 
 
-  igl::viewer::Viewer viewer;
+  igl::opengl::glfw::Viewer viewer;
   viewer.data.set_mesh(V, F);
   viewer.data.set_mesh(V, F);
 
 
 
 

+ 2 - 2
tutorial/204_Gradient/main.cpp

@@ -4,7 +4,7 @@
 #include <igl/jet.h>
 #include <igl/jet.h>
 #include <igl/readDMAT.h>
 #include <igl/readDMAT.h>
 #include <igl/readOFF.h>
 #include <igl/readOFF.h>
-#include <igl/viewer/Viewer.h>
+#include <igl/opengl/glfw/Viewer.h>
 
 
 #include <iostream>
 #include <iostream>
 #include "tutorial_shared_path.h"
 #include "tutorial_shared_path.h"
@@ -32,7 +32,7 @@ int main(int argc, char *argv[])
   // Compute gradient magnitude
   // Compute gradient magnitude
   const VectorXd GU_mag = GU.rowwise().norm();
   const VectorXd GU_mag = GU.rowwise().norm();
 
 
-  igl::viewer::Viewer viewer;
+  igl::opengl::glfw::Viewer viewer;
   viewer.data.set_mesh(V, F);
   viewer.data.set_mesh(V, F);
 
 
   // Compute pseudocolor for original function
   // Compute pseudocolor for original function

+ 3 - 3
tutorial/205_Laplacian/main.cpp

@@ -8,7 +8,7 @@
 #include <igl/readDMAT.h>
 #include <igl/readDMAT.h>
 #include <igl/readOFF.h>
 #include <igl/readOFF.h>
 #include <igl/repdiag.h>
 #include <igl/repdiag.h>
-#include <igl/viewer/Viewer.h>
+#include <igl/opengl/glfw/Viewer.h>
 
 
 #include <iostream>
 #include <iostream>
 #include "tutorial_shared_path.h"
 #include "tutorial_shared_path.h"
@@ -16,7 +16,7 @@
 Eigen::MatrixXd V,U;
 Eigen::MatrixXd V,U;
 Eigen::MatrixXi F;
 Eigen::MatrixXi F;
 Eigen::SparseMatrix<double> L;
 Eigen::SparseMatrix<double> L;
-igl::viewer::Viewer viewer;
+igl::opengl::glfw::Viewer viewer;
 
 
 int main(int argc, char *argv[])
 int main(int argc, char *argv[])
 {
 {
@@ -43,7 +43,7 @@ int main(int argc, char *argv[])
   K = -G.transpose() * T * G;
   K = -G.transpose() * T * G;
   cout<<"|K-L|: "<<(K-L).norm()<<endl;
   cout<<"|K-L|: "<<(K-L).norm()<<endl;
 
 
-  const auto &key_down = [](igl::viewer::Viewer &viewer,unsigned char key,int mod)->bool
+  const auto &key_down = [](igl::opengl::glfw::Viewer &viewer,unsigned char key,int mod)->bool
   {
   {
     switch(key)
     switch(key)
     {
     {

+ 2 - 2
tutorial/301_Slice/main.cpp

@@ -2,7 +2,7 @@
 #include <igl/readOFF.h>
 #include <igl/readOFF.h>
 #include <igl/slice.h>
 #include <igl/slice.h>
 #include <igl/slice_into.h>
 #include <igl/slice_into.h>
-#include <igl/viewer/Viewer.h>
+#include <igl/opengl/glfw/Viewer.h>
 #include <iostream>
 #include <iostream>
 #include "tutorial_shared_path.h"
 #include "tutorial_shared_path.h"
 
 
@@ -34,7 +34,7 @@ int main(int argc, char *argv[])
   igl::slice_into(R,K,1,C);
   igl::slice_into(R,K,1,C);
 
 
   // Plot the mesh with pseudocolors
   // Plot the mesh with pseudocolors
-  igl::viewer::Viewer viewer;
+  igl::opengl::glfw::Viewer viewer;
   viewer.data.set_mesh(V, F);
   viewer.data.set_mesh(V, F);
   viewer.data.set_colors(C);
   viewer.data.set_colors(C);
   viewer.launch();
   viewer.launch();

+ 2 - 2
tutorial/302_Sort/main.cpp

@@ -4,7 +4,7 @@
 #include <igl/readOFF.h>
 #include <igl/readOFF.h>
 #include <igl/slice_into.h>
 #include <igl/slice_into.h>
 #include <igl/sortrows.h>
 #include <igl/sortrows.h>
-#include <igl/viewer/Viewer.h>
+#include <igl/opengl/glfw/Viewer.h>
 #include <iostream>
 #include <iostream>
 #include "tutorial_shared_path.h"
 #include "tutorial_shared_path.h"
 
 
@@ -32,7 +32,7 @@ int main(int argc, char *argv[])
   igl::jet(J,true,C);
   igl::jet(J,true,C);
 
 
   // Plot the mesh with pseudocolors
   // Plot the mesh with pseudocolors
-  igl::viewer::Viewer viewer;
+  igl::opengl::glfw::Viewer viewer;
   viewer.data.set_mesh(V, F);
   viewer.data.set_mesh(V, F);
   viewer.data.set_colors(C);
   viewer.data.set_colors(C);
   viewer.launch();
   viewer.launch();

+ 2 - 2
tutorial/303_LaplaceEquation/main.cpp

@@ -8,7 +8,7 @@
 #include <igl/slice.h>
 #include <igl/slice.h>
 #include <igl/slice_into.h>
 #include <igl/slice_into.h>
 #include <igl/unique.h>
 #include <igl/unique.h>
-#include <igl/viewer/Viewer.h>
+#include <igl/opengl/glfw/Viewer.h>
 #include <Eigen/Sparse>
 #include <Eigen/Sparse>
 #include <iostream>
 #include <iostream>
 #include "tutorial_shared_path.h"
 #include "tutorial_shared_path.h"
@@ -65,7 +65,7 @@ int main(int argc, char *argv[])
   igl::jet(Z,true,C);
   igl::jet(Z,true,C);
 
 
   // Plot the mesh with pseudocolors
   // Plot the mesh with pseudocolors
-  igl::viewer::Viewer viewer;
+  igl::opengl::glfw::Viewer viewer;
   viewer.data.set_mesh(V, F);
   viewer.data.set_mesh(V, F);
   viewer.core.show_lines = false;
   viewer.core.show_lines = false;
   viewer.data.set_colors(C);
   viewer.data.set_colors(C);

+ 3 - 3
tutorial/304_LinearEqualityConstraints/main.cpp

@@ -5,7 +5,7 @@
 #include <igl/massmatrix.h>
 #include <igl/massmatrix.h>
 #include <igl/min_quad_with_fixed.h>
 #include <igl/min_quad_with_fixed.h>
 #include <igl/readOFF.h>
 #include <igl/readOFF.h>
-#include <igl/viewer/Viewer.h>
+#include <igl/opengl/glfw/Viewer.h>
 #include <Eigen/Sparse>
 #include <Eigen/Sparse>
 #include <iostream>
 #include <iostream>
 #include "tutorial_shared_path.h"
 #include "tutorial_shared_path.h"
@@ -72,13 +72,13 @@ int main(int argc, char *argv[])
   igl::jet(Z_const,min_z,max_z,data.C_const);
   igl::jet(Z_const,min_z,max_z,data.C_const);
 
 
   // Plot the mesh with pseudocolors
   // Plot the mesh with pseudocolors
-  igl::viewer::Viewer viewer;
+  igl::opengl::glfw::Viewer viewer;
   viewer.data.set_mesh(V, F);
   viewer.data.set_mesh(V, F);
   viewer.core.show_lines = false;
   viewer.core.show_lines = false;
   viewer.data.set_colors(data.C);
   viewer.data.set_colors(data.C);
 
 
   viewer.callback_key_down = 
   viewer.callback_key_down = 
-    [](igl::viewer::Viewer& viewer,unsigned char key,int mod)->bool
+    [](igl::opengl::glfw::Viewer& viewer,unsigned char key,int mod)->bool
     {
     {
       if(key == ' ')
       if(key == ' ')
       {
       {

+ 4 - 4
tutorial/305_QuadraticProgramming/main.cpp

@@ -5,7 +5,7 @@
 #include <igl/jet.h>
 #include <igl/jet.h>
 #include <igl/massmatrix.h>
 #include <igl/massmatrix.h>
 #include <igl/readOFF.h>
 #include <igl/readOFF.h>
-#include <igl/viewer/Viewer.h>
+#include <igl/opengl/glfw/Viewer.h>
 #include <Eigen/Sparse>
 #include <Eigen/Sparse>
 #include <iostream>
 #include <iostream>
 #include "tutorial_shared_path.h"
 #include "tutorial_shared_path.h"
@@ -14,7 +14,7 @@ Eigen::VectorXi b;
 Eigen::VectorXd B,bc,lx,ux,Beq,Bieq,Z;
 Eigen::VectorXd B,bc,lx,ux,Beq,Bieq,Z;
 Eigen::SparseMatrix<double> Q,Aeq,Aieq;
 Eigen::SparseMatrix<double> Q,Aeq,Aieq;
 
 
-void solve(igl::viewer::Viewer &viewer)
+void solve(igl::opengl::glfw::Viewer &viewer)
 {
 {
   using namespace std;
   using namespace std;
   igl::active_set_params as;
   igl::active_set_params as;
@@ -26,7 +26,7 @@ void solve(igl::viewer::Viewer &viewer)
   viewer.data.set_colors(C);
   viewer.data.set_colors(C);
 }
 }
 
 
-bool key_down(igl::viewer::Viewer &viewer, unsigned char key, int mod)
+bool key_down(igl::opengl::glfw::Viewer &viewer, unsigned char key, int mod)
 {
 {
   switch(key)
   switch(key)
   {
   {
@@ -56,7 +56,7 @@ int main(int argc, char *argv[])
   igl::readOFF(TUTORIAL_SHARED_PATH "/cheburashka.off",V,F);
   igl::readOFF(TUTORIAL_SHARED_PATH "/cheburashka.off",V,F);
 
 
   // Plot the mesh
   // Plot the mesh
-  igl::viewer::Viewer viewer;
+  igl::opengl::glfw::Viewer viewer;
   viewer.data.set_mesh(V, F);
   viewer.data.set_mesh(V, F);
   viewer.core.show_lines = false;
   viewer.core.show_lines = false;
   viewer.callback_key_down = &key_down;
   viewer.callback_key_down = &key_down;

+ 3 - 3
tutorial/306_EigenDecomposition/main.cpp

@@ -1,7 +1,7 @@
 #include <igl/eigs.h>
 #include <igl/eigs.h>
 #include <igl/cotmatrix.h>
 #include <igl/cotmatrix.h>
 #include <igl/massmatrix.h>
 #include <igl/massmatrix.h>
-#include <igl/viewer/Viewer.h>
+#include <igl/opengl/glfw/Viewer.h>
 #include <igl/parula.h>
 #include <igl/parula.h>
 #include <igl/read_triangle_mesh.h>
 #include <igl/read_triangle_mesh.h>
 #include <Eigen/Sparse>
 #include <Eigen/Sparse>
@@ -38,8 +38,8 @@ int main(int argc, char * argv[])
   }
   }
   U = ((U.array()-U.minCoeff())/(U.maxCoeff()-U.minCoeff())).eval();
   U = ((U.array()-U.minCoeff())/(U.maxCoeff()-U.minCoeff())).eval();
 
 
-  igl::viewer::Viewer viewer;
-  viewer.callback_key_down = [&](igl::viewer::Viewer & viewer,unsigned char key,int)->bool
+  igl::opengl::glfw::Viewer viewer;
+  viewer.callback_key_down = [&](igl::opengl::glfw::Viewer & viewer,unsigned char key,int)->bool
   {
   {
     switch(key)
     switch(key)
     {
     {

+ 4 - 4
tutorial/401_BiharmonicDeformation/main.cpp

@@ -2,7 +2,7 @@
 #include <igl/harmonic.h>
 #include <igl/harmonic.h>
 #include <igl/readOBJ.h>
 #include <igl/readOBJ.h>
 #include <igl/readDMAT.h>
 #include <igl/readDMAT.h>
-#include <igl/viewer/Viewer.h>
+#include <igl/opengl/glfw/Viewer.h>
 #include <algorithm>
 #include <algorithm>
 #include <iostream>
 #include <iostream>
 #include "tutorial_shared_path.h"
 #include "tutorial_shared_path.h"
@@ -15,7 +15,7 @@ Eigen::VectorXd Z;
 Eigen::MatrixXi F;
 Eigen::MatrixXi F;
 Eigen::VectorXi b;
 Eigen::VectorXi b;
 
 
-bool pre_draw(igl::viewer::Viewer & viewer)
+bool pre_draw(igl::opengl::glfw::Viewer & viewer)
 {
 {
   using namespace Eigen;
   using namespace Eigen;
   // Determine boundary conditions
   // Determine boundary conditions
@@ -41,7 +41,7 @@ bool pre_draw(igl::viewer::Viewer & viewer)
   return false;
   return false;
 }
 }
 
 
-bool key_down(igl::viewer::Viewer &viewer, unsigned char key, int mods)
+bool key_down(igl::opengl::glfw::Viewer &viewer, unsigned char key, int mods)
 {
 {
   switch(key)
   switch(key)
   {
   {
@@ -109,7 +109,7 @@ int main(int argc, char *argv[])
   }
   }
 
 
   // Plot the mesh with pseudocolors
   // Plot the mesh with pseudocolors
-  igl::viewer::Viewer viewer;
+  igl::opengl::glfw::Viewer viewer;
   viewer.data.set_mesh(U, F);
   viewer.data.set_mesh(U, F);
   viewer.core.show_lines = false;
   viewer.core.show_lines = false;
   viewer.data.set_colors(C);
   viewer.data.set_colors(C);

+ 4 - 4
tutorial/402_PolyharmonicDeformation/main.cpp

@@ -1,7 +1,7 @@
 #include <igl/colon.h>
 #include <igl/colon.h>
 #include <igl/harmonic.h>
 #include <igl/harmonic.h>
 #include <igl/readOBJ.h>
 #include <igl/readOBJ.h>
-#include <igl/viewer/Viewer.h>
+#include <igl/opengl/glfw/Viewer.h>
 #include <algorithm>
 #include <algorithm>
 #include <iostream>
 #include <iostream>
 #include "tutorial_shared_path.h"
 #include "tutorial_shared_path.h"
@@ -16,7 +16,7 @@ Eigen::MatrixXi F;
 Eigen::VectorXi b;
 Eigen::VectorXi b;
 Eigen::VectorXd bc;
 Eigen::VectorXd bc;
 
 
-bool pre_draw(igl::viewer::Viewer & viewer)
+bool pre_draw(igl::opengl::glfw::Viewer & viewer)
 {
 {
   using namespace Eigen;
   using namespace Eigen;
   if(resolve)
   if(resolve)
@@ -35,7 +35,7 @@ bool pre_draw(igl::viewer::Viewer & viewer)
   return false;
   return false;
 }
 }
 
 
-bool key_down(igl::viewer::Viewer &viewer, unsigned char key, int mods)
+bool key_down(igl::opengl::glfw::Viewer &viewer, unsigned char key, int mods)
 {
 {
   switch(key)
   switch(key)
   {
   {
@@ -93,7 +93,7 @@ int main(int argc, char *argv[])
   }
   }
 
 
   // Plot the mesh with pseudocolors
   // Plot the mesh with pseudocolors
-  igl::viewer::Viewer viewer;
+  igl::opengl::glfw::Viewer viewer;
   viewer.data.set_mesh(U, F);
   viewer.data.set_mesh(U, F);
   viewer.core.show_lines = false;
   viewer.core.show_lines = false;
   viewer.data.set_colors(C);
   viewer.data.set_colors(C);

+ 5 - 5
tutorial/403_BoundedBiharmonicWeights/main.cpp

@@ -20,7 +20,7 @@
 #include <igl/readDMAT.h>
 #include <igl/readDMAT.h>
 #include <igl/readMESH.h>
 #include <igl/readMESH.h>
 #include <igl/readTGF.h>
 #include <igl/readTGF.h>
-#include <igl/viewer/Viewer.h>
+#include <igl/opengl/glfw/Viewer.h>
 #include <igl/bbw.h>
 #include <igl/bbw.h>
 //#include <igl/embree/bone_heat.h>
 //#include <igl/embree/bone_heat.h>
 
 
@@ -45,7 +45,7 @@ RotationList pose;
 double anim_t = 1.0;
 double anim_t = 1.0;
 double anim_t_dir = -0.03;
 double anim_t_dir = -0.03;
 
 
-bool pre_draw(igl::viewer::Viewer & viewer)
+bool pre_draw(igl::opengl::glfw::Viewer & viewer)
 {
 {
   using namespace Eigen;
   using namespace Eigen;
   using namespace std;
   using namespace std;
@@ -88,14 +88,14 @@ bool pre_draw(igl::viewer::Viewer & viewer)
   return false;
   return false;
 }
 }
 
 
-void set_color(igl::viewer::Viewer &viewer)
+void set_color(igl::opengl::glfw::Viewer &viewer)
 {
 {
   Eigen::MatrixXd C;
   Eigen::MatrixXd C;
   igl::jet(W.col(selected).eval(),true,C);
   igl::jet(W.col(selected).eval(),true,C);
   viewer.data.set_colors(C);
   viewer.data.set_colors(C);
 }
 }
 
 
-bool key_down(igl::viewer::Viewer &viewer, unsigned char key, int mods)
+bool key_down(igl::opengl::glfw::Viewer &viewer, unsigned char key, int mods)
 {
 {
   switch(key)
   switch(key)
   {
   {
@@ -163,7 +163,7 @@ int main(int argc, char *argv[])
   igl::lbs_matrix(V,W,M);
   igl::lbs_matrix(V,W,M);
 
 
   // Plot the mesh with pseudocolors
   // Plot the mesh with pseudocolors
-  igl::viewer::Viewer viewer;
+  igl::opengl::glfw::Viewer viewer;
   viewer.data.set_mesh(U, F);
   viewer.data.set_mesh(U, F);
   set_color(viewer);
   set_color(viewer);
   viewer.data.set_edges(C,BE,sea_green);
   viewer.data.set_edges(C,BE,sea_green);

+ 4 - 4
tutorial/404_DualQuaternionSkinning/main.cpp

@@ -8,7 +8,7 @@
 #include <igl/readDMAT.h>
 #include <igl/readDMAT.h>
 #include <igl/readOBJ.h>
 #include <igl/readOBJ.h>
 #include <igl/readTGF.h>
 #include <igl/readTGF.h>
-#include <igl/viewer/Viewer.h>
+#include <igl/opengl/glfw/Viewer.h>
 
 
 #include <Eigen/Geometry>
 #include <Eigen/Geometry>
 #include <Eigen/StdVector>
 #include <Eigen/StdVector>
@@ -32,7 +32,7 @@ double anim_t_dir = 0.015;
 bool use_dqs = false;
 bool use_dqs = false;
 bool recompute = true;
 bool recompute = true;
 
 
-bool pre_draw(igl::viewer::Viewer & viewer)
+bool pre_draw(igl::opengl::glfw::Viewer & viewer)
 {
 {
   using namespace Eigen;
   using namespace Eigen;
   using namespace std;
   using namespace std;
@@ -92,7 +92,7 @@ bool pre_draw(igl::viewer::Viewer & viewer)
   return false;
   return false;
 }
 }
 
 
-bool key_down(igl::viewer::Viewer &viewer, unsigned char key, int mods)
+bool key_down(igl::opengl::glfw::Viewer &viewer, unsigned char key, int mods)
 {
 {
   recompute = true;
   recompute = true;
   switch(key)
   switch(key)
@@ -130,7 +130,7 @@ int main(int argc, char *argv[])
   igl::lbs_matrix(V,W,M);
   igl::lbs_matrix(V,W,M);
 
 
   // Plot the mesh with pseudocolors
   // Plot the mesh with pseudocolors
-  igl::viewer::Viewer viewer;
+  igl::opengl::glfw::Viewer viewer;
   viewer.data.set_mesh(U, F);
   viewer.data.set_mesh(U, F);
   viewer.data.set_edges(C,BE,sea_green);
   viewer.data.set_edges(C,BE,sea_green);
   viewer.core.show_lines = false;
   viewer.core.show_lines = false;

+ 4 - 4
tutorial/405_AsRigidAsPossible/main.cpp

@@ -9,7 +9,7 @@
 #include <igl/readDMAT.h>
 #include <igl/readDMAT.h>
 #include <igl/readOFF.h>
 #include <igl/readOFF.h>
 #include <igl/arap.h>
 #include <igl/arap.h>
-#include <igl/viewer/Viewer.h>
+#include <igl/opengl/glfw/Viewer.h>
 
 
 #include <Eigen/Geometry>
 #include <Eigen/Geometry>
 #include <Eigen/StdVector>
 #include <Eigen/StdVector>
@@ -32,7 +32,7 @@ double anim_t = 0.0;
 double anim_t_dir = 0.03;
 double anim_t_dir = 0.03;
 igl::ARAPData arap_data;
 igl::ARAPData arap_data;
 
 
-bool pre_draw(igl::viewer::Viewer & viewer)
+bool pre_draw(igl::opengl::glfw::Viewer & viewer)
 {
 {
   using namespace Eigen;
   using namespace Eigen;
   using namespace std;
   using namespace std;
@@ -77,7 +77,7 @@ bool pre_draw(igl::viewer::Viewer & viewer)
   return false;
   return false;
 }
 }
 
 
-bool key_down(igl::viewer::Viewer &viewer, unsigned char key, int mods)
+bool key_down(igl::opengl::glfw::Viewer &viewer, unsigned char key, int mods)
 {
 {
   switch(key)
   switch(key)
   {
   {
@@ -122,7 +122,7 @@ int main(int argc, char *argv[])
   }
   }
 
 
   // Plot the mesh with pseudocolors
   // Plot the mesh with pseudocolors
-  igl::viewer::Viewer viewer;
+  igl::opengl::glfw::Viewer viewer;
   viewer.data.set_mesh(U, F);
   viewer.data.set_mesh(U, F);
   viewer.data.set_colors(C);
   viewer.data.set_colors(C);
   viewer.callback_pre_draw = &pre_draw;
   viewer.callback_pre_draw = &pre_draw;

+ 4 - 4
tutorial/406_FastAutomaticSkinningTransformations/main.cpp

@@ -15,7 +15,7 @@
 #include <igl/readOBJ.h>
 #include <igl/readOBJ.h>
 #include <igl/arap.h>
 #include <igl/arap.h>
 #include <igl/arap_dof.h>
 #include <igl/arap_dof.h>
-#include <igl/viewer/Viewer.h>
+#include <igl/opengl/glfw/Viewer.h>
 
 
 #include <Eigen/Geometry>
 #include <Eigen/Geometry>
 #include <Eigen/StdVector>
 #include <Eigen/StdVector>
@@ -51,7 +51,7 @@ enum ModeType
   NUM_MODE_TYPES = 4
   NUM_MODE_TYPES = 4
 } mode = MODE_TYPE_ARAP;
 } mode = MODE_TYPE_ARAP;
 
 
-bool pre_draw(igl::viewer::Viewer & viewer)
+bool pre_draw(igl::opengl::glfw::Viewer & viewer)
 {
 {
   using namespace Eigen;
   using namespace Eigen;
   using namespace std;
   using namespace std;
@@ -113,7 +113,7 @@ bool pre_draw(igl::viewer::Viewer & viewer)
   return false;
   return false;
 }
 }
 
 
-bool key_down(igl::viewer::Viewer &viewer, unsigned char key, int mods)
+bool key_down(igl::opengl::glfw::Viewer &viewer, unsigned char key, int mods)
 {
 {
   switch(key)
   switch(key)
   {
   {
@@ -204,7 +204,7 @@ int main(int argc, char *argv[])
   bbd = (V.colwise().maxCoeff()- V.colwise().minCoeff()).norm();
   bbd = (V.colwise().maxCoeff()- V.colwise().minCoeff()).norm();
 
 
   // Plot the mesh with pseudocolors
   // Plot the mesh with pseudocolors
-  igl::viewer::Viewer viewer;
+  igl::opengl::glfw::Viewer viewer;
   viewer.data.set_mesh(U, F);
   viewer.data.set_mesh(U, F);
   viewer.data.add_points(igl::slice(V,b,1),sea_green);
   viewer.data.add_points(igl::slice(V,b,1),sea_green);
   viewer.core.show_lines = false;
   viewer.core.show_lines = false;

+ 6 - 5
tutorial/407_BiharmonicCoordinates/main.cpp

@@ -1,3 +1,4 @@
+#include <igl/opengl/gl.h>
 #include <igl/arap.h>
 #include <igl/arap.h>
 #include <igl/biharmonic_coordinates.h>
 #include <igl/biharmonic_coordinates.h>
 #include <igl/cat.h>
 #include <igl/cat.h>
@@ -11,7 +12,7 @@
 #include <igl/remove_unreferenced.h>
 #include <igl/remove_unreferenced.h>
 #include <igl/slice.h>
 #include <igl/slice.h>
 #include <igl/writeDMAT.h>
 #include <igl/writeDMAT.h>
-#include <igl/viewer/Viewer.h>
+#include <igl/opengl/glfw/Viewer.h>
 #include <Eigen/Sparse>
 #include <Eigen/Sparse>
 #include <iostream>
 #include <iostream>
 #include <queue>
 #include <queue>
@@ -100,7 +101,7 @@ int main(int argc, char * argv[])
   // Random initial velocities to wiggle things
   // Random initial velocities to wiggle things
   arap_data.vel = MatrixXd::Random(n,3);
   arap_data.vel = MatrixXd::Random(n,3);
   
   
-  igl::viewer::Viewer viewer;
+  igl::opengl::glfw::Viewer viewer;
   // Create one huge mesh containing both meshes
   // Create one huge mesh containing both meshes
   igl::cat(1,low.U,high.U,scene.U);
   igl::cat(1,low.U,high.U,scene.U);
   igl::cat(1,low.F,MatrixXi(high.F.array()+low.V.rows()),scene.F);
   igl::cat(1,low.F,MatrixXi(high.F.array()+low.V.rows()),scene.F);
@@ -113,7 +114,7 @@ int main(int argc, char * argv[])
   viewer.data.set_colors(C);
   viewer.data.set_colors(C);
 
 
   viewer.callback_key_pressed = 
   viewer.callback_key_pressed = 
-    [&](igl::viewer::Viewer & viewer,unsigned int key,int mods)->bool
+    [&](igl::opengl::glfw::Viewer & viewer,unsigned int key,int mods)->bool
   {
   {
     switch(key)
     switch(key)
     {
     {
@@ -127,7 +128,7 @@ int main(int argc, char * argv[])
         return true;
         return true;
     }
     }
   };
   };
-  viewer.callback_pre_draw = [&](igl::viewer::Viewer & viewer)->bool
+  viewer.callback_pre_draw = [&](igl::opengl::glfw::Viewer & viewer)->bool
   {
   {
     glEnable(GL_CULL_FACE);
     glEnable(GL_CULL_FACE);
     if(viewer.core.is_animating)
     if(viewer.core.is_animating)
@@ -164,6 +165,6 @@ int main(int argc, char * argv[])
 'r'     to reset positions 
 'r'     to reset positions 
       )";
       )";
   viewer.core.rotation_type = 
   viewer.core.rotation_type = 
-    igl::viewer::ViewerCore::ROTATION_TYPE_TWO_AXIS_VALUATOR_FIXED_UP;
+    igl::opengl::ViewerCore::ROTATION_TYPE_TWO_AXIS_VALUATOR_FIXED_UP;
   viewer.launch();
   viewer.launch();
 }
 }

+ 3 - 3
tutorial/501_HarmonicParam/main.cpp

@@ -2,7 +2,7 @@
 #include <igl/harmonic.h>
 #include <igl/harmonic.h>
 #include <igl/map_vertices_to_circle.h>
 #include <igl/map_vertices_to_circle.h>
 #include <igl/readOFF.h>
 #include <igl/readOFF.h>
-#include <igl/viewer/Viewer.h>
+#include <igl/opengl/glfw/Viewer.h>
 
 
 #include "tutorial_shared_path.h"
 #include "tutorial_shared_path.h"
 
 
@@ -10,7 +10,7 @@ Eigen::MatrixXd V;
 Eigen::MatrixXi F;
 Eigen::MatrixXi F;
 Eigen::MatrixXd V_uv;
 Eigen::MatrixXd V_uv;
 
 
-bool key_down(igl::viewer::Viewer& viewer, unsigned char key, int modifier)
+bool key_down(igl::opengl::glfw::Viewer& viewer, unsigned char key, int modifier)
 {
 {
   if (key == '1')
   if (key == '1')
   {
   {
@@ -50,7 +50,7 @@ int main(int argc, char *argv[])
   V_uv *= 5;
   V_uv *= 5;
 
 
   // Plot the mesh
   // Plot the mesh
-  igl::viewer::Viewer viewer;
+  igl::opengl::glfw::Viewer viewer;
   viewer.data.set_mesh(V, F);
   viewer.data.set_mesh(V, F);
   viewer.data.set_uv(V_uv);
   viewer.data.set_uv(V_uv);
   viewer.callback_key_down = &key_down;
   viewer.callback_key_down = &key_down;

+ 3 - 3
tutorial/502_LSCMParam/main.cpp

@@ -1,6 +1,6 @@
 #include <igl/boundary_loop.h>
 #include <igl/boundary_loop.h>
 #include <igl/readOFF.h>
 #include <igl/readOFF.h>
-#include <igl/viewer/Viewer.h>
+#include <igl/opengl/glfw/Viewer.h>
 
 
 #include <igl/lscm.h>
 #include <igl/lscm.h>
 
 
@@ -10,7 +10,7 @@ Eigen::MatrixXd V;
 Eigen::MatrixXi F;
 Eigen::MatrixXi F;
 Eigen::MatrixXd V_uv;
 Eigen::MatrixXd V_uv;
 
 
-bool key_down(igl::viewer::Viewer& viewer, unsigned char key, int modifier)
+bool key_down(igl::opengl::glfw::Viewer& viewer, unsigned char key, int modifier)
 {
 {
 
 
   if (key == '1')
   if (key == '1')
@@ -54,7 +54,7 @@ int main(int argc, char *argv[])
   V_uv *= 5;
   V_uv *= 5;
 
 
   // Plot the mesh
   // Plot the mesh
-  igl::viewer::Viewer viewer;
+  igl::opengl::glfw::Viewer viewer;
   viewer.data.set_mesh(V, F);
   viewer.data.set_mesh(V, F);
   viewer.data.set_uv(V_uv);
   viewer.data.set_uv(V_uv);
   viewer.callback_key_down = &key_down;
   viewer.callback_key_down = &key_down;

+ 3 - 3
tutorial/503_ARAPParam/main.cpp

@@ -3,7 +3,7 @@
 #include <igl/harmonic.h>
 #include <igl/harmonic.h>
 #include <igl/map_vertices_to_circle.h>
 #include <igl/map_vertices_to_circle.h>
 #include <igl/readOFF.h>
 #include <igl/readOFF.h>
-#include <igl/viewer/Viewer.h>
+#include <igl/opengl/glfw/Viewer.h>
 
 
 #include "tutorial_shared_path.h"
 #include "tutorial_shared_path.h"
 
 
@@ -14,7 +14,7 @@ Eigen::MatrixXd initial_guess;
 
 
 bool show_uv = false;
 bool show_uv = false;
 
 
-bool key_down(igl::viewer::Viewer& viewer, unsigned char key, int modifier)
+bool key_down(igl::opengl::glfw::Viewer& viewer, unsigned char key, int modifier)
 {
 {
   if (key == '1')
   if (key == '1')
     show_uv = false;
     show_uv = false;
@@ -76,7 +76,7 @@ int main(int argc, char *argv[])
   V_uv *= 20;
   V_uv *= 20;
 
 
   // Plot the mesh
   // Plot the mesh
-  igl::viewer::Viewer viewer;
+  igl::opengl::glfw::Viewer viewer;
   viewer.data.set_mesh(V, F);
   viewer.data.set_mesh(V, F);
   viewer.data.set_uv(V_uv);
   viewer.data.set_uv(V_uv);
   viewer.callback_key_down = &key_down;
   viewer.callback_key_down = &key_down;

+ 4 - 4
tutorial/504_NRosyDesign/main.cpp

@@ -3,7 +3,7 @@
 #include <igl/local_basis.h>
 #include <igl/local_basis.h>
 #include <igl/readOFF.h>
 #include <igl/readOFF.h>
 #include <igl/copyleft/comiso/nrosy.h>
 #include <igl/copyleft/comiso/nrosy.h>
-#include <igl/viewer/Viewer.h>
+#include <igl/opengl/glfw/Viewer.h>
 
 
 #include "tutorial_shared_path.h"
 #include "tutorial_shared_path.h"
 
 
@@ -55,7 +55,7 @@ void representative_to_nrosy(
 // Plots the mesh with an N-RoSy field and its singularities on top
 // Plots the mesh with an N-RoSy field and its singularities on top
 // The constrained faces (b) are colored in red.
 // The constrained faces (b) are colored in red.
 void plot_mesh_nrosy(
 void plot_mesh_nrosy(
-  igl::viewer::Viewer& viewer,
+  igl::opengl::glfw::Viewer& viewer,
   Eigen::MatrixXd& V,
   Eigen::MatrixXd& V,
   Eigen::MatrixXi& F,
   Eigen::MatrixXi& F,
   int N,
   int N,
@@ -101,7 +101,7 @@ void plot_mesh_nrosy(
 }
 }
 
 
   // It allows to change the degree of the field when a number is pressed
   // It allows to change the degree of the field when a number is pressed
-bool key_down(igl::viewer::Viewer& viewer, unsigned char key, int modifier)
+bool key_down(igl::opengl::glfw::Viewer& viewer, unsigned char key, int modifier)
 {
 {
   using namespace Eigen;
   using namespace Eigen;
   using namespace std;
   using namespace std;
@@ -131,7 +131,7 @@ int main(int argc, char *argv[])
   bc.resize(1,3);
   bc.resize(1,3);
   bc << 1,1,1;
   bc << 1,1,1;
 
 
-  igl::viewer::Viewer viewer;
+  igl::opengl::glfw::Viewer viewer;
 
 
   // Interpolate the field and plot
   // Interpolate the field and plot
   key_down(viewer, '4', 0);
   key_down(viewer, '4', 0);

+ 3 - 3
tutorial/505_MIQ/main.cpp

@@ -11,7 +11,7 @@
 #include <igl/rotate_vectors.h>
 #include <igl/rotate_vectors.h>
 #include <igl/copyleft/comiso/miq.h>
 #include <igl/copyleft/comiso/miq.h>
 #include <igl/copyleft/comiso/nrosy.h>
 #include <igl/copyleft/comiso/nrosy.h>
-#include <igl/viewer/Viewer.h>
+#include <igl/opengl/glfw/Viewer.h>
 #include <sstream>
 #include <sstream>
 
 
 #include "tutorial_shared_path.h"
 #include "tutorial_shared_path.h"
@@ -79,7 +79,7 @@ void line_texture(Eigen::Matrix<unsigned char,Eigen::Dynamic,Eigen::Dynamic> &te
     texture_B = texture_R;
     texture_B = texture_R;
   }
   }
 
 
-bool key_down(igl::viewer::Viewer& viewer, unsigned char key, int modifier)
+bool key_down(igl::opengl::glfw::Viewer& viewer, unsigned char key, int modifier)
 {
 {
   if (key == 'E')
   if (key == 'E')
   {
   {
@@ -314,7 +314,7 @@ igl::copyleft::comiso::miq(V,
          false);
          false);
 
 
   // Plot the mesh
   // Plot the mesh
-  igl::viewer::Viewer viewer;
+  igl::opengl::glfw::Viewer viewer;
 
 
   // Plot the original mesh with a texture parametrization
   // Plot the original mesh with a texture parametrization
   key_down(viewer,'7',0);
   key_down(viewer,'7',0);

+ 3 - 3
tutorial/506_FrameField/main.cpp

@@ -10,7 +10,7 @@
 #include <igl/copyleft/comiso/nrosy.h>
 #include <igl/copyleft/comiso/nrosy.h>
 #include <igl/copyleft/comiso/miq.h>
 #include <igl/copyleft/comiso/miq.h>
 #include <igl/copyleft/comiso/frame_field.h>
 #include <igl/copyleft/comiso/frame_field.h>
-#include <igl/viewer/Viewer.h>
+#include <igl/opengl/glfw/Viewer.h>
 
 
 #include "tutorial_shared_path.h"
 #include "tutorial_shared_path.h"
 
 
@@ -68,7 +68,7 @@ void line_texture(Eigen::Matrix<unsigned char,Eigen::Dynamic,Eigen::Dynamic> &te
   texture_B = texture_R;
   texture_B = texture_R;
 }
 }
 
 
-bool key_down(igl::viewer::Viewer& viewer, unsigned char key, int modifier)
+bool key_down(igl::opengl::glfw::Viewer& viewer, unsigned char key, int modifier)
 {
 {
   using namespace std;
   using namespace std;
   using namespace Eigen;
   using namespace Eigen;
@@ -245,7 +245,7 @@ int main(int argc, char *argv[])
            false,
            false,
            2);
            2);
 
 
-  igl::viewer::Viewer viewer;
+  igl::opengl::glfw::Viewer viewer;
   // Plot the original mesh with a texture parametrization
   // Plot the original mesh with a texture parametrization
   key_down(viewer,'6',0);
   key_down(viewer,'6',0);
 
 

+ 3 - 3
tutorial/507_PolyVectorField/main.cpp

@@ -5,7 +5,7 @@
 #include <igl/n_polyvector.h>
 #include <igl/n_polyvector.h>
 #include <igl/readDMAT.h>
 #include <igl/readDMAT.h>
 #include <igl/readOBJ.h>
 #include <igl/readOBJ.h>
-#include <igl/viewer/Viewer.h>
+#include <igl/opengl/glfw/Viewer.h>
 #include <cstdlib>
 #include <cstdlib>
 #include <iostream>
 #include <iostream>
 #include <vector>
 #include <vector>
@@ -70,7 +70,7 @@ Eigen::VectorXd random_constraints(const
   return r;
   return r;
 }
 }
 
 
-bool key_down(igl::viewer::Viewer& viewer, unsigned char key, int modifier)
+bool key_down(igl::opengl::glfw::Viewer& viewer, unsigned char key, int modifier)
 {
 {
   using namespace std;
   using namespace std;
   using namespace Eigen;
   using namespace Eigen;
@@ -144,7 +144,7 @@ int main(int argc, char *argv[])
   // Make the example deterministic
   // Make the example deterministic
   srand(0);
   srand(0);
 
 
-  igl::viewer::Viewer viewer;
+  igl::opengl::glfw::Viewer viewer;
   viewer.data.set_mesh(V, F);
   viewer.data.set_mesh(V, F);
   viewer.callback_key_down = &key_down;
   viewer.callback_key_down = &key_down;
   viewer.core.show_lines = false;
   viewer.core.show_lines = false;

+ 3 - 3
tutorial/508_ConjugateField/main.cpp

@@ -8,7 +8,7 @@
 #include <igl/n_polyvector.h>
 #include <igl/n_polyvector.h>
 #include <igl/readDMAT.h>
 #include <igl/readDMAT.h>
 #include <igl/readOBJ.h>
 #include <igl/readOBJ.h>
-#include <igl/viewer/Viewer.h>
+#include <igl/opengl/glfw/Viewer.h>
 #include <vector>
 #include <vector>
 #include <cstdlib>
 #include <cstdlib>
 
 
@@ -34,7 +34,7 @@ Eigen::VectorXd conjugacy_s;
 Eigen::VectorXd conjugacy_c;
 Eigen::VectorXd conjugacy_c;
 
 
 
 
-bool key_down(igl::viewer::Viewer& viewer, unsigned char key, int modifier)
+bool key_down(igl::opengl::glfw::Viewer& viewer, unsigned char key, int modifier)
 {
 {
   using namespace std;
   using namespace std;
   using namespace Eigen;
   using namespace Eigen;
@@ -173,7 +173,7 @@ int main(int argc, char *argv[])
   pvV << igl::dot_row(Vc,B1), igl::dot_row(Vc,B2);
   pvV << igl::dot_row(Vc,B1), igl::dot_row(Vc,B2);
   csdata.evaluateConjugacy(pvU, pvV, conjugacy_c);
   csdata.evaluateConjugacy(pvU, pvV, conjugacy_c);
   // Launch the viewer
   // Launch the viewer
-  igl::viewer::Viewer viewer;
+  igl::opengl::glfw::Viewer viewer;
   viewer.core.invert_normals = true;
   viewer.core.invert_normals = true;
   viewer.core.show_lines = false;
   viewer.core.show_lines = false;
   viewer.core.show_texture = false;
   viewer.core.show_texture = false;

+ 3 - 3
tutorial/509_Planarization/main.cpp

@@ -6,7 +6,7 @@
 #include <igl/readDMAT.h>
 #include <igl/readDMAT.h>
 #include <igl/readOFF.h>
 #include <igl/readOFF.h>
 #include <igl/slice.h>
 #include <igl/slice.h>
-#include <igl/viewer/Viewer.h>
+#include <igl/opengl/glfw/Viewer.h>
 #include <vector>
 #include <vector>
 #include <cstdlib>
 #include <cstdlib>
 
 
@@ -28,7 +28,7 @@ Eigen::MatrixXd PQC0plan, PQC1plan, PQC2plan, PQC3plan;
 double global_scale; //TODO: not used
 double global_scale; //TODO: not used
 
 
 
 
-bool key_down(igl::viewer::Viewer& viewer, unsigned char key, int modifier)
+bool key_down(igl::opengl::glfw::Viewer& viewer, unsigned char key, int modifier)
 {
 {
   using namespace std;
   using namespace std;
   using namespace Eigen;
   using namespace Eigen;
@@ -107,7 +107,7 @@ int main(int argc, char *argv[])
   igl::slice( VQCplan, FQC.col(3).eval(), 1, PQC3plan);
   igl::slice( VQCplan, FQC.col(3).eval(), 1, PQC3plan);
 
 
   // Launch the viewer
   // Launch the viewer
-  igl::viewer::Viewer viewer;
+  igl::opengl::glfw::Viewer viewer;
   key_down(viewer,'2',0);
   key_down(viewer,'2',0);
   viewer.core.invert_normals = true;
   viewer.core.invert_normals = true;
   viewer.core.show_lines = false;
   viewer.core.show_lines = false;

+ 7 - 7
tutorial/510_Integrable/main.cpp

@@ -2,7 +2,7 @@
 #include <igl/readOBJ.h>
 #include <igl/readOBJ.h>
 #include <igl/n_polyvector.h>
 #include <igl/n_polyvector.h>
 #include <igl/integrable_polyvector_fields.h>
 #include <igl/integrable_polyvector_fields.h>
-#include <igl/viewer/Viewer.h>
+#include <igl/opengl/glfw/Viewer.h>
 #include <igl/local_basis.h>
 #include <igl/local_basis.h>
 #include <igl/avg_edge_length.h>
 #include <igl/avg_edge_length.h>
 #include <igl/is_border_vertex.h>
 #include <igl/is_border_vertex.h>
@@ -222,7 +222,7 @@ bc<<
 
 
 }
 }
 
 
-void drawCuts(igl::viewer::Viewer& viewer,
+void drawCuts(igl::opengl::glfw::Viewer& viewer,
               const Eigen::MatrixXi &cuts)
               const Eigen::MatrixXi &cuts)
 {
 {
   int maxCutNum = cuts.sum();
   int maxCutNum = cuts.sum();
@@ -240,7 +240,7 @@ void drawCuts(igl::viewer::Viewer& viewer,
   viewer.data.add_edges(start, end , Eigen::RowVector3d(1.,0,1.));
   viewer.data.add_edges(start, end , Eigen::RowVector3d(1.,0,1.));
 }
 }
 
 
-void drawField(igl::viewer::Viewer &viewer,
+void drawField(igl::opengl::glfw::Viewer &viewer,
                const Eigen::MatrixXd &field,
                const Eigen::MatrixXd &field,
                const Eigen::RowVector3d &color)
                const Eigen::RowVector3d &color)
 {
 {
@@ -252,7 +252,7 @@ void drawField(igl::viewer::Viewer &viewer,
   }
   }
 }
 }
 
 
-void drawConstraints(igl::viewer::Viewer &viewer)
+void drawConstraints(igl::opengl::glfw::Viewer &viewer)
 {
 {
   for (int n=0; n<2; ++n)
   for (int n=0; n<2; ++n)
   {
   {
@@ -311,7 +311,7 @@ void colorEdgeMeshFaces(const Eigen::VectorXd &values,
 
 
 }
 }
 
 
-void update_display(igl::viewer::Viewer& viewer)
+void update_display(igl::opengl::glfw::Viewer& viewer)
 {
 {
   using namespace std;
   using namespace std;
   using namespace Eigen;
   using namespace Eigen;
@@ -517,7 +517,7 @@ void update_display(igl::viewer::Viewer& viewer)
 
 
 }
 }
 
 
-bool key_down(igl::viewer::Viewer& viewer, unsigned char key, int modifier)
+bool key_down(igl::opengl::glfw::Viewer& viewer, unsigned char key, int modifier)
 {
 {
 
 
   if (key == '1')
   if (key == '1')
@@ -707,7 +707,7 @@ int main(int argc, char *argv[])
 
 
   cerr<<"Done. Press keys 1-0 for various visualizations, 'A' to improve integrability." <<endl;
   cerr<<"Done. Press keys 1-0 for various visualizations, 'A' to improve integrability." <<endl;
 
 
-  igl::viewer::Viewer viewer;
+  igl::opengl::glfw::Viewer viewer;
   viewer.callback_key_down = &key_down;
   viewer.callback_key_down = &key_down;
   viewer.core.show_lines = false;
   viewer.core.show_lines = false;
   key_down(viewer,'2',0);
   key_down(viewer,'2',0);

+ 3 - 3
tutorial/511_PolyVectorFieldGeneral/main.cpp

@@ -1,6 +1,6 @@
 #include <igl/readOBJ.h>
 #include <igl/readOBJ.h>
 #include <igl/readDMAT.h>
 #include <igl/readDMAT.h>
-#include <igl/viewer/Viewer.h>
+#include <igl/opengl/glfw/Viewer.h>
 #include <igl/barycenter.h>
 #include <igl/barycenter.h>
 #include <igl/avg_edge_length.h>
 #include <igl/avg_edge_length.h>
 #include <vector>
 #include <vector>
@@ -71,7 +71,7 @@ Eigen::VectorXd random_constraints(const
   return r;
   return r;
 }
 }
 
 
-bool key_down(igl::viewer::Viewer& viewer, unsigned char key, int modifier)
+bool key_down(igl::opengl::glfw::Viewer& viewer, unsigned char key, int modifier)
 {
 {
   using namespace std;
   using namespace std;
   using namespace Eigen;
   using namespace Eigen;
@@ -172,7 +172,7 @@ int main(int argc, char *argv[])
   // Make the example deterministic
   // Make the example deterministic
   srand(0);
   srand(0);
 
 
-  igl::viewer::Viewer viewer;
+  igl::opengl::glfw::Viewer viewer;
   viewer.data.set_mesh(V, F);
   viewer.data.set_mesh(V, F);
   viewer.callback_key_down = &key_down;
   viewer.callback_key_down = &key_down;
   viewer.core.show_lines = false;
   viewer.core.show_lines = false;

+ 4 - 4
tutorial/602_Matlab/main.cpp

@@ -2,7 +2,7 @@
 #include <igl/readOFF.h>
 #include <igl/readOFF.h>
 #include <igl/cotmatrix.h>
 #include <igl/cotmatrix.h>
 #include <igl/matlab/matlabinterface.h>
 #include <igl/matlab/matlabinterface.h>
-#include <igl/viewer/Viewer.h>
+#include <igl/opengl/glfw/Viewer.h>
 #include <iostream>
 #include <iostream>
 
 
 #include "tutorial_shared_path.h"
 #include "tutorial_shared_path.h"
@@ -17,7 +17,7 @@ Engine* engine;
 // Eigenvectors of the laplacian
 // Eigenvectors of the laplacian
 Eigen::MatrixXd EV;
 Eigen::MatrixXd EV;
 
 
-void plotEV(igl::viewer::Viewer& viewer, int id)
+void plotEV(igl::opengl::glfw::Viewer& viewer, int id)
 {
 {
   Eigen::VectorXd v = EV.col(id);
   Eigen::VectorXd v = EV.col(id);
   v = v.array() - v.minCoeff();
   v = v.array() - v.minCoeff();
@@ -36,7 +36,7 @@ void plotEV(igl::viewer::Viewer& viewer, int id)
 }
 }
 
 
 // This function is called every time a keyboard button is pressed
 // This function is called every time a keyboard button is pressed
-bool key_down(igl::viewer::Viewer& viewer, unsigned char key, int modifier)
+bool key_down(igl::opengl::glfw::Viewer& viewer, unsigned char key, int modifier)
 {
 {
   if (key >= '1' && key <= '9')
   if (key >= '1' && key <= '9')
     plotEV(viewer,(key - '1') + 1);
     plotEV(viewer,(key - '1') + 1);
@@ -72,7 +72,7 @@ int main(int argc, char *argv[])
   igl::matlab::mlgetmatrix(&engine,"EV",EV);
   igl::matlab::mlgetmatrix(&engine,"EV",EV);
 
 
   // Plot the mesh
   // Plot the mesh
-  igl::viewer::Viewer viewer;
+  igl::opengl::glfw::Viewer viewer;
   viewer.callback_key_down = &key_down;
   viewer.callback_key_down = &key_down;
   viewer.data.set_mesh(V, F);
   viewer.data.set_mesh(V, F);
 
 

+ 2 - 2
tutorial/604_Triangle/main.cpp

@@ -1,4 +1,4 @@
-#include <igl/viewer/Viewer.h>
+#include <igl/opengl/glfw/Viewer.h>
 #include <igl/triangle/triangulate.h>
 #include <igl/triangle/triangulate.h>
 // Input polygon
 // Input polygon
 Eigen::MatrixXd V;
 Eigen::MatrixXd V;
@@ -31,7 +31,7 @@ int main(int argc, char *argv[])
   igl::triangle::triangulate(V,E,H,"a0.005q",V2,F2);
   igl::triangle::triangulate(V,E,H,"a0.005q",V2,F2);
 
 
   // Plot the generated mesh
   // Plot the generated mesh
-  igl::viewer::Viewer viewer;
+  igl::opengl::glfw::Viewer viewer;
   viewer.data.set_mesh(V2,F2);
   viewer.data.set_mesh(V2,F2);
   viewer.launch();
   viewer.launch();
 }
 }

+ 3 - 3
tutorial/605_Tetgen/main.cpp

@@ -1,4 +1,4 @@
-#include <igl/viewer/Viewer.h>
+#include <igl/opengl/glfw/Viewer.h>
 #include <igl/copyleft/tetgen/tetrahedralize.h>
 #include <igl/copyleft/tetgen/tetrahedralize.h>
 #include <igl/readOFF.h>
 #include <igl/readOFF.h>
 #include <igl/barycenter.h>
 #include <igl/barycenter.h>
@@ -16,7 +16,7 @@ Eigen::MatrixXi TT;
 Eigen::MatrixXi TF;
 Eigen::MatrixXi TF;
 
 
 // This function is called every time a keyboard button is pressed
 // This function is called every time a keyboard button is pressed
-bool key_down(igl::viewer::Viewer& viewer, unsigned char key, int modifier)
+bool key_down(igl::opengl::glfw::Viewer& viewer, unsigned char key, int modifier)
 {
 {
   using namespace std;
   using namespace std;
   using namespace Eigen;
   using namespace Eigen;
@@ -73,7 +73,7 @@ int main(int argc, char *argv[])
   igl::barycenter(TV,TT,B);
   igl::barycenter(TV,TT,B);
 
 
   // Plot the generated mesh
   // Plot the generated mesh
-  igl::viewer::Viewer viewer;
+  igl::opengl::glfw::Viewer viewer;
   viewer.callback_key_down = &key_down;
   viewer.callback_key_down = &key_down;
   key_down(viewer,'5',0);
   key_down(viewer,'5',0);
   viewer.launch();
   viewer.launch();

+ 3 - 3
tutorial/606_AmbientOcclusion/main.cpp

@@ -2,7 +2,7 @@
 #include <igl/per_vertex_normals.h>
 #include <igl/per_vertex_normals.h>
 #include <igl/readOFF.h>
 #include <igl/readOFF.h>
 #include <igl/embree/ambient_occlusion.h>
 #include <igl/embree/ambient_occlusion.h>
-#include <igl/viewer/Viewer.h>
+#include <igl/opengl/glfw/Viewer.h>
 #include <iostream>
 #include <iostream>
 
 
 #include "tutorial_shared_path.h"
 #include "tutorial_shared_path.h"
@@ -14,7 +14,7 @@ Eigen::MatrixXi F;
 Eigen::VectorXd AO;
 Eigen::VectorXd AO;
 
 
 // It allows to change the degree of the field when a number is pressed
 // It allows to change the degree of the field when a number is pressed
-bool key_down(igl::viewer::Viewer& viewer, unsigned char key, int modifier)
+bool key_down(igl::opengl::glfw::Viewer& viewer, unsigned char key, int modifier)
 {
 {
   using namespace Eigen;
   using namespace Eigen;
   using namespace std;
   using namespace std;
@@ -69,7 +69,7 @@ int main(int argc, char *argv[])
   AO = 1.0 - AO.array();
   AO = 1.0 - AO.array();
 
 
   // Show mesh
   // Show mesh
-  igl::viewer::Viewer viewer;
+  igl::opengl::glfw::Viewer viewer;
   viewer.data.set_mesh(V, F);
   viewer.data.set_mesh(V, F);
   viewer.callback_key_down = &key_down;
   viewer.callback_key_down = &key_down;
   key_down(viewer,'2',0);
   key_down(viewer,'2',0);

+ 3 - 3
tutorial/607_ScreenCapture/main.cpp

@@ -1,12 +1,12 @@
 #include <igl/readOFF.h>
 #include <igl/readOFF.h>
-#include <igl/viewer/Viewer.h>
+#include <igl/opengl/glfw/Viewer.h>
 #include <iostream>
 #include <iostream>
 #include "tutorial_shared_path.h"
 #include "tutorial_shared_path.h"
 #include <igl/png/writePNG.h>
 #include <igl/png/writePNG.h>
 #include <igl/png/readPNG.h>
 #include <igl/png/readPNG.h>
 
 
 // This function is called every time a keyboard button is pressed
 // This function is called every time a keyboard button is pressed
-bool key_down(igl::viewer::Viewer& viewer, unsigned char key, int modifier)
+bool key_down(igl::opengl::glfw::Viewer& viewer, unsigned char key, int modifier)
 {
 {
   if (key == '1')
   if (key == '1')
   {
   {
@@ -75,7 +75,7 @@ int main(int argc, char *argv[])
   std::cerr << "Press 2 to load the saved png and use it as a texture." << std::endl;
   std::cerr << "Press 2 to load the saved png and use it as a texture." << std::endl;
 
 
   // Plot the mesh and register the callback
   // Plot the mesh and register the callback
-  igl::viewer::Viewer viewer;
+  igl::opengl::glfw::Viewer viewer;
   viewer.callback_key_down = &key_down;
   viewer.callback_key_down = &key_down;
   viewer.data.set_mesh(V, F);
   viewer.data.set_mesh(V, F);
   viewer.launch();
   viewer.launch();

+ 3 - 3
tutorial/608_LIM/main.cpp

@@ -2,7 +2,7 @@
 #include <igl/per_vertex_normals.h>
 #include <igl/per_vertex_normals.h>
 #include <igl/readOFF.h>
 #include <igl/readOFF.h>
 #include <igl/lim/lim.h>
 #include <igl/lim/lim.h>
-#include <igl/viewer/Viewer.h>
+#include <igl/opengl/glfw/Viewer.h>
 #include <iostream>
 #include <iostream>
 
 
 #include "tutorial_shared_path.h"
 #include "tutorial_shared_path.h"
@@ -22,7 +22,7 @@ bool barriersEnabled;
 
 
 // This function is called every time a keyboard button is pressed
 // This function is called every time a keyboard button is pressed
 // keys: 0:Original Mesh / 1:Harmonic / 2:Biharmonic / 3:Green / 4:ARAP
 // keys: 0:Original Mesh / 1:Harmonic / 2:Biharmonic / 3:Green / 4:ARAP
-bool key_down(igl::viewer::Viewer& viewer,unsigned char key,int modifier)
+bool key_down(igl::opengl::glfw::Viewer& viewer,unsigned char key,int modifier)
 {
 {
   using namespace std;
   using namespace std;
   using namespace Eigen;
   using namespace Eigen;
@@ -106,7 +106,7 @@ int main(int argc, char *argv[])
   lim(V1,V0,F,C,b,energyType,1e-8,100,true,true,barriersEnabled,true,-1,-1);
   lim(V1,V0,F,C,b,energyType,1e-8,100,true,true,barriersEnabled,true,-1,-1);
 
 
   // Show mesh
   // Show mesh
-  igl::viewer::Viewer viewer;
+  igl::opengl::glfw::Viewer viewer;
   viewer.callback_key_down = &key_down;
   viewer.callback_key_down = &key_down;
   viewer.data.set_mesh(V1, F);
   viewer.data.set_mesh(V1, F);
   viewer.core.show_lines = true;
   viewer.core.show_lines = true;

+ 4 - 4
tutorial/609_Boolean/main.cpp

@@ -2,7 +2,7 @@
 //#define IGL_NO_CORK
 //#define IGL_NO_CORK
 //#undef IGL_STATIC_LIBRARY
 //#undef IGL_STATIC_LIBRARY
 #include <igl/copyleft/cgal/mesh_boolean.h>
 #include <igl/copyleft/cgal/mesh_boolean.h>
-#include <igl/viewer/Viewer.h>
+#include <igl/opengl/glfw/Viewer.h>
 
 
 #include <Eigen/Core>
 #include <Eigen/Core>
 #include <iostream>
 #include <iostream>
@@ -24,7 +24,7 @@ const char * MESH_BOOLEAN_TYPE_NAMES[] =
   "Resolve",
   "Resolve",
 };
 };
 
 
-void update(igl::viewer::Viewer &viewer)
+void update(igl::opengl::glfw::Viewer &viewer)
 {
 {
   igl::copyleft::cgal::mesh_boolean(VA,FA,VB,FB,boolean_type,VC,FC,J);
   igl::copyleft::cgal::mesh_boolean(VA,FA,VB,FB,boolean_type,VC,FC,J);
   Eigen::MatrixXd C(FC.rows(),3);
   Eigen::MatrixXd C(FC.rows(),3);
@@ -44,7 +44,7 @@ void update(igl::viewer::Viewer &viewer)
   std::cout<<"A "<<MESH_BOOLEAN_TYPE_NAMES[boolean_type]<<" B."<<std::endl;
   std::cout<<"A "<<MESH_BOOLEAN_TYPE_NAMES[boolean_type]<<" B."<<std::endl;
 }
 }
 
 
-bool key_down(igl::viewer::Viewer &viewer, unsigned char key, int mods)
+bool key_down(igl::opengl::glfw::Viewer &viewer, unsigned char key, int mods)
 {
 {
   switch(key)
   switch(key)
   {
   {
@@ -79,7 +79,7 @@ int main(int argc, char *argv[])
   igl::readOFF(TUTORIAL_SHARED_PATH "/cheburashka.off",VA,FA);
   igl::readOFF(TUTORIAL_SHARED_PATH "/cheburashka.off",VA,FA);
   igl::readOFF(TUTORIAL_SHARED_PATH "/decimated-knight.off",VB,FB);
   igl::readOFF(TUTORIAL_SHARED_PATH "/decimated-knight.off",VB,FB);
   // Plot the mesh with pseudocolors
   // Plot the mesh with pseudocolors
-  igl::viewer::Viewer viewer;
+  igl::opengl::glfw::Viewer viewer;
 
 
   // Initialize
   // Initialize
   update(viewer);
   update(viewer);

+ 3 - 3
tutorial/610_CSGTree/main.cpp

@@ -1,6 +1,6 @@
 #include <igl/read_triangle_mesh.h>
 #include <igl/read_triangle_mesh.h>
 #include <igl/copyleft/cgal/CSGTree.h>
 #include <igl/copyleft/cgal/CSGTree.h>
-#include <igl/viewer/Viewer.h>
+#include <igl/opengl/glfw/Viewer.h>
 #include <igl/jet.h>
 #include <igl/jet.h>
 #include <Eigen/Core>
 #include <Eigen/Core>
 
 
@@ -24,7 +24,7 @@ int main(int argc, char * argv[])
   read_triangle_mesh(TUTORIAL_SHARED_PATH "/xcylinder.obj",VC,FC);
   read_triangle_mesh(TUTORIAL_SHARED_PATH "/xcylinder.obj",VC,FC);
   read_triangle_mesh(TUTORIAL_SHARED_PATH "/ycylinder.obj",VD,FD);
   read_triangle_mesh(TUTORIAL_SHARED_PATH "/ycylinder.obj",VD,FD);
   read_triangle_mesh(TUTORIAL_SHARED_PATH "/zcylinder.obj",VE,FE);
   read_triangle_mesh(TUTORIAL_SHARED_PATH "/zcylinder.obj",VE,FE);
-  igl::viewer::Viewer viewer;
+  igl::opengl::glfw::Viewer viewer;
 
 
   int num_views = 5+4;
   int num_views = 5+4;
   int view_id = num_views-1;
   int view_id = num_views-1;
@@ -108,7 +108,7 @@ int main(int argc, char * argv[])
   update();
   update();
 
 
   viewer.callback_key_down = 
   viewer.callback_key_down = 
-    [&](igl::viewer::Viewer &viewer, unsigned char key, int mods)->bool
+    [&](igl::opengl::glfw::Viewer &viewer, unsigned char key, int mods)->bool
     {
     {
       switch(key)
       switch(key)
       {
       {

+ 4 - 4
tutorial/702_WindingNumber/main.cpp

@@ -5,7 +5,7 @@
 #include <igl/slice.h>
 #include <igl/slice.h>
 #include <igl/slice_tets.h>
 #include <igl/slice_tets.h>
 #include <igl/winding_number.h>
 #include <igl/winding_number.h>
-#include <igl/viewer/Viewer.h>
+#include <igl/opengl/glfw/Viewer.h>
 #include <Eigen/Sparse>
 #include <Eigen/Sparse>
 #include <iostream>
 #include <iostream>
 
 
@@ -23,7 +23,7 @@ enum OverLayType
   NUM_OVERLAY = 3,
   NUM_OVERLAY = 3,
 } overlay = OVERLAY_NONE;
 } overlay = OVERLAY_NONE;
 
 
-void update_visualization(igl::viewer::Viewer & viewer)
+void update_visualization(igl::opengl::glfw::Viewer & viewer)
 {
 {
   using namespace Eigen;
   using namespace Eigen;
   using namespace std;
   using namespace std;
@@ -70,7 +70,7 @@ void update_visualization(igl::viewer::Viewer & viewer)
   viewer.data.set_face_based(true);
   viewer.data.set_face_based(true);
 }
 }
 
 
-bool key_down(igl::viewer::Viewer& viewer, unsigned char key, int mod)
+bool key_down(igl::opengl::glfw::Viewer& viewer, unsigned char key, int mod)
 {
 {
   switch(key)
   switch(key)
   {
   {
@@ -134,7 +134,7 @@ int main(int argc, char *argv[])
   W = (W.array() - W.minCoeff())/(W.maxCoeff()-W.minCoeff());
   W = (W.array() - W.minCoeff())/(W.maxCoeff()-W.minCoeff());
 
 
   // Plot the generated mesh
   // Plot the generated mesh
-  igl::viewer::Viewer viewer;
+  igl::opengl::glfw::Viewer viewer;
   update_visualization(viewer);
   update_visualization(viewer);
   viewer.callback_key_down = &key_down;
   viewer.callback_key_down = &key_down;
   viewer.launch();
   viewer.launch();

+ 4 - 4
tutorial/703_Decimation/main.cpp

@@ -3,7 +3,7 @@
 #include <igl/edge_flaps.h>
 #include <igl/edge_flaps.h>
 #include <igl/shortest_edge_and_midpoint.h>
 #include <igl/shortest_edge_and_midpoint.h>
 #include <igl/read_triangle_mesh.h>
 #include <igl/read_triangle_mesh.h>
-#include <igl/viewer/Viewer.h>
+#include <igl/opengl/glfw/Viewer.h>
 #include <Eigen/Core>
 #include <Eigen/Core>
 #include <iostream>
 #include <iostream>
 #include <set>
 #include <set>
@@ -28,7 +28,7 @@ int main(int argc, char * argv[])
   MatrixXi F,OF;
   MatrixXi F,OF;
   read_triangle_mesh(filename,OV,OF);
   read_triangle_mesh(filename,OV,OF);
 
 
-  igl::viewer::Viewer viewer;
+  igl::opengl::glfw::Viewer viewer;
 
 
   // Prepare array-based edge data structures and priority queue
   // Prepare array-based edge data structures and priority queue
   VectorXi EMAP;
   VectorXi EMAP;
@@ -65,7 +65,7 @@ int main(int argc, char * argv[])
     viewer.data.set_face_based(true);
     viewer.data.set_face_based(true);
   };
   };
 
 
-  const auto &pre_draw = [&](igl::viewer::Viewer & viewer)->bool
+  const auto &pre_draw = [&](igl::opengl::glfw::Viewer & viewer)->bool
   {
   {
     // If animating then collapse 10% of edges
     // If animating then collapse 10% of edges
     if(viewer.core.is_animating && !Q.empty())
     if(viewer.core.is_animating && !Q.empty())
@@ -95,7 +95,7 @@ int main(int argc, char * argv[])
   };
   };
 
 
   const auto &key_down =
   const auto &key_down =
-    [&](igl::viewer::Viewer &viewer,unsigned char key,int mod)->bool
+    [&](igl::opengl::glfw::Viewer &viewer,unsigned char key,int mod)->bool
   {
   {
     switch(key)
     switch(key)
     {
     {

+ 4 - 4
tutorial/704_SignedDistance/main.cpp

@@ -10,7 +10,7 @@
 #include <igl/slice_mask.h>
 #include <igl/slice_mask.h>
 #include <igl/slice_tets.h>
 #include <igl/slice_tets.h>
 #include <igl/upsample.h>
 #include <igl/upsample.h>
-#include <igl/viewer/Viewer.h>
+#include <igl/opengl/glfw/Viewer.h>
 #include <Eigen/Sparse>
 #include <Eigen/Sparse>
 #include <iostream>
 #include <iostream>
 
 
@@ -27,7 +27,7 @@ double max_distance = 1;
 double slice_z = 0.5;
 double slice_z = 0.5;
 bool overlay = false;
 bool overlay = false;
 
 
-void update_visualization(igl::viewer::Viewer & viewer)
+void update_visualization(igl::opengl::glfw::Viewer & viewer)
 {
 {
   using namespace Eigen;
   using namespace Eigen;
   using namespace std;
   using namespace std;
@@ -97,7 +97,7 @@ void update_visualization(igl::viewer::Viewer & viewer)
   viewer.core.lighting_factor = overlay;
   viewer.core.lighting_factor = overlay;
 }
 }
 
 
-bool key_down(igl::viewer::Viewer& viewer, unsigned char key, int mod)
+bool key_down(igl::opengl::glfw::Viewer& viewer, unsigned char key, int mod)
 {
 {
   switch(key)
   switch(key)
   {
   {
@@ -151,7 +151,7 @@ int main(int argc, char *argv[])
     V,F,igl::PER_EDGE_NORMALS_WEIGHTING_TYPE_UNIFORM,FN,EN,E,EMAP);
     V,F,igl::PER_EDGE_NORMALS_WEIGHTING_TYPE_UNIFORM,FN,EN,E,EMAP);
 
 
   // Plot the generated mesh
   // Plot the generated mesh
-  igl::viewer::Viewer viewer;
+  igl::opengl::glfw::Viewer viewer;
   update_visualization(viewer);
   update_visualization(viewer);
   viewer.callback_key_down = &key_down;
   viewer.callback_key_down = &key_down;
   viewer.core.show_lines = false;
   viewer.core.show_lines = false;

+ 3 - 3
tutorial/705_MarchingCubes/main.cpp

@@ -1,7 +1,7 @@
 #include <igl/copyleft/marching_cubes.h>
 #include <igl/copyleft/marching_cubes.h>
 #include <igl/signed_distance.h>
 #include <igl/signed_distance.h>
 #include <igl/read_triangle_mesh.h>
 #include <igl/read_triangle_mesh.h>
-#include <igl/viewer/Viewer.h>
+#include <igl/opengl/glfw/Viewer.h>
 #include <Eigen/Core>
 #include <Eigen/Core>
 #include <iostream>
 #include <iostream>
 
 
@@ -63,10 +63,10 @@ int main(int argc, char * argv[])
 '2'  Show marching cubes contour of signed distance.
 '2'  Show marching cubes contour of signed distance.
 '3'  Show marching cubes contour of indicator function.
 '3'  Show marching cubes contour of indicator function.
 )";
 )";
-  igl::viewer::Viewer viewer;
+  igl::opengl::glfw::Viewer viewer;
   viewer.data.set_mesh(SV,SF);
   viewer.data.set_mesh(SV,SF);
   viewer.callback_key_down =
   viewer.callback_key_down =
-    [&](igl::viewer::Viewer & viewer, unsigned char key, int mod)->bool
+    [&](igl::opengl::glfw::Viewer & viewer, unsigned char key, int mod)->bool
     {
     {
       switch(key)
       switch(key)
       {
       {

+ 3 - 3
tutorial/706_FacetOrientation/main.cpp

@@ -4,13 +4,13 @@
 #include <igl/slice.h>
 #include <igl/slice.h>
 #include <igl/hsv_to_rgb.h>
 #include <igl/hsv_to_rgb.h>
 #include <igl/embree/reorient_facets_raycast.h>
 #include <igl/embree/reorient_facets_raycast.h>
-#include <igl/viewer/Viewer.h>
+#include <igl/opengl/glfw/Viewer.h>
 #include <fstream>
 #include <fstream>
 #include <iostream>
 #include <iostream>
 #include <string>
 #include <string>
 #include <vector>
 #include <vector>
 
 
-igl::viewer::Viewer viewer;
+igl::opengl::glfw::Viewer viewer;
 Eigen::MatrixXd V;
 Eigen::MatrixXd V;
 std::vector<Eigen::VectorXi> C(2);
 std::vector<Eigen::VectorXi> C(2);
 std::vector<Eigen::MatrixXd> RGBcolors(2);
 std::vector<Eigen::MatrixXd> RGBcolors(2);
@@ -49,7 +49,7 @@ S,s      Scramble colors
 
 
   viewer.callback_key_pressed = 
   viewer.callback_key_pressed = 
     [&scramble_colors]
     [&scramble_colors]
-    (igl::viewer::Viewer& /*viewer*/, unsigned int key, int mod)->bool
+    (igl::opengl::glfw::Viewer& /*viewer*/, unsigned int key, int mod)->bool
   {
   {
     switch(key)
     switch(key)
     {
     {

+ 4 - 4
tutorial/707_SweptVolume/main.cpp

@@ -3,7 +3,7 @@
 #include <igl/material_colors.h>
 #include <igl/material_colors.h>
 #include <igl/copyleft/marching_cubes.h>
 #include <igl/copyleft/marching_cubes.h>
 #include <igl/copyleft/swept_volume.h>
 #include <igl/copyleft/swept_volume.h>
-#include <igl/viewer/Viewer.h>
+#include <igl/opengl/glfw/Viewer.h>
 #include <Eigen/Core>
 #include <Eigen/Core>
 #include <iostream>
 #include <iostream>
 
 
@@ -30,7 +30,7 @@ int main(int argc, char * argv[])
   cout<<R"(Usage:
   cout<<R"(Usage:
 [space]  Toggle between transforming original mesh and swept volume
 [space]  Toggle between transforming original mesh and swept volume
 )";
 )";
-  igl::viewer::Viewer viewer;
+  igl::opengl::glfw::Viewer viewer;
   viewer.data.set_mesh(V,F);
   viewer.data.set_mesh(V,F);
   viewer.data.set_face_based(true);
   viewer.data.set_face_based(true);
   viewer.core.is_animating = !show_swept_volume;
   viewer.core.is_animating = !show_swept_volume;
@@ -43,7 +43,7 @@ int main(int argc, char * argv[])
   std::cerr<<" finished."<<std::endl;
   std::cerr<<" finished."<<std::endl;
 
 
   viewer.callback_pre_draw =
   viewer.callback_pre_draw =
-    [&](igl::viewer::Viewer & viewer)->bool
+    [&](igl::opengl::glfw::Viewer & viewer)->bool
     {
     {
       if(!show_swept_volume)
       if(!show_swept_volume)
       {
       {
@@ -57,7 +57,7 @@ int main(int argc, char * argv[])
       return false;
       return false;
     };
     };
   viewer.callback_key_down =
   viewer.callback_key_down =
-    [&](igl::viewer::Viewer & viewer, unsigned char key, int mod)->bool
+    [&](igl::opengl::glfw::Viewer & viewer, unsigned char key, int mod)->bool
     {
     {
       switch(key)
       switch(key)
       {
       {

+ 3 - 3
tutorial/708_Picking/main.cpp

@@ -1,7 +1,7 @@
 #include "tutorial_shared_path.h"
 #include "tutorial_shared_path.h"
 #include <igl/readOFF.h>
 #include <igl/readOFF.h>
 #include <igl/unproject_onto_mesh.h>
 #include <igl/unproject_onto_mesh.h>
-#include <igl/viewer/Viewer.h>
+#include <igl/opengl/glfw/Viewer.h>
 #include <iostream>
 #include <iostream>
 
 
 int main(int argc, char *argv[])
 int main(int argc, char *argv[])
@@ -15,9 +15,9 @@ int main(int argc, char *argv[])
 
 
   // Initialize white
   // Initialize white
   C = Eigen::MatrixXd::Constant(F.rows(),3,1);
   C = Eigen::MatrixXd::Constant(F.rows(),3,1);
-  igl::viewer::Viewer viewer;
+  igl::opengl::glfw::Viewer viewer;
   viewer.callback_mouse_down = 
   viewer.callback_mouse_down = 
-    [&V,&F,&C](igl::viewer::Viewer& viewer, int, int)->bool
+    [&V,&F,&C](igl::opengl::glfw::Viewer& viewer, int, int)->bool
   {
   {
     int fid;
     int fid;
     Eigen::Vector3f bc;
     Eigen::Vector3f bc;

+ 4 - 4
tutorial/709_VectorFieldVisualizer/main.cpp

@@ -11,7 +11,7 @@
 #include <igl/sort_vectors_ccw.h>
 #include <igl/sort_vectors_ccw.h>
 #include <igl/streamlines.h>
 #include <igl/streamlines.h>
 #include <igl/copyleft/comiso/nrosy.h>
 #include <igl/copyleft/comiso/nrosy.h>
-#include <igl/viewer/Viewer.h>
+#include <igl/opengl/glfw/Viewer.h>
 
 
 #include <cstdlib>
 #include <cstdlib>
 #include <iostream>
 #include <iostream>
@@ -64,7 +64,7 @@ void representative_to_nrosy(
     }
     }
 }
 }
 
 
-bool pre_draw(igl::viewer::Viewer &viewer)
+bool pre_draw(igl::opengl::glfw::Viewer &viewer)
 {
 {
     using namespace Eigen;
     using namespace Eigen;
     using namespace std;
     using namespace std;
@@ -88,7 +88,7 @@ bool pre_draw(igl::viewer::Viewer &viewer)
     return false;
     return false;
 }
 }
 
 
-bool key_down(igl::viewer::Viewer &viewer, unsigned char key, int modifier)
+bool key_down(igl::opengl::glfw::Viewer &viewer, unsigned char key, int modifier)
 {
 {
     if (key == ' ')
     if (key == ' ')
     {
     {
@@ -128,7 +128,7 @@ int main(int argc, char *argv[])
 
 
 
 
     // Viewer Settings
     // Viewer Settings
-    igl::viewer::Viewer viewer;
+    igl::opengl::glfw::Viewer viewer;
     viewer.data.set_mesh(V, F);
     viewer.data.set_mesh(V, F);
     viewer.callback_pre_draw = &pre_draw;
     viewer.callback_pre_draw = &pre_draw;
     viewer.callback_key_down = &key_down;
     viewer.callback_key_down = &key_down;

+ 11 - 11
tutorial/710_SLIM/main.cpp

@@ -12,7 +12,7 @@
 #include "igl/harmonic.h"
 #include "igl/harmonic.h"
 #include <igl/serialize.h>
 #include <igl/serialize.h>
 #include <igl/read_triangle_mesh.h>
 #include <igl/read_triangle_mesh.h>
-#include <igl/viewer/Viewer.h>
+#include <igl/opengl/glfw/Viewer.h>
 #include <igl/flipped_triangles.h>
 #include <igl/flipped_triangles.h>
 #include <igl/euler_characteristic.h>
 #include <igl/euler_characteristic.h>
 #include <igl/barycenter.h>
 #include <igl/barycenter.h>
@@ -30,12 +30,12 @@ using namespace std;
 using namespace Eigen;
 using namespace Eigen;
 
 
 void check_mesh_for_issues(Eigen::MatrixXd& V, Eigen::MatrixXi& F);
 void check_mesh_for_issues(Eigen::MatrixXd& V, Eigen::MatrixXi& F);
-void param_2d_demo_iter(igl::viewer::Viewer& viewer);
+void param_2d_demo_iter(igl::opengl::glfw::Viewer& viewer);
 void get_soft_constraint_for_circle(Eigen::MatrixXd& V_o, Eigen::MatrixXi& F, Eigen::VectorXi& b, Eigen::MatrixXd& bc);
 void get_soft_constraint_for_circle(Eigen::MatrixXd& V_o, Eigen::MatrixXi& F, Eigen::VectorXi& b, Eigen::MatrixXd& bc);
-void soft_const_demo_iter(igl::viewer::Viewer& viewer);
-void deform_3d_demo_iter(igl::viewer::Viewer& viewer);
+void soft_const_demo_iter(igl::opengl::glfw::Viewer& viewer);
+void deform_3d_demo_iter(igl::opengl::glfw::Viewer& viewer);
 void get_cube_corner_constraints(Eigen::MatrixXd& V_o, Eigen::MatrixXi& F, Eigen::VectorXi& b, Eigen::MatrixXd& bc);
 void get_cube_corner_constraints(Eigen::MatrixXd& V_o, Eigen::MatrixXi& F, Eigen::VectorXi& b, Eigen::MatrixXd& bc);
-void display_3d_mesh(igl::viewer::Viewer& viewer);
+void display_3d_mesh(igl::opengl::glfw::Viewer& viewer);
 void int_set_to_eigen_vector(const std::set<int>& int_set, Eigen::VectorXi& vec);
 void int_set_to_eigen_vector(const std::set<int>& int_set, Eigen::VectorXi& vec);
 
 
 Eigen::MatrixXd V;
 Eigen::MatrixXd V;
@@ -53,7 +53,7 @@ enum DEMO_TYPE {
 };
 };
 DEMO_TYPE demo_type;
 DEMO_TYPE demo_type;
 
 
-bool key_down(igl::viewer::Viewer& viewer, unsigned char key, int modifier){
+bool key_down(igl::opengl::glfw::Viewer& viewer, unsigned char key, int modifier){
   if (key == ' ') {
   if (key == ' ') {
     switch (demo_type) {
     switch (demo_type) {
       case PARAM_2D: {
       case PARAM_2D: {
@@ -76,7 +76,7 @@ bool key_down(igl::viewer::Viewer& viewer, unsigned char key, int modifier){
   return false;
   return false;
 }
 }
 
 
-void param_2d_demo_iter(igl::viewer::Viewer& viewer) {
+void param_2d_demo_iter(igl::opengl::glfw::Viewer& viewer) {
   if (first_iter) {
   if (first_iter) {
     timer.start();
     timer.start();
     igl::read_triangle_mesh(TUTORIAL_SHARED_PATH "/face.obj", V, F);
     igl::read_triangle_mesh(TUTORIAL_SHARED_PATH "/face.obj", V, F);
@@ -114,7 +114,7 @@ void param_2d_demo_iter(igl::viewer::Viewer& viewer) {
   }
   }
 }
 }
 
 
-void soft_const_demo_iter(igl::viewer::Viewer& viewer) {
+void soft_const_demo_iter(igl::opengl::glfw::Viewer& viewer) {
   if (first_iter) {
   if (first_iter) {
 
 
     igl::read_triangle_mesh(TUTORIAL_SHARED_PATH "/circle.obj", V, F);
     igl::read_triangle_mesh(TUTORIAL_SHARED_PATH "/circle.obj", V, F);
@@ -141,7 +141,7 @@ void soft_const_demo_iter(igl::viewer::Viewer& viewer) {
   }
   }
 }
 }
 
 
-void deform_3d_demo_iter(igl::viewer::Viewer& viewer) {
+void deform_3d_demo_iter(igl::opengl::glfw::Viewer& viewer) {
   if (first_iter) {
   if (first_iter) {
     igl::readOBJ(TUTORIAL_SHARED_PATH "/cube_40k.obj", V, F);
     igl::readOBJ(TUTORIAL_SHARED_PATH "/cube_40k.obj", V, F);
 
 
@@ -163,7 +163,7 @@ void deform_3d_demo_iter(igl::viewer::Viewer& viewer) {
   }
   }
 }
 }
 
 
-void display_3d_mesh(igl::viewer::Viewer& viewer) {
+void display_3d_mesh(igl::opengl::glfw::Viewer& viewer) {
   MatrixXd V_temp; MatrixXi F_temp;
   MatrixXd V_temp; MatrixXi F_temp;
   Eigen::MatrixXd Barycenters;
   Eigen::MatrixXd Barycenters;
 
 
@@ -232,7 +232,7 @@ int main(int argc, char *argv[]) {
 
 
 
 
   // Launch the viewer
   // Launch the viewer
-  igl::viewer::Viewer viewer;
+  igl::opengl::glfw::Viewer viewer;
   viewer.callback_key_down = &key_down;
   viewer.callback_key_down = &key_down;
 
 
   // Disable wireframe
   // Disable wireframe

+ 3 - 3
tutorial/711_Subdivision/main.cpp

@@ -2,7 +2,7 @@
 #include <igl/loop.h>
 #include <igl/loop.h>
 #include <igl/upsample.h>
 #include <igl/upsample.h>
 #include <igl/false_barycentric_subdivision.h>
 #include <igl/false_barycentric_subdivision.h>
-#include <igl/viewer/Viewer.h>
+#include <igl/opengl/glfw/Viewer.h>
 #include <Eigen/Core>
 #include <Eigen/Core>
 #include <iostream>
 #include <iostream>
 
 
@@ -25,12 +25,12 @@ int main(int argc, char * argv[])
 3  Apply Loop subdivided mesh
 3  Apply Loop subdivided mesh
 4  Apply False barycentric subdivision
 4  Apply False barycentric subdivision
 )";
 )";
-  igl::viewer::Viewer viewer;
+  igl::opengl::glfw::Viewer viewer;
   viewer.data.set_mesh(V,F);
   viewer.data.set_mesh(V,F);
   viewer.data.set_face_based(true);
   viewer.data.set_face_based(true);
 
 
   viewer.callback_key_down =
   viewer.callback_key_down =
-    [&](igl::viewer::Viewer & viewer, unsigned char key, int mod)->bool
+    [&](igl::opengl::glfw::Viewer & viewer, unsigned char key, int mod)->bool
     {
     {
       switch(key)
       switch(key)
       {
       {