-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCTextureGL.cpp
More file actions
61 lines (48 loc) · 1.42 KB
/
CTextureGL.cpp
File metadata and controls
61 lines (48 loc) · 1.42 KB
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
#include "CTextureGL.h"
#ifdef ANDROID
#include <GLES2/gl2.h>
#include <GLES2/gl2ext.h>
#include <android/log.h>
#else
#include <GL/glew.h>
#ifdef __APPLE__
#include <OpenGL/glext.h>
#include <OpenGL/gl.h>
#else
#include <GL/glext.h> // used for GL_BGRA
#include <GL/gl.h>
#endif
#endif
CTextureGL::CTextureGL(){
init();
}
CTextureGL::CTextureGL(unsigned char* data_, int sizeX_, int sizeY_, int channels_){
init();
this->data = data_;
this->sizeX = sizeX_;
this->sizeY = sizeY_;
this->channels = channels_;
generateTexture();
}
CTextureGL::~CTextureGL(){
//delete [] data;
delete [] textureName;
}
void CTextureGL::generateTexture(){
if(!data){
cout << "CTextureGL::GenerateTexture(): No data has been assigned yet!" << endl;
return;
}
glGenTextures(1, &ID);
glBindTexture(GL_TEXTURE_2D, ID);
if (channels == 3)
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, sizeX, sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, data);
else if (channels == 4)
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, sizeX, sizeY, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
//delete [] data;
//data = NULL;
}