Erm...
After struggling for a day to get my program to read filestreams using c++ fstream it now works. Well, sort of - like the title of the thread says, it insists in reading the file in sodding octal. How in the name of all that's holy did that happen? I thought it defaulted to binary? here's the code and a link to the program - note that you'll need Qt installed to run it. It was written in Linux if that makes a difference...
Header file
#ifndef TARGA_H
#define TARGA_H
#include <GL/gl.h>
#include <fstream>
#include <iostream>
class LoadTexture
{
public:
LoadTexture(){}
~LoadTexture(){ /*delete[] textureArray;*/ }
/*typedef struct
{
GLubyte idLength;
GLubyte colourMapType;
GLubyte imageType;
//Color Map Specification:
//GLubyte firstEntryIndex1;
//GLubyte firstEntryIndex2;
GLubyte firstEntryIndex[2];
//GLubyte colorMapLength1;
//GLubyte colorMapLength2;
GLubyte colorMapLength[2];
GLubyte colorMapEntrySize;
//image specification
//GLubyte xOrigin1;
//GLubyte xOrigin2;
GLubyte xOrigin[2];
//GLubyte yOrigin1;
//GLubyte yOrigin2;
GLubyte yOrigin[2];
//GLubyte imageWidth1;
//GLubyte imageWidth2;
GLubyte imageWidth[2];
//GLubyte imageHeight1;
//GLubyte imageHeight2;
GLubyte imageHeight[2];
GLubyte pixelDepth;
GLubyte imageDescriptor;
} TGAHeader;*/
typedef struct
{
GLbyte idLength;
GLbyte colourMapType;
GLbyte imageType;
//Color Map Specification:
GLbyte firstEntryIndex[2]; //2
GLbyte colorMapLength[2]; //2
GLbyte colorMapEntrySize;
//image specification
GLbyte xOrigin[2]; //2
GLbyte yOrigin[2]; //2
GLbyte imageWidth[2]; //2
GLbyte imageHeight[2]; //2
GLbyte pixelDepth;
GLbyte imageDescriptor;
} TGAHeader;
typedef struct
{
GLubyte *imageData;
GLint bitDepth;
GLint width;
GLint height;
GLint texID;
GLuint type;
} Texture;
TGAHeader tgaHeader;
Texture texture;
bool LoadTGATexture( char * );
void LoadUncompressedTexture( TGAHeader *, std::fstream * );
void LoadCompressedTexture( TGAHeader *, std::fstream * );
};
#endif //TARGA_H
Source file
#include "targa.h"
bool LoadTexture::LoadTGATexture( char *fileName )
{
std::fstream file;
file.open( fileName, std::ios::in | std::ios::binary );
if ( !file ){
printf( "Error : Could not open file %s\n", fileName );
return false;
}
else{
printf( "Opened file %s succesfully\n", fileName );
}
//file.seekg( 0, std::ios::beg );
file.read( ( char * )&tgaHeader, sizeof( tgaHeader ) );
if( ( tgaHeader.imageType = 2) ){
LoadUncompressedTexture( &tgaHeader, &file );
}
else if( ( tgaHeader.imageType = 10 ) ){
LoadCompressedTexture( &tgaHeader, &file );
}
file.close();
return true;
}
void LoadTexture::LoadUncompressedTexture( TGAHeader *tgaHeader, std::fstream *file )
{
printf( "Loading uncompressed tga image\n" );
}
void LoadTexture::LoadCompressedTexture( TGAHeader *tgaHeader, std::fstream *file )
{
printf( "Loading compressed tga image\n" );
}
http://www.warmachine.demon.nl/seraphim.tar.gz
Help?
[edited by - ChaosWars on April 3, 2004 3:24:41 PM]