GLuint createTexture const char path std ifstream tex path std ostring

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
GLuint createTexture(const char *path) {
std::ifstream tex(path);
std::ostringstream oss;
oss << tex.rdbuf();
std::string str = oss.str();
const char* charStr = str.c_str();
tex.close();
int width = *(int*)&(charStr[0x12]);
int height = *(int*)&(charStr[0x16]);
int dataPos = *(int*)&(charStr[0x0A]);
dataPos = dataPos == 0 ? 54 : dataPos;
GLuint texName;
glGenTextures(1, &texName);
glBindTexture(GL_TEXTURE_2D, texName);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, charStr + dataPos);
glBindTexture(GL_TEXTURE_2D, 0);
return texName;
}