cloudy-raytracer/common/texture.h

42 lines
1 KiB
C++

#ifndef TEXTURE_H
#define TEXTURE_H
#include "common/CImg.h"
#include "common/color.h"
#include "common/vector2d.h"
using namespace cimg_library;
class Texture {
public:
// Constructor
Texture(int width, int height);
Texture(char const *fileName);
// Image functions
inline void resize(int width, int height) { this->image_.resize(width, height, 1, 3); }
bool load(char const *fileName);
bool save(char const *fileName) const;
// Get
inline bool isNull() const { return this->image_.is_empty(); }
inline int width() const { return this->image_.width(); }
inline int height() const { return this->image_.height(); }
Color getPixelAt(int x, int y) const;
// Set
void setPixelAt(int x, int y, Color const &color);
void setTexture(CImg<float> image);
// Color functions
Color color(float u, float v, bool interpolate = true) const;
Color color(Vector2d const &surfacePosition, bool interpolate = true) const;
CImg<float>& getImage();
private:
CImg<float> image_;
};
#endif