-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrawtexture.cpp
43 lines (33 loc) · 1.04 KB
/
rawtexture.cpp
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
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "rawtexture.h"
#include "msg.h"
#include "file.h"
RawTexture::RawTexture(const char *filename) {
if (!count) {
m_texturefile = new char[strlen(filename)];
strcpy(m_texturefile, filename);
genTO();
}
count++;
}
RawTexture::~RawTexture() {
if (!--count)
freeTO();
}
void RawTexture::genTO() {
glGenTextures(1, &TO);
glBindTexture(GL_TEXTURE_2D, TO);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
#define height 512
#define width 512
char *tex_buf;
tex_buf = File::readFile(m_texturefile);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, height, width, 0, GL_RGB, GL_UNSIGNED_BYTE, tex_buf);
//glGenerateMipmap(GL_TEXTURE_2D);
delete [] tex_buf;
}