create_mesh_vbo.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. #ifndef IGL_CREATE_MESH_VBO
  2. #define IGL_CREATE_MESH_VBO
  3. // NOTE: It wouldn't be so hard to template this using Eigen's templates
  4. #include <Eigen/Core>
  5. #if __APPLE__
  6. # include <OpenGL/gl.h>
  7. #else
  8. # ifdef _WIN32
  9. # define NOMINMAX
  10. # include <Windows.h>
  11. # undef NOMINMAX
  12. # endif
  13. # include <GL/gl.h>
  14. #endif
  15. // Create a VBO (Vertex Buffer Object) for a mesh. Actually two VBOs: one
  16. // GL_ARRAY_BUFFER for the vertex positions (V) and one
  17. // GL_ELEMENT_ARRAY_BUFFER for the triangle indices (F)
  18. namespace igl
  19. {
  20. // Inputs:
  21. // V #V by 3 eigen Matrix of mesh vertex 3D positions
  22. // F #F by 3 eigne Matrix of face (triangle) indices
  23. // Outputs:
  24. // V_vbo_id buffer id for vertex positions
  25. // F_vbo_id buffer id for face indices
  26. //
  27. // NOTE: when using glDrawElements VBOs for V and F using MatrixXd and
  28. // MatrixXi will have types GL_DOUBLE and GL_UNSIGNED_INT respectively
  29. //
  30. inline void create_mesh_vbo(
  31. const Eigen::MatrixXd & V,
  32. const Eigen::MatrixXi & F,
  33. GLuint & V_vbo_id,
  34. GLuint & F_vbo_id);
  35. // Inputs:
  36. // V #V by 3 eigen Matrix of mesh vertex 3D positions
  37. // F #F by 3 eigne Matrix of face (triangle) indices
  38. // N #V by 3 eigen Matrix of mesh vertex 3D normals
  39. // Outputs:
  40. // V_vbo_id buffer id for vertex positions
  41. // F_vbo_id buffer id for face indices
  42. // N_vbo_id buffer id for vertex positions
  43. inline void create_mesh_vbo(
  44. const Eigen::MatrixXd & V,
  45. const Eigen::MatrixXi & F,
  46. const Eigen::MatrixXd & N,
  47. GLuint & V_vbo_id,
  48. GLuint & F_vbo_id,
  49. GLuint & N_vbo_id);
  50. }
  51. // Implementation
  52. #include "create_vector_vbo.h"
  53. #include "create_index_vbo.h"
  54. // http://www.songho.ca/opengl/gl_vbo.html#create
  55. inline void igl::create_mesh_vbo(
  56. const Eigen::MatrixXd & V,
  57. const Eigen::MatrixXi & F,
  58. GLuint & V_vbo_id,
  59. GLuint & F_vbo_id)
  60. {
  61. // Create VBO for vertex position vectors
  62. create_vector_vbo(V,V_vbo_id);
  63. // Create VBO for face index lists
  64. create_index_vbo(F,F_vbo_id);
  65. }
  66. // http://www.songho.ca/opengl/gl_vbo.html#create
  67. inline void igl::create_mesh_vbo(
  68. const Eigen::MatrixXd & V,
  69. const Eigen::MatrixXi & F,
  70. const Eigen::MatrixXd & N,
  71. GLuint & V_vbo_id,
  72. GLuint & F_vbo_id,
  73. GLuint & N_vbo_id)
  74. {
  75. // Create VBOs for faces and vertices
  76. create_mesh_vbo(V,F,V_vbo_id,F_vbo_id);
  77. // Create VBO for normal vectors
  78. create_vector_vbo(N,N_vbo_id);
  79. }
  80. #endif