Go to the documentation of this file.00001 #include <assert.h>
00002 #include "texture.h"
00003
00004 _iil4mitkTexture::_iil4mitkTexture (iil4mitkWidget* aParent)
00005 : _width (0), _height (0), _model (0), _internal (0), _valid (false), _interpolation (false), _red (1.0), _green (1.0), _blue (1.0), _alpha (1.0),parent(aParent)
00006 {
00007 assert (parent);
00008
00009 parent->MakeCurrent ();
00010 glGenTextures (1, &_name);
00011 glBindTexture (GL_TEXTURE_2D, _name);
00012 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
00013 glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
00014 glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
00015 glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
00016 glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
00017 }
00018
00019
00020
00021
00022
00023 _iil4mitkTexture::~_iil4mitkTexture () {
00024 if(parent!=NULL)
00025 parent->MakeCurrent ();
00026 glDeleteTextures (1, &_name);
00027
00028
00029
00030 }
00031
00032 void
00033 _iil4mitkTexture::bind ()
00034 {
00035 glBindTexture (GL_TEXTURE_2D, _name);
00036 }
00037
00038
00039 void
00040 _iil4mitkTexture::setSize (const unsigned int width, const unsigned int height)
00041 {
00042 assert (width > 0);
00043 assert (height > 0);
00044
00045 if ((width != _width) || (height != _height)) {
00046 _valid = false;
00047 }
00048 _width = width;
00049 _height = height;
00050 }
00051
00052 unsigned int
00053 _iil4mitkTexture::width () const
00054 {
00055 return _width;
00056 }
00057
00058 unsigned int
00059 _iil4mitkTexture::height () const
00060 {
00061 return _height;
00062 }
00063
00064 void
00065 _iil4mitkTexture::setModel (int model)
00066 {
00067 switch (model) {
00068 case INTENSITY:
00069 _model = GL_LUMINANCE;
00070 break;
00071 case INTENSITY_ALPHA:
00072 _model = GL_LUMINANCE_ALPHA;
00073 break;
00074 case COLOR:
00075 _model = GL_RGB;
00076 break;
00077 case COLOR_ALPHA:
00078 _model = GL_RGBA;
00079 break;
00080 case RGB:
00081 _model = GL_RGB;
00082 break;
00083 case RGBA:
00084 _model = GL_RGBA;
00085 break;
00086 }
00087 if (_internal != _model) {
00088 _internal = _model;
00089 _valid = false;
00090 }
00091 }
00092
00093 void
00094 _iil4mitkTexture::setData (const unsigned char* data)
00095 {
00096 glTexImage2D (GL_TEXTURE_2D, 0, _internal, _width, _height, 0, _model, GL_UNSIGNED_BYTE, data);
00097 _valid = true;
00098 }
00099
00100 void
00101 _iil4mitkTexture::setInterpolation (const bool on) {
00102 if (on) {
00103 glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
00104 glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
00105 } else {
00106 glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
00107 glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
00108 }
00109 _interpolation = on;
00110 }
00111
00112 void
00113 _iil4mitkTexture::invalidate ()
00114 {
00115
00116 _valid = false;
00117 }
00118
00119 bool
00120 _iil4mitkTexture::isValid ()
00121 {
00122 return _valid;
00123 }