/*
* Texture.h
* Jonathan Boldiga
* 09/03/03
*
* Description: The Texture class represents a single texture
* object in the engine. To load a texture,
* you only need to call the loadTexture() function.
*
*/
#ifndef __TEXTURE_H
#define __TEXTURE_H
#define WIN32_LEAN_AND_MEAN
#define WIN32_EXTRA_LEAN
#include
#include
#include
#include
#include
#include
#define BITMAP_ID 0x4D42 // the universal bitmap ID
enum TextureTypes{
PCX,
BMP,
TGA
};
// only partial pcx file header
typedef struct{
unsigned char manufacturer;
unsigned char version;
unsigned char encoding;
unsigned char bits;
unsigned char xMin;
unsigned char yMin;
unsigned char xMax;
unsigned char yMax;
unsigned char *palette;
} PCXHEADER;
typedef struct{
unsigned char imageTypeCode;
short int imageWidth;
short int imageHeight;
unsigned char bitCount;
} TGAHEADER;
class Texture{
private:
long int scaledWidth;
long int scaledHeight;
unsigned char* palette;
unsigned char* loadBitmapFile(char* filename, BITMAPINFOHEADER* bitmapInfoHeader);
unsigned char* loadPCXFile(char* filename, PCXHEADER* pcxHeader);
unsigned char* loadTGAFile(char* filename, TGAHEADER* tgaHeader);
void loadPCXTexture(char* filename);
void loadBMPTexture(char* filename);
void loadTGATexture(char* filename);
///////////////TO DO: ADD loadJPGTexture function////////////////////
public:
TextureTypes textureType;
unsigned char tgaImageCode; // 0 = not TGA image, 2 = color, 3 = greyscale
int width;
int height;
int bitDepth;
unsigned int textureID;
unsigned char* data;
Texture() { data = NULL; palette = NULL; }
~Texture(){ unload(); }
void loadTexture(char* filename);
void unload(){
glDeleteTextures(1, &textureID);
if (data != NULL)
free(data);
if (palette != NULL)
free(palette);
data = NULL;
palette = NULL;
}
};
#endif