erebus

view liberebus/src/texture.h @ 0:4abdce1361b9

initial commit
author John Tsiombikas <nuclear@member.fsf.org>
date Sun, 27 Apr 2014 16:02:47 +0300
parents
children 474a0244f57d
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_