Mesh.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #ifndef MESH_H
  2. #define MESH_H
  3. #include <GL/glew.h>
  4. #include <GLFW/glfw3.h>
  5. class Mesh
  6. {
  7. public:
  8. Mesh(int mode);
  9. virtual ~Mesh();
  10. void addPosition(float x, float y, float z);
  11. void addColor(float r, float g, float b, float a);
  12. void addTexture(float tx, float ty);
  13. void addNormal(float nx, float ny, float nz);
  14. void build(bool print = false);
  15. void draw();
  16. void draw(unsigned int start, unsigned int count);
  17. static const int COLOR = 1;
  18. static const int TEXTURE = 2;
  19. static const int NORMAL = 4;
  20. private:
  21. void ensureCapacity(unsigned int index);
  22. GLuint vba = 0;
  23. GLuint vbo = 0;
  24. unsigned int positionStartIndex = 0;
  25. unsigned int colorStartIndex = 0;
  26. unsigned int textureStartIndex = 0;
  27. unsigned int normalStartIndex = 0;
  28. unsigned int positionIndex = 0;
  29. unsigned int colorIndex = 0;
  30. unsigned int textureIndex = 0;
  31. unsigned int normalIndex = 0;
  32. unsigned int vertexSize = 0;
  33. unsigned int vertices = 0;
  34. unsigned int dataSize = 3;
  35. float* data = nullptr;
  36. };
  37. class NormalTextureMesh : public Mesh
  38. {
  39. public:
  40. NormalTextureMesh();
  41. void addTriangle(float p1x, float p1y, float p1z, float p1nx, float p1ny, float p1nz, float p1texX, float p1texY,
  42. float p2x, float p2y, float p2z, float p2nx, float p2ny, float p2nz, float p2texX, float p2texY,
  43. float p3x, float p3y, float p3z, float p3nx, float p3ny, float p3nz, float p3texX, float p3texY);
  44. void addCuboid(float sx, float sy, float sz, float ex, float ey, float ez,
  45. float topTexStartX, float topTexStartY, float topTexEndX, float topTexEndY,
  46. float bottomTexStartX, float bottomTexStartY, float bottomTexEndX, float bottomTexEndY,
  47. float northTexStartX, float northTexStartY, float northTexEndX, float northTexEndY,
  48. float southTexStartX, float southTexStartY, float southTexEndX, float southTexEndY,
  49. float eastTexStartX, float eastTexStartY, float eastTexEndX, float eastTexEndY,
  50. float westTexStartX, float westTexStartY, float westTexEndX, float westTexEndY);
  51. };
  52. #endif