erebus

view liberebus/src/texture.h @ 48:9971a08f4104

merged
author John Tsiombikas <nuclear@member.fsf.org>
date Wed, 24 Feb 2016 00:29:31 +0200
parents 4abdce1361b9
children
line source
1 #ifndef TEXTURE_H_
2 #define TEXTURE_H_
4 #include "image.h"
5 #include "color.h"
7 class Texture {
8 public:
9 Image<float> img;
11 inline Color lookup(float u, float v) const;
13 bool load(const char *fname) { return img.load(fname); }
14 };
17 inline Color Texture::lookup(float u, float v) const
18 {
19 int xsz = img.get_width();
20 int ysz = img.get_height();
22 int x = (float)u / (float)xsz;
23 int y = (float)v / (float)ysz;
25 float *pix = img.get_pixels() + ((y % ysz) * xsz + (x % xsz)) * 4;
26 return Color(pix[0], pix[1], pix[2]);
27 }
30 #endif // TEXTURE_H_