-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbmp.cpp
More file actions
76 lines (60 loc) · 1.28 KB
/
Copy pathbmp.cpp
File metadata and controls
76 lines (60 loc) · 1.28 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
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
#include "bmp.h"
#include <cstdlib>
#include <iostream>
BMPLoader::BMPLoader()
{
image = 0;
imageWidth = 0;
imageHeight = 0;
}
BMPLoader::~BMPLoader()
{
//FreeImage();
}
void testLines()
{
}
/**void LoadTexture() {
tdogl::Bitmap bmp = tdogl::Bitmap::bitmapFromFile(ResourcePath("hazard.png"));
bmp.flipVertically();
gTexture = new tdogl::Texture(bmp);
}**/
bool BMPLoader::loadBMP(const char * file)
{
GLint totalBytes, lineBytes;
FILE *pFile = fopen(file, "rb");
if(!pFile)
{
//Include a debug statement here
return false;
}
fseek(pFile, 0x0012, SEEK_SET);
fread(&imageWidth, 4, 1, pFile);
fread(&imageHeight, 4, 1, pFile);
fseek(pFile, 54, SEEK_SET);
lineBytes = imageWidth*3;
while(lineBytes%4 != 0)
lineBytes++;
totalBytes = lineBytes * imageHeight;
image = new GLubyte[totalBytes];
fread(image, totalBytes, 1, pFile);
/*if (fread(image, totalBytes, 1, pFile) <= 0)
{
delete image;
fclose(pFile);
return 0;
}*/
//std::cout<<val<<" "<<file[1];
//for(int i=0; i<totalBytes; i++)
// std::cout<<image[i]<<" ";
//Do error checking here
char textureColors;
for(int index=0; index<totalBytes; index+=3)
{
textureColors = image[index];
image[index] = image[index+2];
image[index+2] = textureColors;
}
fclose(pFile);
return true;
}