Renderer.cpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. #include "rendering/Renderer.h"
  2. #include "rendering/wrapper/GLWrapper.h"
  3. Renderer::Renderer(const WindowSize& size, Shader& shader) : size(size), shader(shader), texture(true), color(true) {
  4. shader.use();
  5. GLWrapper::enableBlending();
  6. setTextureMode(false);
  7. setColorMode(false);
  8. }
  9. void Renderer::pop() {
  10. stack.pop();
  11. }
  12. void Renderer::push() {
  13. stack.push();
  14. }
  15. void Renderer::update() {
  16. shader.setMatrix("model", stack.get().getValues());
  17. }
  18. Renderer& Renderer::scale(float sx, float sy) {
  19. stack.get().scale(sx, sy);
  20. return *this;
  21. }
  22. Renderer& Renderer::scale(float s) {
  23. stack.get().scale(s);
  24. return *this;
  25. }
  26. Renderer& Renderer::translate(float tx, float ty) {
  27. stack.get().translate(tx, ty);
  28. return *this;
  29. }
  30. Renderer& Renderer::translateX(float tx) {
  31. stack.get().translateX(tx);
  32. return *this;
  33. }
  34. Renderer& Renderer::translateY(float ty) {
  35. stack.get().translateY(ty);
  36. return *this;
  37. }
  38. Renderer& Renderer::translateTo(float tx, float ty) {
  39. stack.get().translateTo(tx, ty);
  40. return *this;
  41. }
  42. Renderer& Renderer::rotate(float degrees) {
  43. stack.get().rotate(degrees);
  44. return *this;
  45. }
  46. void Renderer::setTextureMode(bool b) {
  47. if(b != texture) {
  48. texture = b;
  49. shader.setInt("useTexture", b);
  50. }
  51. }
  52. void Renderer::setColorMode(bool b) {
  53. if(b != color) {
  54. color = b;
  55. shader.setInt("useColor", b);
  56. }
  57. }
  58. void Renderer::drawString(float x, float y, const char* text) {
  59. setTextureMode(true);
  60. setColorMode(true);
  61. fontRenderer.drawString(x, y, text);
  62. }