forked from Illiux/Diabolical-Fuckup
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtexture.cpp
67 lines (57 loc) · 1.17 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include "texture.h"
#include "GL/glpng.h"
bool Texture::isValid()
{
bool valid = true;
if (texture==-1)
valid = false;
return valid;
}
int Texture::getWidth()
{
return width;
}
int Texture::getHeight()
{
return height;
}
void Texture::bind()
{
glBindTexture( GL_TEXTURE_2D, texture);
}
// For creating invalid placeholder textures
Texture::Texture()
{
height = 0;
width = 0;
texture = -1;
}
Texture::Texture(std::string filename)
{
pngInfo* info = new pngInfo;
texture = pngBind(filename.c_str(), PNG_NOMIPMAP, PNG_ALPHA, info,GL_REPEAT,GL_LINEAR,GL_LINEAR);
if (texture==0) {
texture=-1;
height=0;
width=0;
} else {
height = info->Height;
width = info->Width;
}
}
SDL_Surface *Texture::loadImage(std::string filename){
SDL_Surface* any_image = NULL;
//optimized image that will be used
SDL_Surface* optimizedimage = NULL;
//load image
any_image = IMG_Load(filename.c_str());
if (any_image != NULL){
//create an optimized image
optimizedimage = SDL_DisplayFormat(any_image);
//free the old image
SDL_FreeSurface (any_image);
}
//optimizedimage = zoomSurface(optimizedimage,.5,.5,.5);
//return the optimized image
return optimizedimage;
}