#ifndef FILETEXTURE_H #define FILETEXTURE_H #include #include "wrapper/Texture.h" #include "images/PNGReader.h" template 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* buffer = new Color[png.getBufferSize()]; if(!png.readData(buffer)) { texture.setData(png.getWidth(), png.getHeight(), buffer); } delete[] buffer; } void bindTo(int index) const { texture.bindTo(index); } }; #endif