erebus

view liberebus/src/texture.h @ 2:474a0244f57d

fixed specialization mistake fixed line endings added makefiles
author John Tsiombikas <nuclear@member.fsf.org>
date Mon, 28 Apr 2014 06:31:10 +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_