0
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 "stdafx.h"
#include "Image.h"
Image::Image( char* file, int width, int height ){
this->width = width;
this->height = height;
data = new GLubyte[height*width*4];
FILE *fp;
int x, y;
if( ( fp = fopen( file, "rb" ) ) == NULL ){
fprintf( stderr, "texture file cannot open\n" );
return;
}
fseek(fp, 18, SEEK_SET);
for( y = 0; y < height; y++ ){
for( x = 0; x < width; x++ ){
data[(x+y*width)*4+2] = fgetc(fp);
data[(x+y*width)*4+1] = fgetc(fp);
data[(x+y*width)*4] = fgetc(fp);
data[(x+y*width)*4+3] = fgetc(fp);
}
}
fclose(fp);
}
Image::~Image(){
delete []this->data;
this->data = 0;
}
|