Main Page Namespace List Class Hierarchy Alphabetical List Data Structures File List Namespace Members Data Fields Globals

# ExCTexture.cpp

Go to the documentation of this file.

    00001 /*
    00002  * ExNihilo 3D Engine
    00003  *
    00004  *  This program is free software; you can redistribute it and/or modify
    00005  *  it under the terms of the GNU General Public License as published by
    00006  *  the Free Software Foundation; either version 2 of the License, or
    00007  *  (at your option) any later version.
    00008  *
    00009  *  This program is distributed in the hope that it will be useful,
    00010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
    00011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    00012  *  GNU Library General Public License for more details.
    00013  *
    00014  *  You should have received a copy of the GNU General Public License
    00015  *  along with this program; if not, write to the Free Software
    00016  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
    00017  *
    00018  * Please read AUTHORS file !!!
    00019  *
    00020  * $Id: ExCTexture.cpp,v 1.16 2002/11/24 11:59:01 data Exp $
    00021  *
    00022  */
    00023
    00024 #include "ExCTexture.h"
    00025
    00026
    00027 ExCTexture::ExCTexture(void)
    00028 {
    00029 Guard(ExCTexture::ExCTexture(void))
    00030         SetName("ExCTexture");
    00031         SetType(typeid(this).name());
    00032 UnGuard
    00033 }
    00034
    00035 ExCTexture::ExCTexture(std::string FileName)
    00036 {
    00037 Guard(ExCTexture::ExCTexture(std::string FileName))
    00038         SetName("ExCTexture");
    00039         SetType(typeid(this).name());
    00040         LoadFile(FileName);
    00041 UnGuard
    00042 }
    00043
    00044 ExCTexture::~ExCTexture(void)
    00045 {
    00046 Guard(ExCTexture::~ExCTexture(void))
    00047 UnGuard
    00048 }
    00049
    00050 void ExCTexture::SetName(std::string     Name)
    00051 {
    00052 Guard(void ExCTexture::SetName(std::string       Name))
    00053         if(Name.find(".")<Name.length())//if extension remove them
    00054         {
    00055                 Name.erase(Name.find("."),Name.length()-Name.find("."));
    00056                 m_ObjectName=Name;
    00057         }else
    00058         {
    00059                 m_ObjectName=Name;
    00060         }
    00061 UnGuard
    00062 }
    00063
    00064 void ExCTexture::SetActive(void)
    00065 {
    00066 Guard(ExCTexture::SetActive(void))
    00067
    00068         glBindTexture(GL_TEXTURE_2D,m_Texture);
    00069 UnGuard
    00070 }
    00071
    00072
    00073 bool ExCTexture::LoadFile(std::string FileName)
    00074 {
    00075 Guard(ExCTexture::LoadFile(std::string FileName))
    00076         m_Image= new ExCImageLoader;
    00077         int Type = GL_RGB;
    00078         std::string             StrPath;
    00079         SetName(FileName);
    00080         #ifdef UNIX_SRC
    00081                 StrPath=PREFIX "/ExNihilo/Data/Textures/";
    00082         #else
    00083                 StrPath="../Data/Textures/";
    00084         #endif
    00085
    00086         if(m_Image->LoadImage(StrPath+FileName))
    00087         {
    00088
    00089                 SetName(FileName);
    00090                 glGenTextures(1,&m_Texture);
    00091                 glBindTexture(GL_TEXTURE_2D,m_Texture);
    00092                 glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_REPEAT);
    00093                 glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_REPEAT);
    00094                 glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
    00095                 glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
    00096                 //std::cout<<"Tex ID :"<<m_Texture<<std::endl;
    00097                 switch (m_Image->m_TextureType)
    00098                 {
    00099                 case BMP:
    00100                         gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGB, m_Image->m_sizeX, m_Image->m_sizeY,
    00101                                 GL_RGB, GL_UNSIGNED_BYTE, m_Image->m_data);
    00102                         //glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, m_Image->m_sizeX,m_Image->m_sizeY,
    00103                         //      0, GL_RGB, GL_UNSIGNED_BYTE, m_Image->m_data);
    00104
    00105                         break;
    00106                 case PCX:
    00107                         gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGBA, m_Image->m_sizeX,m_Image->m_sizeY,
    00108                                 GL_RGBA, GL_UNSIGNED_BYTE, m_Image->m_data);
    00109                         break;
    00110                 case TGA:
    00111
    00112             if(m_Image->m_channels == 4)Type = GL_RGBA;
    00113                     gluBuild2DMipmaps(GL_TEXTURE_2D,m_Image->m_channels,m_Image->m_sizeX,
    00114                                           m_Image->m_sizeY, Type, GL_UNSIGNED_BYTE,m_Image->m_data);
    00115             break;
    00116                 case PPM:
    00117                         gluBuild2DMipmaps(GL_TEXTURE_2D, 3, m_Image->m_sizeX, m_Image->m_sizeY,
    00118                                 GL_RGB, GL_UNSIGNED_BYTE, m_Image->m_data);
    00119                         break;
    00120                 default:
    00121                         break;
    00122                 }
    00123                 return true;
    00124         }
    00125
    00126         *Consol<<"ExCTexture Exception::unable to load file "<<FileName<<std::endl;
    00127         delete m_Image;
    00128 return false;
    00129 UnGuard
    00130 }
    00131