erebus
view liberebus/src/texture.h @ 10:506e114b7ca2
foo
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Sat, 24 May 2014 17:43:46 +0300 |
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_