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
|
#include "../modules.h"
#if LIBJIN_MODULES_RENDER
#include <fstream>
#include "texture.h"
#include "../utils/utils.h"
#include "../Math/Math.h"
namespace jin
{
namespace graphics
{
using namespace jin::math;
/*static*/ Texture* Texture::createTexture(Bitmap* bitmap)
{
Texture* tex = new Texture();
const Color* pixels = bitmap->getPixels();
tex->size.w = bitmap->getWidth();
tex->size.h = bitmap->getHeight();
unsigned int w = tex->size.w;
unsigned int h = tex->size.h;
glGenTextures(1, &tex->texture);
glBindTexture(GL_TEXTURE_2D, tex->texture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
tex->vertCoord[0] = 0; tex->vertCoord[1] = 1;
tex->vertCoord[2] = 0; tex->vertCoord[3] = h;
tex->vertCoord[4] = w; tex->vertCoord[5] = h;
tex->vertCoord[6] = w; tex->vertCoord[7] = 1;
tex->textCoord[0] = 0; tex->textCoord[1] = 0;
tex->textCoord[2] = 0; tex->textCoord[3] = 1;
tex->textCoord[4] = 1; tex->textCoord[5] = 1;
tex->textCoord[6] = 1; tex->textCoord[7] = 0;
return tex;
}
Texture::Texture()
: Drawable()
{
}
Texture::~Texture()
{
}
} // graphics
} // jin
#endif // LIBJIN_MODULES_RENDER
|