summaryrefslogtreecommitdiff
path: root/image.cpp
blob: a3d0d6acf9d1ef08ecbebf2ab285f28b126095f9 (plain)
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
#include "image.h"

#include "gl.h"

#include "stb_image.h"

Image::Image() {
	data = 0;
}

Image::Image(const std::string& filename) {
	load(filename);
}

Image::~Image() {
	if(data) {
		stbi_image_free(data);
	}
}

void Image::load(const std::string& filename) {
	int w, h, ch;
	data = stbi_load(filename.c_str(), &w, &h, &ch, 4);
	
	width = w;
	height = h;
	
	if(ch == 4) {
		format = GL_RGBA;
	} else {
		format = GL_RGB;
	}
}

unsigned int Image::w() const {
	return width;
}

unsigned int Image::h() const {
	return height;
}

unsigned int Image::f() const {
	return format;
}

const void* Image::d() const {
	return data;
}