-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscoremodel.cpp
More file actions
executable file
·125 lines (108 loc) · 2.9 KB
/
scoremodel.cpp
File metadata and controls
executable file
·125 lines (108 loc) · 2.9 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/*
* Copyright (C) 2011-2012 Michal Hozza (mhozza@gmail.com)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "scoremodel.h"
#include "utils.h"
#include "game.h"
#include <string>
#include <sstream>
#include <iostream>
using namespace std;
ScoreModel::ScoreModel(int x, int y)
{
this->x = x;
this->y = y;
float width, height;
bool alpha;
GLubyte *img;
if(!Utils::loadPngImage("graphics/numbers.png",width,height,alpha,&img))
{
cerr << "Unable to load font: graphics/numbers.png" << endl;
}
//todo skontrolovat return val, rozmery
GLubyte font[10][192];
GLubyte bitmap[10][32];
for(int i = 0;i<10;i++)
{
for(int j=0;j<16;j++)
{
for(int k = 0;k<12;k++)
{
font[i][12*j+k] = *(img+((int)width*j+12*i+k)*4);
}
}
}
for(int i = 0;i<10;i++)
{
int k = 0;
for(int l = 0;l<32;l++)
{
GLubyte bt = 0;
for(int j = 0; j< 8;j++)
{
bt |= (1-(font[i][k] & 1)) << (7-j);
k++;
if(k%12 == 0) break;
}
bitmap[i][l] = bt;
}
}
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
fontOffset = glGenLists (10);
for (int i = 0; i<10; i++)
{
glNewList(fontOffset + i, GL_COMPILE);
//glColor3i(1,1,1);
glBitmap(12, 16, 0.0, 0.0, 15.0, 0.0, bitmap[i]);
glEndList();
}
scoreBytes = new GLubyte[1];
scoreBytes[0] = 0;
}
void ScoreModel::draw()
{
glDisable(GL_TEXTURE_2D);
glDisable(GL_FOG);
glDisable(GL_LIGHTING);
glColor3f(1,1,1);
glMatrixMode(GL_PROJECTION); // Budeme menit projekcnu maticu (transformaciu)
glPushMatrix();
glLoadIdentity(); // Vynulovanie
glOrtho (0.0, 800, 0.0, 600, -1.0, 1.0); // Rovnobezne pravouhle premietanie
glRasterPos2i(x, y);
glPushAttrib (GL_LIST_BIT);
glListBase(fontOffset);
glCallLists(score_sz, GL_UNSIGNED_BYTE, scoreBytes);
glPopAttrib();
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
glEnable(GL_TEXTURE_2D);
if(Game::fog)
glEnable(GL_FOG);
glEnable(GL_LIGHTING);
}
void ScoreModel::setScore(int score)
{
ostringstream s;
s << score;
delete this->scoreBytes;
score_sz = s.str().length();
this->scoreBytes = new GLubyte[score_sz];
for(int i = 0; i<score_sz;i++)
{
this->scoreBytes[i] = s.str()[i]-'0';
}
}