-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTextureLoader.h
More file actions
45 lines (38 loc) · 1000 Bytes
/
Copy pathTextureLoader.h
File metadata and controls
45 lines (38 loc) · 1000 Bytes
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
#ifndef TEXTURE_LOADER_H
#define TEXTURE_LOADER_H
#include<iostream>
#include<fstream>
#include <string>
#include<vector>
#include<stdio.h>
#include <stdlib.h>
class TextureLoader
{
FILE* pFile;
long lSize;
char* buffer;
size_t result;
public:
int width,height,nrChannels;
char* data;
TextureLoader(std::string file, std::string name);
};
TextureLoader::TextureLoader(std::string file, std::string name)
{
pFile = fopen(file.c_str(), "rb");
if (pFile == NULL) { fputs("File error", stderr); exit(1); }
fseek(pFile, 0, SEEK_END);
lSize = ftell(pFile);
rewind(pFile);
buffer = (char*)malloc(sizeof(char) * lSize);
if (buffer == NULL) { fputs("Memory error", stderr); exit(2); }
result = fread(buffer, 1, lSize, pFile);
data = buffer;
for (size_t i = 0; i < 7; i++)
{
memmove(&data[i], &data[i + 1], strlen(data) - i);
}
if (result != lSize) { fputs("Reading error", stderr); exit(3); }
fclose(pFile);
}
#endif