ColorRenderer.cpp 607 B

1234567891011121314151617
  1. #include "rendering/ColorRenderer.h"
  2. ColorRenderer::ColorRenderer() : buffer(8 * 1024 * 1024, 2 * sizeof(float) + 4) {
  3. vertexBuffer.bind();
  4. int step = 2 * sizeof(float) + 4;
  5. vertexBuffer.setFloatAttribute(0, 2, 0, step);
  6. vertexBuffer.setColorAttribute(2, 2 * sizeof(float), step);
  7. }
  8. void ColorRenderer::draw(const Vertex& v1, const Vertex& v2, const Vertex& v3) {
  9. vertexBuffer.bind();
  10. buffer.reset(3 * sizeof (float) * 6);
  11. buffer.add(v1.x).add(v1.y).add(v1.color);
  12. buffer.add(v2.x).add(v2.y).add(v2.color);
  13. buffer.add(v3.x).add(v3.y).add(v3.color);
  14. buffer.draw();
  15. }