basic/geometry/IGS/IGS_Texture.cpp

Go to the documentation of this file.
00001 #include <assert.h>
00002 #include "IGS_Texture.h"
00003 #include "opengl/glos.h"
00004 #include <gl/gl.h>
00005 #include <gl/glaux.h>
00006 
00007 //=============================================================================
00008 // Constructor
00009 //
00010 // Description: Constructor
00011 //=============================================================================
00012 IGS_Texture::IGS_Texture():
00013         mFilename( NULL ),
00014         mImage( NULL ),
00015         mTextureNumber( 0 )
00016 {
00017 }
00018 
00019 //=============================================================================
00020 // Destructor
00021 //
00022 // Description: Destructor
00023 //=============================================================================
00024 IGS_Texture::~IGS_Texture()
00025 {
00026         delete[] mFilename;
00027         mFilename = NULL;
00028 
00029 
00030 }
00031 
00032 //=============================================================================
00033 // GetBuffer
00034 //
00035 // Description: Gets the buffer that this texture uses for rendering
00036 //=============================================================================
00037 const unsigned char* IGS_Texture::GetBuffer() const
00038 {
00039         return this->mImage->data;
00040 }
00041 
00042 //=============================================================================
00043 // GetSizeX
00044 //
00045 // Description: Gets the X size of this texture
00046 //=============================================================================
00047 int IGS_Texture::GetSizeX() const
00048 {
00049         return this->mImage->sizeX;
00050 }
00051 
00052 //=============================================================================
00053 // GetSizeY
00054 //
00055 // Description: Gets the Y size of this texture
00056 //=============================================================================
00057 int IGS_Texture::GetSizeY() const
00058 {
00059         return this->mImage->sizeY;
00060 }
00061 
00062 
00063 //=============================================================================
00064 // SetFilename
00065 //
00066 // Description: sets the filename for a particular texture
00067 //=============================================================================
00068 void IGS_Texture::LoadFromDisk()
00069 {
00070         mImage = auxDIBImageLoad( this->mFilename );
00071         assert( mImage != NULL );
00072 
00073         GLenum errorcode;
00074         errorcode = ::glGetError();
00075         errorcode = ::glGetError();
00076 
00077         ::glEnable( GL_TEXTURE_2D );
00078         errorcode = ::glGetError();
00079         assert( errorcode == GL_NO_ERROR );
00080 
00081         ::glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
00082         errorcode = ::glGetError();
00083         assert( errorcode == GL_NO_ERROR );
00084 
00085         ::glGenTextures( 1, &this->mTextureNumber );
00086         errorcode = ::glGetError();
00087         assert( errorcode == GL_NO_ERROR );
00088 
00089         ::glBindTexture( GL_TEXTURE_2D, this->mTextureNumber );
00090         errorcode = ::glGetError();
00091         assert( errorcode == GL_NO_ERROR );
00092 
00093         ::glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
00094         errorcode = ::glGetError();
00095         assert( errorcode == GL_NO_ERROR );
00096 
00097         ::glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
00098         errorcode = ::glGetError();
00099         assert( errorcode == GL_NO_ERROR );
00100 
00101         ::glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST );
00102         errorcode = ::glGetError();
00103         assert( errorcode == GL_NO_ERROR );
00104 
00105         ::glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
00106         errorcode = ::glGetError();
00107         assert( errorcode == GL_NO_ERROR );
00108 
00109         ::glTexImage2D
00110         ( 
00111                 GL_TEXTURE_2D, 
00112                 0, 
00113                 GL_RGB,                                 //IAN IMPROVE: we will need an alpha componenet later!
00114 //              this->GetSizeX(), 
00115 //              this->GetSizeY(),
00116                 256,
00117                 256,
00118                 0,
00119                 GL_RGB,
00120                 GL_UNSIGNED_BYTE,
00121                 this->GetBuffer()
00122         );
00123 
00124         errorcode = ::glGetError();
00125         assert( errorcode == GL_NO_ERROR );
00126 }
00127 //=============================================================================
00128 // MakeActive
00129 //
00130 // Description: sets this texture to be used for texture mapping
00131 //=============================================================================
00132 void IGS_Texture::MakeActive() const
00133 {
00134         GLenum errorcode;
00135         errorcode = ::glGetError();
00136         errorcode = ::glGetError();
00137 
00138         ::glBindTexture( GL_TEXTURE_2D, this->mTextureNumber );
00139         errorcode = ::glGetError();
00140         assert( errorcode == GL_NO_ERROR );
00141 }
00142 
00143 //=============================================================================
00144 // SetFilename
00145 //
00146 // Description: sets the filename for a particular texture
00147 //=============================================================================
00148 void IGS_Texture::SetFilename( const char* name )
00149 {
00150         delete[] mFilename;
00151         mFilename = new char[ strlen( name ) + 1 ];
00152         strcpy( mFilename, name );
00153 }

Generated on Sat Apr 1 21:30:33 2006 for Motion Planning Kernel by  doxygen 1.4.6-NO