create_mesh_vbo.h 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. # include <GL/gl.h>
  9. #endif
  10. // Create a VBO (Vertex Buffer Object) for a mesh. Actually two VBOs: one
  11. // GL_ARRAY_BUFFER for the vertex positions (V) and one
  12. // GL_ELEMENT_ARRAY_BUFFER for the triangle indices (F)
  13. namespace igl
  14. {
  15. // Inputs:
  16. // V #V by 3 eigen Matrix of mesh vertex 3D positions
  17. // F #F by 3 eigne Matrix of face (triangle) indices
  18. // Outputs:
  19. // V_vbo_id buffer id for vertex positions
  20. // F_vbo_id buffer id for face indices
  21. //
  22. // NOTE: when using glDrawElements VBOs for V and F using MatrixXd and
  23. // MatrixXi will have types GL_DOUBLE and GL_UNSIGNED_INT respectively
  24. //
  25. inline void create_mesh_vbo(
  26. const Eigen::MatrixXd & V,
  27. const Eigen::MatrixXi & F,
  28. GLuint & V_vbo_id,
  29. GLuint & F_vbo_id);
  30. // Inputs:
  31. // V #V by 3 eigen Matrix of mesh vertex 3D positions
  32. // F #F by 3 eigne Matrix of face (triangle) indices
  33. // N #V by 3 eigen Matrix of mesh vertex 3D normals
  34. // Outputs:
  35. // V_vbo_id buffer id for vertex positions
  36. // F_vbo_id buffer id for face indices
  37. // N_vbo_id buffer id for vertex positions
  38. inline void create_mesh_vbo(
  39. const Eigen::MatrixXd & V,
  40. const Eigen::MatrixXi & F,
  41. const Eigen::MatrixXd & N,
  42. GLuint & V_vbo_id,
  43. GLuint & F_vbo_id,
  44. GLuint & N_vbo_id);
  45. }
  46. // Implementation
  47. #include "create_vector_vbo.h"
  48. #include "create_index_vbo.h"
  49. // http://www.songho.ca/opengl/gl_vbo.html#create
  50. inline void igl::create_mesh_vbo(
  51. const Eigen::MatrixXd & V,
  52. const Eigen::MatrixXi & F,
  53. GLuint & V_vbo_id,
  54. GLuint & F_vbo_id)
  55. {
  56. // Create VBO for vertex position vectors
  57. create_vector_vbo(V,V_vbo_id);
  58. // Create VBO for face index lists
  59. create_index_vbo(F,F_vbo_id);
  60. }
  61. // http://www.songho.ca/opengl/gl_vbo.html#create
  62. inline void igl::create_mesh_vbo(
  63. const Eigen::MatrixXd & V,
  64. const Eigen::MatrixXi & F,
  65. const Eigen::MatrixXd & N,
  66. GLuint & V_vbo_id,
  67. GLuint & F_vbo_id,
  68. GLuint & N_vbo_id)
  69. {
  70. // Create VBOs for faces and vertices
  71. create_mesh_vbo(V,F,V_vbo_id,F_vbo_id);
  72. // Create VBO for normal vectors
  73. create_vector_vbo(N,N_vbo_id);
  74. }
  75. #endif