diff -r 907929fa9b59 -r 9dbb9c8c115b include/material.h --- a/include/material.h Wed Apr 23 19:35:03 2008 +0200 +++ b/include/material.h Thu Apr 24 10:49:11 2008 +0200 @@ -223,6 +223,45 @@ }; /** + * pixmap for image texture + */ +class Pixmap +{ + Colour *data; + int w,h; +public: + Pixmap(): data(NULL), w(0), h(0) {}; + Pixmap(Float *adata, int aw, int ah): + data((Colour*)(adata)), w(aw), h(ah) {}; + void setData(Float *adata, int aw, int ah) + { data = (Colour*)adata; w = aw; h = ah; }; + Colour get(int x, int y) { return data[y*w + x]; }; + int getWidth() { return w; }; + int getHeight() { return h; }; +}; + +/** + * 2D image texture + */ +class ImageTexture: public Texture2D +{ + Pixmap *pixmap; +public: + ImageTexture(TextureMap *tmap, Pixmap *image): + Texture2D(tmap), pixmap(image) {}; + Colour evaluate(const Vector3 &point) + { + Float u,v; + map->map(point, u,v); + u = u - 0.5; + u -= floor(u); + v = -(v - 0.5); + v -= floor(v); + return pixmap->get(u*pixmap->getWidth(), v*pixmap->getHeight()); + }; +}; + +/** * 2D checkers texture */ class CheckersTexture: public Texture2D