2022-11-05 22:08:16 +01:00
|
|
|
#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:
|
2023-01-24 13:32:19 +01:00
|
|
|
// Constructor
|
|
|
|
Texture(int width, int height);
|
|
|
|
Texture(char const *fileName);
|
2022-11-05 22:08:16 +01:00
|
|
|
|
2023-01-24 13:32:19 +01:00
|
|
|
// 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;
|
2022-11-05 22:08:16 +01:00
|
|
|
|
2023-01-24 13:32:19 +01:00
|
|
|
// 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);
|
2023-01-25 10:20:27 +01:00
|
|
|
void setTexture(CImg<float> image);
|
|
|
|
|
2023-01-24 13:32:19 +01:00
|
|
|
|
|
|
|
// Color functions
|
|
|
|
Color color(float u, float v, bool interpolate = true) const;
|
|
|
|
Color color(Vector2d const &surfacePosition, bool interpolate = true) const;
|
2022-11-05 22:08:16 +01:00
|
|
|
|
2023-01-25 10:20:27 +01:00
|
|
|
CImg<float> getImage();
|
2023-01-24 13:32:19 +01:00
|
|
|
|
2023-01-25 10:20:27 +01:00
|
|
|
private:
|
2023-01-24 13:32:19 +01:00
|
|
|
CImg<float> image_;
|
2022-11-05 22:08:16 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|