12345678910111213141516171819202122232425262728293031323334 |
- #ifndef FILETEXTURE_H
- #define FILETEXTURE_H
- #include "wrapper/Texture.h"
- #include "images/PNGReader.h"
- template<int N>
- class FileTexture final {
- Texture texture;
- public:
- FileTexture(const char* path) : texture(TextureFormat::color8(N)) {
- PNGReader png(path);
- if(png.hasError()) {
- return;
- }
- if(png.getChannels() != N) {
- std::cout << "expected " << N << " from '" << path << "' but got " << png.getChannels() << "\n";
- return;
- }
- Color<N>* buffer = new Color<N>[png.getBufferSize()];
- if(!png.readData(buffer)) {
- texture.setData(png.getWidth(), png.getHeight(), buffer);
- }
- delete[] buffer;
- }
- void bindTo(int index) const {
- texture.bindTo(index);
- }
- };
- #endif
|