FramebufferRectangle.cpp 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #include "client/engine/shader/FramebufferRectangle.h"
  2. #include "client/engine/Wrapper.h"
  3. FramebufferRectangle::FramebufferRectangle()
  4. {
  5. }
  6. FramebufferRectangle::~FramebufferRectangle()
  7. {
  8. glDeleteVertexArrays(1, &vba);
  9. glDeleteBuffers(1, &vbo);
  10. }
  11. bool FramebufferRectangle::init()
  12. {
  13. glGenVertexArrays(1, &vba);
  14. glBindVertexArray(vba);
  15. glGenBuffers(1, &vbo);
  16. glBindBuffer(GL_ARRAY_BUFFER, vbo);
  17. glVertexAttribPointer(0, 2, GL_FLOAT, 0, sizeof(float) * 4, (GLvoid*) 0);
  18. glEnableVertexAttribArray(0);
  19. glVertexAttribPointer(2, 2, GL_FLOAT, 0, sizeof(float) * 4, (GLvoid*) (sizeof(float) * 2));
  20. glEnableVertexAttribArray(2);
  21. Engine::printError();
  22. float data[] =
  23. {
  24. -1.0f, 1.0f, 0.0f, 1.0f,
  25. -1.0f, -1.0f, 0.0f, 0.0f,
  26. 1.0f, -1.0f, 1.0f, 0.0f,
  27. -1.0f, 1.0f, 0.0f, 1.0f,
  28. 1.0f, -1.0f, 1.0f, 0.0f,
  29. 1.0f, 1.0f, 1.0f, 1.0f
  30. };
  31. glBufferData(GL_ARRAY_BUFFER, sizeof(float) * 24, data, GL_STATIC_DRAW);
  32. return true;
  33. }
  34. void FramebufferRectangle::draw()
  35. {
  36. glBindVertexArray(vba);
  37. glBindBuffer(GL_ARRAY_BUFFER, vbo);
  38. glDrawArrays(GL_TRIANGLES, 0, 6);
  39. }