Texture2D.cc

Go to the documentation of this file.
00001 #include <esg/texture/Texture2D.h>
00002 
00003 using namespace esg;
00004 
00005 void Texture2D::_delete_texture(void)
00006 {
00007     if (_texture) 
00008         for (unsigned i = 0; i < _height; i++) delete [] _texture[i];
00009     delete [] _texture;
00010 }
00011 
00012 void Texture2D::_allocate_texture(unsigned w, unsigned h)
00013 {
00014     _delete_texture();
00015     _width   = w;
00016     _height  = h;
00017 #ifdef WIN32
00018         _texture = (Color3f**) malloc(_height * sizeof(Color3f*));
00019 #else
00020         _texture = new Color3f* [_height];
00021 #endif
00022     for (unsigned i = 0; i < _height; i++)
00023         _texture[i] = new Color3f [_width];
00024 }
00025 
00026 
00027 
00028 bool Texture2D::value(unsigned row, unsigned col, Color3f& c) const
00029 {
00030     if (_texture && row < _height && col < _width) {
00031         c.set(_texture[row][col]);
00032         return true;
00033     }
00034     return false;
00035 }
00036 
00037 bool Texture2D::mapUV(float u, float v, Color3f& c) const
00038 {
00039     if (!_texture) return false;
00040     c.set(_texture [(unsigned)(fabs(_height*(v-(int)v)))] [(unsigned)(fabs(_width*(u-(int)u)))]);
00041     return true;
00042 }
00043 
00044 bool Texture2D::mapXYZ(float x, float y, float z, Color3f& c) const
00045 {
00046     return false;
00047 }

Generated on Wed Jun 28 12:24:32 2006 for esg by  doxygen 1.4.6