summaryrefslogtreecommitdiff
path: root/image.cpp
blob: 9850a0bfd1a1ad508168c61fdb4e16e1aed8df57 (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_RGBA;
	}
}

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;
}