Original Post
I've been at this for a day and if I had any hair to loose I would have lost it by now :/
I want to use the C++ fstream functions to read in the header data of an uncompressed (and later compressed) targa file. I can't get the information to read into the struct that I've made however - I'm new to OpenGL programming and C++ BTW.
This is what I've written so far :
Header file
I've searched these forums and found quite a number of posts, a few of them involving the c++ manner of loading the textures but non of them went into the specifics I'm looking for.
[edited by - ChaosWars on April 3, 2004 12:56:32 PM]
#ifndef TARGA_H
#define TARGA_H
#include <GL/gl.h>
#include <fstream>
#include <iostream>
/*typedef struct
{
char idLength;
char colourMapType;
char imageType;
//colormapspecification:
short int firstEntry;
short int colorMapLength;
char colorMapEntrySize;
//image specification
short int xOrigin;
short int yOrigin;
short int imageWidth;
short int imageHeight;
char pixelDepth;
char imageDescriptor;
} TGAHeader;*/
class LoadTexture
{
public:
LoadTexture(){};
~LoadTexture(){};
typedef struct
{
GLbyte idLength;
GLbyte colourMapType;
GLbyte imageType;
GLbyte colorMapSpecification[5];
GLbyte imageSpecification[10];
} TGAHeader;
typedef struct
{
GLubyte *imageData;
GLint bitDepth;
GLint width;
GLint height;
GLint texID;
GLuint type;
} Texture;
TGAHeader tgaHeader;
Texture texture;
bool LoadTGATexture( char *, TGAHeader * );
//void LoadUncompressedTexture( TGAFile *, char *, std::ifstream * );
//void LoadCompressedTexture( TGAFile *, char *, std::ifstream * );
};
#endif //TARGA_H
cpp file
bool LoadTexture::LoadTGATexture( char *fileName, TGAHeader *tgaHeader )
{
std::ifstream 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.read( ( char * )tgaHeader, sizeof( GLbyte ) );
file.close();
return true;
}
How do I now read the information from the file stream I've opened into the struct tgaHeader? I am at a loss here