create_mesh_vbo.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #ifndef IGL_CREATE_MESH_VBO_H
  2. #define IGL_CREATE_MESH_VBO_H
  3. #include "igl_inline.h"
  4. // NOTE: It wouldn't be so hard to template this using Eigen's templates
  5. #include <Eigen/Core>
  6. #ifdef __APPLE__
  7. # include <OpenGL/gl.h>
  8. #elif defined(_WIN32)
  9. # define NOMINMAX
  10. # include <Windows.h>
  11. # undef NOMINMAX
  12. # include <GL/glew.h>
  13. # include <GL/gl.h>
  14. #else
  15. # define GL_GLEXT_PROTOTYPES
  16. # include <GL/gl.h>
  17. # include <GL/glext.h>
  18. #endif
  19. // Create a VBO (Vertex Buffer Object) for a mesh. Actually two VBOs: one
  20. // GL_ARRAY_BUFFER for the vertex positions (V) and one
  21. // GL_ELEMENT_ARRAY_BUFFER for the triangle indices (F)
  22. namespace igl
  23. {
  24. // Inputs:
  25. // V #V by 3 eigen Matrix of mesh vertex 3D positions
  26. // F #F by 3 eigne Matrix of face (triangle) indices
  27. // Outputs:
  28. // V_vbo_id buffer id for vertex positions
  29. // F_vbo_id buffer id for face indices
  30. //
  31. // NOTE: when using glDrawElements VBOs for V and F using MatrixXd and
  32. // MatrixXi will have types GL_DOUBLE and GL_UNSIGNED_INT respectively
  33. //
  34. IGL_INLINE void create_mesh_vbo(
  35. const Eigen::MatrixXd & V,
  36. const Eigen::MatrixXi & F,
  37. GLuint & V_vbo_id,
  38. GLuint & F_vbo_id);
  39. // Inputs:
  40. // V #V by 3 eigen Matrix of mesh vertex 3D positions
  41. // F #F by 3 eigne Matrix of face (triangle) indices
  42. // N #V by 3 eigen Matrix of mesh vertex 3D normals
  43. // Outputs:
  44. // V_vbo_id buffer id for vertex positions
  45. // F_vbo_id buffer id for face indices
  46. // N_vbo_id buffer id for vertex positions
  47. IGL_INLINE void create_mesh_vbo(
  48. const Eigen::MatrixXd & V,
  49. const Eigen::MatrixXi & F,
  50. const Eigen::MatrixXd & N,
  51. GLuint & V_vbo_id,
  52. GLuint & F_vbo_id,
  53. GLuint & N_vbo_id);
  54. }
  55. #ifdef IGL_HEADER_ONLY
  56. # include "create_mesh_vbo.cpp"
  57. #endif
  58. #endif