A 2D tile-based sandbox game.
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

RenderQueue.h 1.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #pragma once
  2. #include <vector>
  3. #include "GlWrappers.h"
  4. namespace Cygnet {
  5. class RenderQueue {
  6. public:
  7. struct Locs {
  8. GLint transform;
  9. GLint position;
  10. GLint texCoord;
  11. GLint tex;
  12. };
  13. RenderQueue(Locs locs, float scale):
  14. locs_(std::move(locs)), pixScale_(scale) {};
  15. RenderQueue(GlProgram &prog, float scale):
  16. RenderQueue({
  17. prog.uniformLoc("transform"),
  18. prog.attribLoc("position"),
  19. prog.attribLoc("texCoord"),
  20. prog.uniformLoc("tex"),
  21. }, scale) {}
  22. void show(float x, float y, GlTexture &tex) { show(x, y, tex.width(), tex.height(), tex.id()); }
  23. void show(float x, float y, float w, float h, GLuint tex) {
  24. queue_.push_back({ x, y, w * pixScale_, h * pixScale_, tex });
  25. }
  26. float pixScale() { return pixScale_; }
  27. void pixScale(float scale) { pixScale_ = scale; }
  28. float scaleX() { return mat_[0]; }
  29. void scaleX(float sx) { mat_[0] = sx; }
  30. float scaleY() { return -mat_[4]; }
  31. void scaleY(float sy) { mat_[4] = -sy; }
  32. float translateX() { return mat_[2]; }
  33. void translateX(float tx) { mat_[2] = tx; }
  34. float translateY() { return mat_[5]; }
  35. void translateY(float ty) { mat_[5] = ty; }
  36. void draw();
  37. private:
  38. struct Entry {
  39. float x, y, w, h;
  40. GLuint tex;
  41. };
  42. Locs locs_;
  43. float pixScale_;
  44. GLfloat mat_[9] = {
  45. 1, 0, 0, // scaleX, 0, translateX,
  46. 0, -1, 0, // 0, -scaleY, translateY,
  47. 0, 0, 1, // 0, 0, 1
  48. };
  49. std::vector<Entry> queue_;
  50. };
  51. }