-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTextured.cpp
More file actions
64 lines (58 loc) · 1.64 KB
/
Copy pathTextured.cpp
File metadata and controls
64 lines (58 loc) · 1.64 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
62
63
64
#include "Textured.h"
Textured::Textured(){
this->x = 0;
this->y = 0;
this->w = 0;
this->h = 0;
this->r = 0;
};
Textured::~Textured(){};
void Textured::init(double x,double y,double w,double h,double r,char* imagePath){
this->x = x;
this->y = y;
this->w = w;
this->h = h;
this->r = r;
loadGLTextures(imagePath);
};
void Textured::update(double x,double y,double w,double h,double r){
this->x = x;
this->y = y;
this->w = w;
this->h = h;
this->r = r;
};
void Textured::loadGLTextures(char* imagePath){
vector<unsigned char> image;
unsigned width;
unsigned height;
decode(image,width,height,imagePath);
glGenTextures(2, &texture[0]);
glBindTexture(GL_TEXTURE_2D, texture[0]);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, &image[0]);
};
void Textured::render(){
glEnable(GL_TEXTURE_2D);
glPushMatrix();
glColor3f(1.0,1.0,1.0);
glBindTexture(GL_TEXTURE_2D,texture[0]);
glTranslatef(-x,-y,0);
glScalef(w,h,1);
glRotatef(r,0,0,1);
glRotatef(180,0,0,1);
glTranslatef(-0.5,-0.5,0);
glBegin(GL_QUADS);
glTexCoord2f(0,0);
glVertex2f(0,0);
glTexCoord2f(0,1);
glVertex2f(0,1);
glTexCoord2f(1,1);
glVertex2f(1,1);
glTexCoord2f(1,0);
glVertex2f(1,0);
glEnd();
glPopMatrix();
glDisable(GL_TEXTURE_2D);
};