a2072e3088adddae7197cc5e8259206ce4f95e0e
[demo] / src / opengl / texture-gl.cc
1 #include <GL/glew.h>
2
3 #include "texture.h"
4 #include "opengl/texture-gl.h"
5
6 TextureGL::TextureGL()
7 {
8         w = 0;
9         h = 0;
10
11         pixels = 0;
12         tex = 0;
13 }
14
15 TextureGL::~TextureGL()
16 {
17         glDeleteTextures(1, &tex);
18 }
19
20 void TextureGL::update()
21 {
22         if(!tex) {
23                 glGenTextures(1, &tex);
24                 glBindTexture(GL_TEXTURE_2D, tex);
25                 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
26                 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
27         }
28         else {
29                 glBindTexture(GL_TEXTURE_2D, tex);
30         }
31
32         glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, w, h, 0, GL_RGB, GL_UNSIGNED_BYTE, pixels);
33         glGenerateMipmap(GL_TEXTURE_2D);
34 }
35
36
37 void TextureGL::bind()
38 {
39         glBindTexture(GL_TEXTURE_2D, tex);
40 }