00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
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())
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
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
00103
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