FileTexture.h 583 B

123456789101112131415161718192021222324252627282930
  1. #ifndef FILE_TEXTURE_H
  2. #define FILE_TEXTURE_H
  3. #include <iostream>
  4. #include "client/rendering/wrapper/Texture.h"
  5. #include "gaming-core/images/PNGReader.h"
  6. class FileTexture final {
  7. Texture texture;
  8. public:
  9. FileTexture(const char* path);
  10. void bind(int index) const;
  11. private:
  12. template<int N>
  13. void read(PNGReader& png) {
  14. Color<N>* buffer = new Color<N>[png.getBufferSize()];
  15. if(png.readData(buffer)) {
  16. return;
  17. }
  18. texture.setColorData(png.getWidth(), png.getHeight(), buffer);
  19. delete[] buffer;
  20. }
  21. };
  22. #endif