erebus

diff 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 diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/liberebus/src/texture.h	Sun Apr 27 16:02:47 2014 +0300
     1.3 @@ -0,0 +1,30 @@
     1.4 +#ifndef TEXTURE_H_
     1.5 +#define TEXTURE_H_
     1.6 +
     1.7 +#include "image.h"
     1.8 +#include "color.h"
     1.9 +
    1.10 +class Texture {
    1.11 +public:
    1.12 +	Image<float> img;
    1.13 +
    1.14 +	inline Color lookup(float u, float v) const;
    1.15 +
    1.16 +	bool load(const char *fname) { return img.load(fname); }
    1.17 +};
    1.18 +
    1.19 +
    1.20 +inline Color Texture::lookup(float u, float v) const
    1.21 +{
    1.22 +	int xsz = img.get_width();
    1.23 +	int ysz = img.get_height();
    1.24 +
    1.25 +	int x = (float)u / (float)xsz;
    1.26 +	int y = (float)v / (float)ysz;
    1.27 +
    1.28 +	float *pix = img.get_pixels() + ((y % ysz) * xsz + (x % xsz)) * 4;
    1.29 +	return Color(pix[0], pix[1], pix[2]);
    1.30 +}
    1.31 +
    1.32 +
    1.33 +#endif	// TEXTURE_H_
    1.34 \ No newline at end of file