-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathTexture.cpp
48 lines (36 loc) · 1.21 KB
/
Texture.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
44
45
46
#include "client.h"
#include "Texture.h"
int Texture::idgen = 1;
bool Texture::load( const char *path, bool multiply_color_by_alpha ){
if(image) {
print("Texture::load: Warning: image is already set. possible leak");
}
Image *img = new Image();
img->loadPNG(path, multiply_color_by_alpha );
setImage(img);
return true;
}
void Texture::setLinearMagFilter(){
glBindTexture( GL_TEXTURE_2D, tex );
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
}
void Texture::setLinearMinFilter(){
glBindTexture( GL_TEXTURE_2D, tex );
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
}
void Texture::setImage( Image *img ) {
if(tex==0){
glGenTextures( 1, &tex );
if(tex==0) {
GLenum e = glGetError();
print("glGetError fail: %d", e );
}
assertmsg(tex!=0,"glGenTexture failed");
glBindTexture( GL_TEXTURE_2D, tex );
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
}
glBindTexture(GL_TEXTURE_2D, tex );
glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, img->width, img->height, 0, GL_RGBA, GL_UNSIGNED_BYTE, img->buffer );
image = img;
}