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
|
void Texture::RenderSection(GLfloat x, GLfloat y, Rectangle* _rect, GLfloat scaleX /* = 1 */, GLfloat scaleY /* = 1 */, GLfloat _rotation /* = 0 */, GLfloat _red /* = 1 */, GLfloat _green /* = 1 */, GLfloat _blue /* = 1 */, GLfloat _alpha /* = 1 */)
{
glPushMatrix();
//bind texture
glBindTexture(GL_TEXTURE_2D, m_Texture);
glTranslatef(x, y, 0.0f);
if(Rotation != 0)
{
GLfloat x, y;
x = ((rect->right - rect->left)/2) * m_Width;
y = ((rect->top - rect->bottom)/2) * m_Height;
glTranslatef(x ,y, 0.0f);
glRotatef(Rotation,0.0f,0.0f,1.0f);
glTranslatef(-x ,-y, 0.0f);
}
glScalef(scaleX, scaleY, 0);
//width for drawing
int32 box_width = ceil(m_Width * (_rect->right - _rect->left));
int32 box_height = ceil(m_Height * ( _rect->bottom - _rect->top ));
GLfloat box_top = 1.0f - _rect->top;
GLfloat box_bottom = 1.0f - _rect->bottom;
//draw the quad
glBegin(GL_QUADS);
//bottom-left vertex (corner)
glColor4f(_red, _green, _blue, _alpha);
glTexCoord2f(_rect->left, box_top);
glVertex2f(0, 0);
//bottom-right vertex (corner)
glTexCoord2f(_rect->right , box_top);
glVertex2f((GLfloat)box_width, 0);
//top-right vertex (corner)
glTexCoord2f(_rect->right , box_bottom);
glVertex2f((GLfloat)box_width, (GLfloat)box_height);
//top-left vertex (corner)
glTexCoord2f(_rect->left , box_bottom);
glVertex2f(0, (GLfloat)box_height);
glEnd();
//reset the color
glColor3f(1.0f, 1.0f, 1.0f);
glPopMatrix();
}
|