Lurking
12-12-2002, 05:10 PM
my tga loader isn't loading tga's! grrr... if you could take a look at my loader and spot any errors that i might have missed that would help me out alot. Thanx!
void tga: http://www.opengl.org/discussion_boards/ubb/biggrin.gifefine(){
glTexImage2D(GL_TEXTURE_2D,0,m_type,m_Width,m_Heig ht,0,GL_RGB,GL_UNSIGNED_BYTE,m_data);
}
void tga::GenerateID(){
glGenTextures(1,&m_textID);
}
void tga::Bind(){
glBindTexture(GL_TEXTURE_2D,m_textID);
}
void tga::Filter(){
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
}
bool tga::Load(char *filename){
fstream file;
long x = 0;
unsigned char rgbSwitch;
file.open(filename,ios::in | ios::binary);
if(!file.is_open()){
file.close();
return false;
}else{
file.seekg(2,ios::beg);
file.read((char*)&m_type,sizeof(unsigned char));
if((m_type != 2) | | (m_type != 3)){
file.close();
return false;
}else{
file.seekg(13,ios::cur);
file.read((char*)&m_Width,sizeof(short int));
file.read((char*)&m_Height,sizeof(short int));
file.read((char*)&m_bites,sizeof(unsigned char));
file.seekg(1,ios::cur);
m_channels = m_bites / 8;
m_size = m_Width * m_Height;
m_size *= m_channels;
m_data = new unsigned char[m_size];
file.read((char*)&m_data,sizeof(unsigned char));
while(x < m_size){
rgbSwitch = m_data[x];
m_data[x] = m_data[x + 2];
m_data[x + 2] = rgbSwitch;
x += m_channels;
}
file.close();
return true;
}
}
}
void tga: http://www.opengl.org/discussion_boards/ubb/biggrin.gifefine(){
glTexImage2D(GL_TEXTURE_2D,0,m_type,m_Width,m_Heig ht,0,GL_RGB,GL_UNSIGNED_BYTE,m_data);
}
void tga::GenerateID(){
glGenTextures(1,&m_textID);
}
void tga::Bind(){
glBindTexture(GL_TEXTURE_2D,m_textID);
}
void tga::Filter(){
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
}
bool tga::Load(char *filename){
fstream file;
long x = 0;
unsigned char rgbSwitch;
file.open(filename,ios::in | ios::binary);
if(!file.is_open()){
file.close();
return false;
}else{
file.seekg(2,ios::beg);
file.read((char*)&m_type,sizeof(unsigned char));
if((m_type != 2) | | (m_type != 3)){
file.close();
return false;
}else{
file.seekg(13,ios::cur);
file.read((char*)&m_Width,sizeof(short int));
file.read((char*)&m_Height,sizeof(short int));
file.read((char*)&m_bites,sizeof(unsigned char));
file.seekg(1,ios::cur);
m_channels = m_bites / 8;
m_size = m_Width * m_Height;
m_size *= m_channels;
m_data = new unsigned char[m_size];
file.read((char*)&m_data,sizeof(unsigned char));
while(x < m_size){
rgbSwitch = m_data[x];
m_data[x] = m_data[x + 2];
m_data[x + 2] = rgbSwitch;
x += m_channels;
}
file.close();
return true;
}
}
}