Mesh.cpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #include <fstream>
  2. #include "client/rendering/Mesh.h"
  3. Mesh::Mesh() {
  4. vertexBuffer.bind();
  5. vertexBuffer.setFloatAttribute(0, 3, 0, 11);
  6. vertexBuffer.setFloatAttribute(1, 2, 3, 11);
  7. vertexBuffer.setFloatAttribute(2, 3, 5, 11);
  8. vertexBuffer.setFloatAttribute(3, 3, 8, 11);
  9. }
  10. void Mesh::add(const Triangle& data) {
  11. buffer.add(data);
  12. }
  13. void Mesh::clear() {
  14. buffer.clear();
  15. }
  16. void Mesh::build() {
  17. vertexBuffer.bindBuffer();
  18. vertexBuffer.setData(sizeof (Triangle) * buffer.getLength(), buffer.getData());
  19. }
  20. void Mesh::draw() const {
  21. vertexBuffer.bindArray();
  22. vertexBuffer.draw(buffer.getLength() * 3);
  23. }
  24. void Mesh::save() {
  25. std::ofstream out;
  26. out.open("scene");
  27. for(Triangle& t : buffer) {
  28. out << t.a.position[0] << ", ";
  29. out << t.a.position[1] << ", ";
  30. out << t.a.position[2] << ", ";
  31. out << t.a.texture[0] << ", ";
  32. out << t.a.texture[1] << "\n";
  33. out << t.b.position[0] << ", ";
  34. out << t.b.position[1] << ", ";
  35. out << t.b.position[2] << ", ";
  36. out << t.b.texture[0] << ", ";
  37. out << t.b.texture[1] << "\n";
  38. out << t.c.position[0] << ", ";
  39. out << t.c.position[1] << ", ";
  40. out << t.c.position[2] << ", ";
  41. out << t.c.texture[0] << ", ";
  42. out << t.c.texture[1] << "\n";
  43. }
  44. }