util::Texture1D Class Reference

A utility class for one-dimensional textures. More...

#include <util/texture.h>

List of all members.

Public Member Functions

void bind ()
 Bind the texture.
const Texture1Doperator= (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.

Detailed Description

A utility class for one-dimensional textures.

Definition at line 18 of file texture.h.


Constructor & Destructor Documentation

util::Texture1D::Texture1D (  ) 

Default constructor.

Definition at line 7 of file texture.cpp.

00008                          :
00009   data(0),
00010   size(0),
00011   tex_name(0)
{}

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.

Parameters:
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.

00110                           {
00111   glDeleteTextures(1, &tex_name);
00112   delete[] data;
00113 }


Member Function Documentation

void util::Texture1D::bind (  ) 

Bind the texture.

Definition at line 116 of file texture.cpp.

00116                          {
00117   glBindTexture(GL_TEXTURE_1D, tex_name);
00118 }

void util::Texture1D::blend (  )  [static]

Sets the blending mode to blend.

Definition at line 155 of file texture.cpp.

00155                           {
00156   glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_BLEND);
00157 }

void util::Texture1D::clamp ( bool  enable = true  )  [static]

Enables texture coordinate clamping.

Parameters:
enable If true enable clamping, if false repeat.

Definition at line 123 of file texture.cpp.

Referenced by operator=(), and Texture1D().

00123                                      {
00124   if (enable)
00125     glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_WRAP_S, GL_CLAMP);
00126   else
00127     glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_WRAP_S, GL_REPEAT);
00128 }

void util::Texture1D::decal (  )  [static]

Sets the blending mode to decal.

Definition at line 150 of file texture.cpp.

00150                           {
00151   glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
00152 }

void util::Texture1D::filter ( bool  enable = true  )  [static]

Enables filtering.

Parameters:
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().

00145                              {
00146   glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
00147 }

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.

00160                             {
00161   glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
00162 }


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Generated on Fri May 31 15:38:35 2013 for VVE by  doxygen 1.6.3