erebus

annotate liberebus/src/texture.h @ 8:e2d9bf168a41

semi-works ...
author John Tsiombikas <nuclear@member.fsf.org>
date Sat, 24 May 2014 06:12:57 +0300
parents 4abdce1361b9
children
rev   line source
nuclear@2 1 #ifndef TEXTURE_H_
nuclear@2 2 #define TEXTURE_H_
nuclear@2 3
nuclear@2 4 #include "image.h"
nuclear@2 5 #include "color.h"
nuclear@2 6
nuclear@2 7 class Texture {
nuclear@2 8 public:
nuclear@2 9 Image<float> img;
nuclear@2 10
nuclear@2 11 inline Color lookup(float u, float v) const;
nuclear@2 12
nuclear@2 13 bool load(const char *fname) { return img.load(fname); }
nuclear@2 14 };
nuclear@2 15
nuclear@2 16
nuclear@2 17 inline Color Texture::lookup(float u, float v) const
nuclear@2 18 {
nuclear@2 19 int xsz = img.get_width();
nuclear@2 20 int ysz = img.get_height();
nuclear@2 21
nuclear@2 22 int x = (float)u / (float)xsz;
nuclear@2 23 int y = (float)v / (float)ysz;
nuclear@2 24
nuclear@2 25 float *pix = img.get_pixels() + ((y % ysz) * xsz + (x % xsz)) * 4;
nuclear@2 26 return Color(pix[0], pix[1], pix[2]);
nuclear@2 27 }
nuclear@2 28
nuclear@2 29
nuclear@2 30 #endif // TEXTURE_H_