-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtexture.cpp
More file actions
39 lines (28 loc) · 1.18 KB
/
Copy pathtexture.cpp
File metadata and controls
39 lines (28 loc) · 1.18 KB
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
#include "texture.hpp"
void Texture::makeTexture(const char* FilePath,GLuint gltexture)
{
FILE* TextureImage;
unsigned char* TextureData;
TextureImage=fopen(FilePath,"rb");
if( ! TextureImage ) {
printf("Cannot open file : %s\n", FilePath );
return;
}
unsigned char header[54];
fread(header,1,54,TextureImage); //read header
int width = *(int*)&(header[0x12]);
int height = *(int*)&(header[0x16]);
fseek ( TextureImage , 128 , SEEK_SET );
TextureData=(unsigned char *)malloc(width*height*3);
fread(TextureData,width*height,3,TextureImage);
fclose(TextureImage);
glBindTexture(GL_TEXTURE_2D,gltexture);
glPixelStorei(GL_UNPACK_ALIGNMENT,2);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR,GL_MODULATE);
glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_CLAMP_TO_EDGE);
glTexImage2D(GL_TEXTURE_2D,0,GL_RGB,width,height,0,GL_BGR,GL_UNSIGNED_BYTE,TextureData);
delete TextureData;
}