A utility class for one-dimensional textures. More...
#include <util/texture.h>
Public Member Functions | |
void | bind () |
Bind the texture. | |
const Texture1D & | operator= (const Texture1D &texture) |
Assignment operator. | |
Texture1D (std::string filename) | |
Constructor initialising from an image file. | |
Texture1D (const Texture1D &texture) | |
Copy Constructor. | |
Texture1D () | |
Default constructor. | |
~Texture1D () | |
Destructor. | |
Static Public Member Functions | |
static void | blend () |
Sets the blending mode to blend. | |
static void | clamp (bool enable=true) |
Enables texture coordinate clamping. | |
static void | decal () |
Sets the blending mode to decal. | |
static void | filter (bool enable=true) |
Enables filtering. | |
static void | modulate () |
Sets the blending mode to modulate. | |
static void | replace () |
Sets the blending mode to replace. |
A utility class for one-dimensional textures.
Definition at line 18 of file texture.h.
util::Texture1D::Texture1D | ( | ) |
Default constructor.
Definition at line 7 of file texture.cpp.
util::Texture1D::Texture1D | ( | const Texture1D & | texture | ) |
Copy Constructor.
Definition at line 14 of file texture.cpp.
References clamp(), filter(), and modulate().
00015 : 00016 data(0), 00017 size(0), 00018 tex_name(0) 00019 { 00020 if (!texture.data) return; 00021 00022 size = texture.size; 00023 data = new GLubyte[size * 4]; 00024 00025 for (unsigned int i = 0; i < size; i++) 00026 data[i] = texture.data[i]; 00027 00028 glEnable(GL_TEXTURE_1D); 00029 00030 glPixelStorei(GL_UNPACK_ALIGNMENT, 1); 00031 00032 glGenTextures(1, &tex_name); 00033 glBindTexture(GL_TEXTURE_1D, tex_name); 00034 glTexImage1D(GL_TEXTURE_1D, 0, GL_RGBA, size, 0, GL_RGBA, GL_UNSIGNED_BYTE, data); 00035 00036 clamp(); 00037 filter(); 00038 modulate(); }
util::Texture1D::Texture1D | ( | std::string | filename | ) |
Constructor initialising from an image file.
filename | The file containing the image. The image must be in a format supported by the Qt image filters. |
Definition at line 44 of file texture.cpp.
References clamp(), filter(), and modulate().
00045 : 00046 data(0), 00047 size(0), 00048 tex_name(0) 00049 { 00050 QImage image(filename.c_str()); 00051 if (!image.width()) { 00052 std::cerr << "Error: Texture initialised by " 00053 << filename << " is empty." << std::endl; 00054 return; 00055 } 00056 00057 size = image.width(); 00058 00059 data = new GLubyte[size * 4]; 00060 for (unsigned int x = 0; x < size; x++) { 00061 data[x * 4 + 0] = (GLubyte)qRed(image.pixel(x, 0)); 00062 data[x * 4 + 1] = (GLubyte)qGreen(image.pixel(x, 0)); 00063 data[x * 4 + 2] = (GLubyte)qBlue(image.pixel(x, 0)); 00064 data[x * 4 + 3] = (GLubyte)qAlpha(image.pixel(x, 0)); 00065 } 00066 00067 glEnable(GL_TEXTURE_1D); 00068 00069 glPixelStorei(GL_UNPACK_ALIGNMENT, 1); 00070 00071 glGenTextures(1, &tex_name); 00072 glBindTexture(GL_TEXTURE_1D, tex_name); 00073 glTexImage1D(GL_TEXTURE_1D, 0, GL_RGBA, size, 0, GL_RGBA, GL_UNSIGNED_BYTE, data); 00074 00075 clamp(); 00076 filter(); 00077 modulate(); }
util::Texture1D::~Texture1D | ( | ) |
Destructor.
Definition at line 110 of file texture.cpp.
void util::Texture1D::bind | ( | ) |
Bind the texture.
Definition at line 116 of file texture.cpp.
void util::Texture1D::blend | ( | ) | [static] |
Sets the blending mode to blend.
Definition at line 155 of file texture.cpp.
void util::Texture1D::clamp | ( | bool | enable = true |
) | [static] |
Enables texture coordinate clamping.
enable | If true enable clamping, if false repeat. |
Definition at line 123 of file texture.cpp.
Referenced by operator=(), and Texture1D().
void util::Texture1D::decal | ( | ) | [static] |
Sets the blending mode to decal.
Definition at line 150 of file texture.cpp.
void util::Texture1D::filter | ( | bool | enable = true |
) | [static] |
Enables filtering.
enable | If true, filtering is enabled, if false it is disabled/ |
Definition at line 133 of file texture.cpp.
Referenced by operator=(), and Texture1D().
00133 { 00134 if (enable) { 00135 glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 00136 glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 00137 } 00138 else { 00139 glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 00140 glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 00141 } 00142 }
void util::Texture1D::modulate | ( | ) | [static] |
Sets the blending mode to modulate.
Definition at line 145 of file texture.cpp.
Referenced by operator=(), and Texture1D().
const util::Texture1D & util::Texture1D::operator= | ( | const Texture1D & | texture | ) |
Assignment operator.
Definition at line 80 of file texture.cpp.
References clamp(), filter(), and modulate().
00080 { 00081 glDeleteTextures(1, &tex_name); 00082 delete[] data; 00083 data = 0; 00084 size = 0; 00085 00086 if (!texture.data) return *this; 00087 00088 size = texture.size; 00089 data = new GLubyte[size * 4]; 00090 00091 for (unsigned int i = 0; i < size; i++) 00092 data[i] = texture.data[i]; 00093 00094 glEnable(GL_TEXTURE_1D); 00095 00096 glPixelStorei(GL_UNPACK_ALIGNMENT, 1); 00097 00098 glGenTextures(1, &tex_name); 00099 glBindTexture(GL_TEXTURE_1D, tex_name); 00100 glTexImage1D(GL_TEXTURE_1D, 0, GL_RGBA, size, 0, GL_RGBA, GL_UNSIGNED_BYTE, data); 00101 00102 clamp(); 00103 filter(); 00104 modulate(); 00105 00106 return *this; 00107 }
void util::Texture1D::replace | ( | ) | [static] |
Sets the blending mode to replace.
Definition at line 160 of file texture.cpp.