Line data Source code
1 : #include <GL/glut.h>
2 : #include "SpriteGameObject.h"
3 : #include "constants.h"
4 : #include "api.h"
5 :
6 : //------------------------------------------------------------------------------
7 0 : SpriteGameObject::SpriteGameObject() : Object() {
8 0 : textureId = -1;
9 0 : }
10 :
11 : //------------------------------------------------------------------------------
12 0 : void SpriteGameObject::draw(Object* camera) {
13 0 : glPushMatrix();
14 0 : glColor3f(1.0f, 1.0f, 1.0f);
15 0 : glTranslatef(position_.x, position_.y, position_.z);
16 0 : glScalef(scale_.x, scale_.y, scale_.z);
17 :
18 0 : if (textureId >= 0) {
19 0 : glEnable(GL_BLEND);
20 0 : glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
21 0 : glEnable(GL_TEXTURE_2D);
22 0 : glBindTexture(GL_TEXTURE_2D, textureIds[textureId]);
23 0 : }
24 :
25 0 : glBegin(GL_QUADS);
26 0 : glTexCoord2f(0.0f, 1.0f);
27 0 : glVertex3f (-1.0f, -1.0f, 0.0f);
28 :
29 0 : glTexCoord2f(1.0f, 1.0f);
30 0 : glVertex3f (1.0f, -1.0f, 0.0f);
31 :
32 0 : glTexCoord2f(1.0f, 0.0f);
33 0 : glVertex3f (1.0f, 1.0f, 0.0f);
34 :
35 0 : glTexCoord2f(0.0f, 0.0f);
36 0 : glVertex3f (-1.0f, 1.0f, 0.0f);
37 0 : glEnd();
38 :
39 0 : glDisable(GL_TEXTURE_2D);
40 0 : glPopMatrix();
41 0 : }
42 :
43 : //------------------------------------------------------------------------------
44 0 : void SpriteGameObject::setTexture(const std::string &textureKey) {
45 0 : textureId = textureHash[textureKey];
46 0 : }
|