#include <texture.h>
Public Types | |
enum | { INTENSITY = 0, INTENSITY_ALPHA, COLOR, COLOR_ALPHA, RGB, RGBA } |
The color models of the image. More... | |
Public Member Functions | |
_iil4mitkTexture (iil4mitkWidget *parent) | |
The constructor. | |
virtual | ~_iil4mitkTexture () |
The destructor. | |
void | bind () |
Binds the texture to the OpenGL context of the widget. | |
void | setSize (const unsigned int width, const unsigned int height) |
Sets the size of the texture. | |
unsigned int | width () const |
Gets the width of the texture. | |
unsigned int | height () const |
Gets the height of the texture. | |
void | setModel (int model) |
Sets the color model of the data. If the color is different from white, the RGBA color model is used. | |
void | setData (const unsigned char *data) |
Sets the image data for the texture. If some of the above parameters have been changed, the method brings the texture to a valid state. | |
void | setInterpolation (const bool on=true) |
Turns the bilinear interpolation of the texture on/off. | |
void | invalidate () |
Makes the texture invalid. | |
bool | isValid () |
Checks if the texture is still valid. For example, the texture gets invalid if its parameters are changed without setting new data. |
Definition at line 13 of file texture.h.
anonymous enum |
The color models of the image.
Definition at line 56 of file texture.h.
{INTENSITY = 0, INTENSITY_ALPHA, COLOR, COLOR_ALPHA, RGB, RGBA};
_iil4mitkTexture::_iil4mitkTexture | ( | iil4mitkWidget * | parent ) |
The constructor.
Definition at line 4 of file texture.cpp.
References GL_CLAMP, GL_NEAREST, GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_TEXTURE_MIN_FILTER, GL_TEXTURE_WRAP_S, GL_TEXTURE_WRAP_T, GL_UNPACK_ALIGNMENT, glBindTexture(), glGenTextures(), glPixelStorei(), glTexParameterf(), and glTexParameteri().
: _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) { assert (parent); parent->MakeCurrent (); glGenTextures (1, &_name); glBindTexture (GL_TEXTURE_2D, _name); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); }
_iil4mitkTexture::~_iil4mitkTexture | ( | ) | [virtual] |
The destructor.
Frees the texture in the OpenGL context, if it is still
Definition at line 23 of file texture.cpp.
References glDeleteTextures().
{ if(parent!=NULL) parent->MakeCurrent (); glDeleteTextures (1, &_name); // Are the textures deleted automatically? }
void _iil4mitkTexture::bind | ( | ) |
Binds the texture to the OpenGL context of the widget.
Definition at line 33 of file texture.cpp.
References GL_TEXTURE_2D, and glBindTexture().
Referenced by iil4mitkImage::drawTextures().
{ glBindTexture (GL_TEXTURE_2D, _name); }
unsigned int _iil4mitkTexture::height | ( | ) | const |
Gets the height of the texture.
Definition at line 59 of file texture.cpp.
Referenced by setSize(), and iil4mitkImage::updateTexture().
{
return _height;
}
void _iil4mitkTexture::invalidate | ( | ) |
bool _iil4mitkTexture::isValid | ( | ) |
Checks if the texture is still valid. For example, the texture gets invalid if its parameters are changed without setting new data.
Definition at line 120 of file texture.cpp.
Referenced by iil4mitkImage::drawTextures().
{
return _valid;
}
void _iil4mitkTexture::setData | ( | const unsigned char * | data ) |
Sets the image data for the texture. If some of the above parameters have been changed, the method brings the texture to a valid state.
Definition at line 94 of file texture.cpp.
References GL_TEXTURE_2D, GL_UNSIGNED_BYTE, and glTexImage2D().
Referenced by iil4mitkImage::updateTexture().
{ glTexImage2D (GL_TEXTURE_2D, 0, _internal, _width, _height, 0, _model, GL_UNSIGNED_BYTE, data); _valid = true; }
void _iil4mitkTexture::setInterpolation | ( | const bool | on = true ) |
Turns the bilinear interpolation of the texture on/off.
Definition at line 101 of file texture.cpp.
References GL_LINEAR, GL_NEAREST, GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_TEXTURE_MIN_FILTER, and glTexParameterf().
Referenced by iil4mitkImage::drawTextures().
{ if (on) { glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); } else { glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); } _interpolation = on; }
void _iil4mitkTexture::setModel | ( | int | model ) |
Sets the color model of the data. If the color is different from white, the RGBA color model is used.
model | the color model which is requested |
Definition at line 65 of file texture.cpp.
References COLOR, COLOR_ALPHA, GL_LUMINANCE, GL_LUMINANCE_ALPHA, GL_RGB, GL_RGBA, INTENSITY, INTENSITY_ALPHA, RGB, and RGBA.
Referenced by iil4mitkImage::drawTextures().
{ switch (model) { case INTENSITY: _model = GL_LUMINANCE; break; case INTENSITY_ALPHA: _model = GL_LUMINANCE_ALPHA; break; case COLOR: _model = GL_RGB; break; case COLOR_ALPHA: _model = GL_RGBA; break; case RGB: _model = GL_RGB; break; case RGBA: _model = GL_RGBA; break; } if (_internal != _model) { _internal = _model; _valid = false; } }
void _iil4mitkTexture::setSize | ( | const unsigned int | width, |
const unsigned int | height | ||
) |
unsigned int _iil4mitkTexture::width | ( | ) | const |
Gets the width of the texture.
Definition at line 53 of file texture.cpp.
Referenced by setSize(), and iil4mitkImage::updateTexture().
{
return _width;
}