12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /* rectangle.hpp: generates a vertex mesh and draws it.
  2. *
  3. * Copyright (C) 2014: Dalton Nell, Slop Contributors (https://github.com/naelstrof/slop/graphs/contributors).
  4. *
  5. * This file is part of Slop.
  6. *
  7. * Slop is free software: you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation, either version 3 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * Slop is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with Slop. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. #ifndef N_GLRECTANGLE_H_
  21. #define N_GLRECTANGLE_H_
  22. #include <iostream>
  23. #include <GL/glew.h>
  24. #include <GL/gl.h>
  25. #include <glm/glm.hpp>
  26. #include <vector>
  27. #include "shader.hpp"
  28. #include "rectangle.hpp"
  29. namespace slop {
  30. struct RectangleBuffer {
  31. unsigned int corner_verts;
  32. unsigned int corner_uvs;
  33. unsigned int rectangle_verts;
  34. unsigned int rectangle_uvs;
  35. unsigned int center_verts;
  36. unsigned int center_uvs;
  37. };
  38. class GLRectangle : public Rectangle {
  39. private:
  40. glm::vec2 ul, oul;
  41. glm::vec2 bl, obl;
  42. glm::vec2 ur, our;
  43. glm::vec2 br, obr;
  44. bool highlight;
  45. void generateBuffers();
  46. RectangleBuffer buffer;
  47. unsigned int corner_vertCount;
  48. unsigned int rectangle_vertCount;
  49. unsigned int center_vertCount;
  50. float border;
  51. float padding;
  52. Shader* shader;
  53. glm::vec4 color;
  54. public:
  55. glm::vec4 getRect();
  56. GLRectangle(glm::vec2 p1, glm::vec2 p2, float border = 1, float padding = 0, glm::vec4 color = glm::vec4(1,1,1,1), bool highlight = false );
  57. ~GLRectangle();
  58. void setPoints( glm::vec2 p1, glm::vec2 p2 );
  59. void draw(glm::mat4& matrix);
  60. };
  61. }
  62. #endif // N_RECTANGLE_H_