fork download
  1. -----------------------------------LOADER.h---------------------------------------------
  2.  
  3. class Loader
  4. {
  5. public:
  6. Loader();
  7. ~Loader();
  8.  
  9. public:
  10. std::shared_ptr<RawModel> loadToVAO(const void *position, const void *color);
  11.  
  12. template <typename _Tp, std::size_t _Nm>
  13. std::shared_ptr<RawModel> loadToVAO(std::array<_Tp, _Nm> & position, const void *)
  14. {
  15. VertexArray *vao = new VertexArray();
  16. vao->Bind();
  17. VertexBuffer *vbo = new VertexBuffer(position._M_elems, sizeof(_Tp) * position.size());
  18. VertexBufferLayout layout;
  19. layout.Push<_Tp>(2);
  20. vao->AddBuffer(vbo, layout);
  21. std::shared_ptr<RawModel> rawModel(new RawModel());
  22. rawModel->addVAO(vao);
  23. return rawModel;
  24. }
  25.  
  26. private:
  27. VertexArray createVAO(const void *position, const void *color);
  28. };
  29.  
  30. template <typename V, typename... T>
  31. constexpr auto array_of(T &&... t)
  32. -> std::array<V, sizeof...(T)>
  33. {
  34. return {{std::forward<T>(t)...}};
  35. }
  36.  
  37. -------------------------------------Loader.cpp-------------------------------------------------
  38. #include "Loader.h"
  39.  
  40. std::shared_ptr<RawModel> Loader::loadToVAO(const void *position, const void *color)
  41. {
  42. VertexArray *vao = new VertexArray();
  43. vao->Bind();
  44. VertexBuffer *vbo = new VertexBuffer(position, sizeof(float) * 2 * 4);
  45. VertexBufferLayout layout;
  46. layout.Push<float>(2);
  47. vao->AddBuffer(vbo, layout);
  48. std::shared_ptr<RawModel> rawModel(new RawModel());
  49. rawModel->addVAO(vao);
  50. return rawModel;
  51. }
  52.  
  53. Loader::Loader()
  54. {
  55. }
  56.  
  57. Loader::~Loader()
  58. {
  59. }
  60.  
  61.  
  62. ----------------------------------------main.cpp----------------------------------------------
  63.  
  64. auto arr = array_of<float>(
  65. -0.5f, //v0
  66. 0.5f,
  67.  
  68. -0.5f, //v1
  69. -0.5f,
  70.  
  71. 0.5f, //v2
  72. -0.5f,
  73.  
  74. 0.5f,
  75. 0.5f //v3
  76. );
  77.  
  78. Loader loader;
  79. std::shared_ptr<RawModel> rawModel = loader.loadToVAO<float>(arr, color);
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:38:20: fatal error: Loader.h: No such file or directory
 #include "Loader.h"
                    ^
compilation terminated.
stdout
Standard output is empty