00001 /*************************************************************************** 00002 * This file is part of OpenCAL: Open Computer Animation Library * 00003 * I created OpenCAL as my master's thesis Computer Science (multimedia) * 00004 * at the tUL university in Diepenbeek, Belgium * 00005 * * 00006 * Copyright (C) 2003-2004 by Jeroen Dierckx * 00007 * jeroen.dierckx@student.luc.ac.be * 00008 * * 00009 ***************************************************************************/ 00010 00011 // Includes 00012 #include "Texture.h" 00013 using namespace OpenCAL; 00014 using namespace Utils; 00015 00016 /* 00017 #include <OpenCAL/Image.h> 00018 */ 00019 00020 using namespace std; 00021 00022 00023 /****************************** 00024 * Constructors and destructor * 00025 ******************************/ 00026 00027 /* 00028 Texture::Texture() 00029 : m_textureID(0), m_width(0), m_height(0), m_image(0) 00030 { 00031 } 00032 */ 00033 00034 Texture::Texture(const string &filename, bool clamp) 00035 : m_filename(filename), m_clamp(clamp) 00036 //: m_textureID(0), m_width(0), m_height(0), m_image(0) 00037 { 00038 //loadFromFile(filename); 00039 } 00040 00041 Texture::~Texture() 00042 { 00043 /* 00044 #ifdef USE_OPENGL 00045 if(m_textureID != 0) 00046 glDeleteTextures(1, &m_textureID); 00047 #endif // USE_OPENGL 00048 */ 00049 00050 /* 00051 if(m_image) 00052 delete m_image; 00053 */ 00054 } 00055 00056 00057 /****************** 00058 * Other functions * 00059 ******************/ 00060 00061 /* 00062 void Texture::initialize(bool clamp) 00063 { 00064 if(!m_image) return; 00065 00066 #ifdef USE_OPENGL 00068 if(m_textureID != 0) 00069 glDeleteTextures(1, &m_textureID); 00070 00071 //glPixelStorei(GL_UNPACK_ALIGNMENT, 1); 00072 glGenTextures(1, &m_textureID); 00073 glBindTexture(GL_TEXTURE_2D, m_textureID); 00074 00075 // Select modulate to mix texture with color for shading 00076 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); 00077 00078 // When texture area is small, bilinear filter the closest mipmap 00079 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST); 00080 00081 // When texture area is large, bilinear filter the original 00082 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 00083 00084 // The texture wraps over at the edges (repeat), or ends at the edges (clamp) 00085 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, clamp ? GL_CLAMP : GL_REPEAT); 00086 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, clamp ? GL_CLAMP : GL_REPEAT); 00087 00088 // Build our texture mipmaps 00089 GLenum mode; 00090 switch(m_image->getDepth()) 00091 { 00092 case 3: 00093 mode = GL_RGB; 00094 break; 00095 case 4: 00096 mode = GL_RGBA; 00097 break; 00098 00099 default: 00100 cerr << "Unknown image depth!" << endl; 00101 }; 00102 gluBuild2DMipmaps(GL_TEXTURE_2D, m_image->getDepth(), m_width, m_height, mode, GL_UNSIGNED_BYTE, m_image->getData()); 00103 //glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, m_width, m_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, m_image->getData()); 00104 00105 00106 //glBindTexture(GL_TEXTURE_2D, 0); 00107 cout << "Texture ID: " << m_textureID << endl; 00108 #endif // USE_OPENGL 00109 00110 delete m_image; 00111 m_image = 0; 00112 } 00113 */ 00114 00115 /* 00116 void Texture::loadFromFile(const string &filename) 00117 { 00118 #ifdef USE_OPENGL 00119 if(m_textureID != 0) 00120 glDeleteTextures(1, &m_textureID); 00121 #endif // USE_OPENGL 00122 00123 if(m_image) 00124 delete m_image; 00125 00126 m_textureID = 0; 00127 m_image = new Image(filename); 00128 m_width = m_image->getWidth(); 00129 m_height = m_image->getHeight(); 00130 } 00131 */ 00132 00133 /* 00134 #ifdef USE_OPENGL 00135 void Texture::bindGL() 00136 { 00137 glBindTexture(GL_TEXTURE_2D, m_textureID); 00138 } 00139 00140 void Texture::unbindGL() 00141 { 00142 glBindTexture(GL_TEXTURE_2D, 0); 00143 } 00144 #endif // USE_OPENGL 00145 */