Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | Related Pages

Image.cpp

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 "Image.h" 00013 #include <OpenCAL/ImageLoader.h> 00014 using namespace OpenCAL::Utils; 00015 00016 using namespace std; 00017 00018 00019 /****************************** 00020 * Constructors and destructor * 00021 ******************************/ 00022 00023 Image::Image(unsigned int width, unsigned int height, unsigned int depth) 00024 : m_width(width), m_height(height), m_depth(depth) 00025 { 00026 m_data = new unsigned char[width * height * depth]; 00027 } 00028 00029 Image::Image(const string &filename) 00030 : m_width(0), m_height(0), m_depth(0), m_data(0) 00031 { 00032 ImageLoader::loadImage(this, filename); 00033 } 00034 00035 Image::~Image() 00036 { 00037 if(m_data) 00038 delete[] m_data; 00039 } 00040 00041 00042 /****************** 00043 * Other functions * 00044 ******************/ 00045 00046 void Image::resize(unsigned int width, unsigned int height, unsigned int depth) 00047 { 00048 if(m_data) 00049 delete[] m_data; 00050 00051 m_width = width; 00052 m_height = height; 00053 m_depth = depth; 00054 00055 m_data = new unsigned char[width * height * depth]; 00056 } 00057 00058 void Image::clear() 00059 { 00060 memcpy(m_data, 0, m_width * m_height * m_depth * sizeof(unsigned char)); 00061 } 00062 00063 00064 #ifdef BLABLABLA 00065 void Image::load(const string &filename, bool clamp) 00066 { 00067 m_textureID = 0; 00068 00069 // Handle tga textures 00070 if(stricmp(strrchr(filename.c_str(), '.'), ".tga") == 0) 00071 { 00072 CTga * Tga; 00073 Tga = new CTga(); 00074 if(Tga->ReadFile(filename.c_str()) == 0) 00075 { 00076 Tga->Release(); 00077 return; 00078 } 00079 00080 if(Tga->Bpp() != 32) 00081 { 00082 Tga->Release(); 00083 return; 00084 } 00085 00086 //Flip texture 00087 m_width = Tga->GetSizeX(); 00088 m_height = Tga->GetSizeY(); 00089 m_depth = Tga->Bpp() / 8; 00090 00091 char* texData = new char[m_width * m_height * m_depth]; 00092 00093 for(int y = 0; y < (int) m_height; ++y) 00094 { 00095 memcpy(&texData[y * m_width * m_depth], 00096 &((char*) Tga->GetPointer()) [(m_height - y - 1) * m_width * m_depth], m_width * m_depth); 00097 } 00098 00099 00100 glPixelStorei(GL_UNPACK_ALIGNMENT, 1); 00101 00102 glGenImages(1, &m_textureID); 00103 00104 glBindImage(GL_TEXTURE_2D, m_textureID); 00105 if(clamp) 00106 { 00107 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); 00108 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); 00109 00110 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 00111 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 00112 00113 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, m_width, m_height, 0, GL_RGBA , GL_UNSIGNED_BYTE, texData); 00114 } 00115 else 00116 { 00117 /* glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); 00118 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); 00119 00120 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_LINEAR); 00121 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 00122 00123 gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGBA, m_width, m_height, GL_RGBA, GL_UNSIGNED_BYTE, texData); 00124 */ 00125 glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); 00126 glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST); 00127 gluBuild2DMipmaps(GL_TEXTURE_2D, 4, m_width, m_height, GL_RGBA, GL_UNSIGNED_BYTE, texData); 00128 } 00129 00130 Tga->Release(); 00131 00132 delete[] texData; 00133 } 00134 } 00135 #endif // BLABLABLA

Generated on Sun Aug 15 19:19:22 2004 for OpenCAL: Open Computer Animation Library by doxygen 1.3.8