-
Notifications
You must be signed in to change notification settings - Fork 0
/
cTexture.cpp
67 lines (55 loc) · 1.31 KB
/
cTexture.cpp
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
62
63
64
65
66
67
#include "cTexture.h"
#include "corona.h"
#include "Globals.h"
cTexture::cTexture(void)
{
}
cTexture::~cTexture(void)
{
}
bool cTexture::Load(char *filename,int type,int wraps,int wrapt,int magf,int minf,bool mipmap)
{
corona::Image* img;
int components;
img = corona::OpenImage(filename);
if(type==GL_RGB)
{
//img = corona::OpenImage(filename,corona::PF_R8G8B8);
components = 3;
}
else if(type==GL_RGBA)
{
//img = corona::OpenImage(filename,corona::PF_R8G8B8A8);
components = 4;
}
else return false;
if(img==NULL) return false;
width = img->getWidth();
height = img->getHeight();
glGenTextures(1, &id);
glBindTexture(GL_TEXTURE_2D,id);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,wraps);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,wrapt);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,magf);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,minf);
if(!mipmap)
{
glTexImage2D(GL_TEXTURE_2D,0,components,width,height,0,type,
GL_UNSIGNED_BYTE,img->getPixels());
}
else
{
gluBuild2DMipmaps(GL_TEXTURE_2D,components,width,height,type,
GL_UNSIGNED_BYTE,img->getPixels());
}
return true;
}
int cTexture::GetID()
{
return id;
}
void cTexture::GetSize(int *w,int *h)
{
*w = width;
*h = height;
}