-
Notifications
You must be signed in to change notification settings - Fork 0
/
Texture.cpp
132 lines (92 loc) · 2.97 KB
/
Texture.cpp
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
125
126
127
128
129
130
131
132
/*-----------------------------------------------------------------------------
Texture.cpp
2006 Shamus Young
-------------------------------------------------------------------------------
This loads in textures. Nothin' fancy.
-----------------------------------------------------------------------------*/
#define MAX_STRING 128
#include "precompiled.h"
struct texture {
struct texture* next;
GLuint id;
char name[16];
char* image_name;
char* mask_name;
AUX_RGBImageRec* image;
};
static struct texture* head_texture;
/*-----------------------------------------------------------------------------
-----------------------------------------------------------------------------*/
static AUX_RGBImageRec* LoadBMP ( char *Filename )
{
FILE* File = NULL;
if ( !Filename )
return NULL;
//I hope I don't borked it...
fopen_s(&File, Filename, "r" );
if ( File ) {
fclose( File );
return auxDIBImageLoad( Filename );
}
return NULL;
}
/*-----------------------------------------------------------------------------
t e x t u r e i d
-----------------------------------------------------------------------------*/
static struct texture* LoadTexture ( char* name ) {
char filename[MAX_STRING];
struct texture* t;
t = new struct texture;
strcpy_s ( t->name, name );
sprintf_s ( filename, "textures/%s.bmp", name );
t->image = LoadBMP ( filename );
if ( !t->image ) {
t->id = 0;
return t;
}
glGenTextures ( 1, &t->id ); // Create The Texture
// Typical Texture Generation Using Data From The Bitmap
glBindTexture ( GL_TEXTURE_2D, t -> id );
// Generate The Texture
glTexImage2D ( GL_TEXTURE_2D, 0, 3,
t -> image->sizeX,
t -> image->sizeY,
0, GL_RGB, GL_UNSIGNED_BYTE,
t -> image->data );
free ( t -> image );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR ); // Linear Filtering
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); // Linear Filtering
t -> next = head_texture;
head_texture = t;
return t;
}
/*-----------------------------------------------------------------------------
-----------------------------------------------------------------------------*/
unsigned TextureFromName ( char* name )
{
struct texture* t;
for ( t = head_texture; t; t = t -> next ) {
if ( !_stricmp ( name, t -> name ) )
return t -> id;
}
t = LoadTexture ( name );
if ( t )
return t->id;
return 0;
}
/*-----------------------------------------------------------------------------
-----------------------------------------------------------------------------*/
void TextureInit ( void )
{
}
/*-----------------------------------------------------------------------------
-----------------------------------------------------------------------------*/
void TextureTerm ( void )
{
struct texture* t;
while ( head_texture ) {
t = head_texture->next;
free ( head_texture );
head_texture = t;
}
}