-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtexture.h
124 lines (103 loc) · 2.84 KB
/
texture.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
// -----------------------------------------------------------------
// Learning Team B
// Members:
// Adam LeMmon
// Faith Satterthwaite
// Tom Fletcher
// Justin Ball
// CS 4280 – 11:30 am
// Final Project
// Dr. Rague
// Due: 12/06/12
// Version: 2.4
// -----------------------------------------------------------------
// We made five major improvements to this game
// 1) New controls
// 2) Enemy attack
// 3) HUD (heads up display)
// 4) Enemy health bars
// 5) New Weapon
// -----------------------------------------------------------------
#ifndef __TEXTURE_H
#define __TEXTURE_H
#define WIN32_LEAN_AND_MEAN
#define WIN32_EXTRA_LEAN
/*
TEXTURE.H
The CTexture class
OpenGL Game Programming
Author: Kevin Hawkins
Date: 3/29/2001
Description: The CTexture class represents a single texture
object in the engine. To load a texture,
you only need to call the LoadTexture() function.
*/
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <gl/gl.h>
#include <gl/glu.h>
#define BITMAP_ID 0x4D42 // the universal bitmap ID
enum texTypes_t
{
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 CTexture
{
private:
long int scaledWidth;
long int scaledHeight;
unsigned char *palette;
unsigned char *LoadBitmapFile(char *filename, BITMAPINFOHEADER *bitmapInfoHeader);
unsigned char *LoadBitmapFileWithAlpha(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);
public:
texTypes_t textureType;
unsigned char tgaImageCode; // 0 = not TGA image, 2 = color, 3 = greyscale
int width;
int height;
int bitDepth;
unsigned int texID;
unsigned char *data;
CTexture() { data = NULL; palette = NULL; }
~CTexture() { Unload(); }
void LoadTexture(char *filename);
void Unload()
{
glDeleteTextures(1, &texID);
if (data != NULL)
free(data);
if (palette != NULL)
free(palette);
data = NULL;
palette = NULL;
}
};
#endif