Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

texture.C

Go to the documentation of this file.
00001 #include "std/config.H"
00002 #include "texture.H"
00003 
00004 static bool debug = Config::get_var_bool("DEBUG_TEXTURE",false);
00005 
00006 /***********************************************************************P5
00007  * Method : TEXTURE::load_image
00008  * Params : 
00009  * Returns: int (success/failure)
00010  * Effects: load image from file,
00011  *          expand it so dimensions are powers of 2
00012  ***********************************************************************/
00013 int 
00014 TEXTURE::load_image()
00015 {
00016    if (_image_not_available)
00017       return 0;
00018 
00019    _img.load_file(**_file);
00020    expand_image();
00021    if (_img.empty()) {
00022       _image_not_available = true;
00023       cerr << "TEXTURE::load_image - could not load " << _file << endl;
00024    }
00025    return !_img.empty();
00026 }
00027 
00028 /***********************************************************************P5
00029  * Method : TEXTURE::set_image
00030  * Params : GLubyte *data, int w, int h, uint bpp
00031  * Returns: int (success/failure)
00032  * Effects: set image from data (not from file)
00033  *          expand it so dimensions are powers of 2
00034  ***********************************************************************/
00035 int
00036 TEXTURE::set_image(unsigned char *data, int w, int h, uint bpp)
00037 {
00038    _img.set(w,h,bpp,data);
00039    expand_image();
00040    return !_img.empty();
00041 }
00042 
00043 void 
00044 TEXTURE::expand_image() 
00045 {
00046    // expand image so dimensions are powers of two:
00047    // also computes the scale factors so texture coordinates
00048    // in [0,1]x[0,1] map to the real image, not the padded
00049    // extra parts that are added to reach a full power of 2 size:
00050    if (!_img.empty() && _expand_image) {
00051       int w = _img.width();
00052       int h = _img.height();
00053       if (!_img.expand_power2())
00054          return; // no change occurred
00055       err_adv(debug, "TEXTURE::expand_image: expanding from %dx%d to %dx%d",
00056               w, h, _img.width(), _img.height());
00057       _scale = mlib::Wtransf::scaling(
00058          mlib::Wvec((double)w/_img.width(), (double)h/_img.height(), 1)
00059          );
00060    }
00061 }
00062 
00063 void
00064 TEXTURE::expand_power2(int width, int height)
00065 {
00066    _img.resize(width, height, _img.bpp());
00067    _img.expand_power2();
00068 }
00069 
00070 /* end of file texture.C */

Generated on Mon Sep 18 11:39:34 2006 for jot by  doxygen 1.4.4