automatic download of data files
[safbench] / digits.cpp
1 // License information.
2 // The Software "SAF BENCH" was written by Patrik.A, also known as Nitton Attiofyra
3 // on YouTube. (https://www.youtube.com/@NittonAttiofyra)
4
5 // The software is released in to the Public Domain and comes with no warranty and is used
6 // at your own risk!
7
8 #include <stdlib.h> // VS 2005 wont compile it if its noth placed here, need to investigate
9 #ifdef macintosh
10 #include <glut.h>
11 #include <gl.h>
12 #include <glu.h>
13 #else
14 #include <GL/glut.h>
15 #include <GL/gl.h>
16 #include <GL/glu.h>
17 #endif
18 #include <iostream>
19 #include "digits.h"
20 #include "bmp_alpha.h"
21 #include <stdio.h>
22
23 #define for if(0);else for      // C2374 VC6++ on Alpha bug
24
25 #ifdef _WIN32
26 #pragma warning( disable : 4305 )
27 #define for if(0);else for      // VC6++ on Alpha bug
28 #endif
29
30 int draw_fps[5];                                                // array that holds up to 5 digits that represents etch digit in the FPS number
31 int draw_score[8] = {                                   // array that holds up to 8 digits that represents etch digit in the Score number
32         0, 10, 10, 10,
33         10, 10, 10, 10
34 };
35 static GLuint textures_digits_1;                // Textures
36
37 // Load textures
38 void textures_digits()
39 {
40 #ifdef macintosh
41         textures_digits_1 = LoadTexture(":textures:menu:digits.bmp", 64, 64);
42 #else
43         textures_digits_1 = LoadTexture("textures/menu/digits.bmp", 64, 64);
44 #endif
45 }
46
47 // render fps counter on screen
48 void render_fps()
49 {
50         for (int i = 0; i < 5; ++i)
51         {
52                 glEnable(GL_BLEND);
53                 glBindTexture( GL_TEXTURE_2D, textures_digits_1 );
54                 glEnable(GL_TEXTURE_2D);
55                 glBegin(GL_QUADS);
56                 glNormal3f(0, 0, 1);
57                 glColor3f(1, 1, 1);
58
59                 switch(draw_fps[i])
60                 {
61                         // draw fps digit 0
62                 case 0:
63                         glTexCoord2f(0,-.25);glVertex3f(3 - i, 10, -20);        // Top Left
64                         glTexCoord2f(.25,-.25);glVertex3f(4 - i,10, -20);       // Top Right
65                         glTexCoord2f(.25,0);glVertex3f(4 - i, 11, -20);         // Bottom Rigth
66                         glTexCoord2f(0,0);glVertex3f(3 - i, 11, -20);           // Bottom Left
67                         break;
68                         // draw fps digit 1
69                 case 1:
70                         glTexCoord2f(.25,-.25);glVertex3f(3 - i, 10, -20);      // Top Left
71                         glTexCoord2f(.5,-.25);glVertex3f(4 - i,10, -20);        // Top Right
72                         glTexCoord2f(.5,0);glVertex3f(4 - i, 11, -20);          // Bottom Rigth
73                         glTexCoord2f(.25,0);glVertex3f(3 - i, 11, -20);         // Bottom Left
74                         break;
75                         // draw fps digit 2
76                 case 2:
77                         glTexCoord2f(.5,-.25);glVertex3f(3 - i, 10, -20);       // Top Left
78                         glTexCoord2f(.75,-.25);glVertex3f(4 - i,10, -20);       // Top Right
79                         glTexCoord2f(.75,0);glVertex3f(4 - i, 11, -20);         // Bottom Rigth
80                         glTexCoord2f(.5,0);glVertex3f(3 - i, 11, -20);          // Bottom Left
81                         break;
82                         // draw fps digit 3
83                 case 3:
84                         glTexCoord2f(.75,-.25);glVertex3f(3 - i, 10, -20);              // Top Left
85                         glTexCoord2f(1,-.25);glVertex3f(4 - i,10, -20); // Top Right
86                         glTexCoord2f(1,0);glVertex3f(4 - i, 11, -20);           // Bottom Rigth
87                         glTexCoord2f(.75,0);glVertex3f(3 - i, 11, -20);         // Bottom Left
88                         break;
89                         // draw fps digit 4
90                 case 4:
91                         glTexCoord2f(0,-.5);glVertex3f(3 - i, 10, -20);         // Top Left
92                         glTexCoord2f(.25,-.5);glVertex3f(4 - i,10, -20);        // Top Right
93                         glTexCoord2f(.25,-.25);glVertex3f(4 - i, 11, -20);      // Bottom Rigth
94                         glTexCoord2f(0,-.25);glVertex3f(3 - i, 11, -20);        // Bottom Left
95                         break;
96                         // draw fps digit 5
97                 case 5:
98                         glTexCoord2f(.25,-.5);glVertex3f(3 - i, 10, -20);       // Top Left
99                         glTexCoord2f(.5,-.5);glVertex3f(4 - i,10, -20);         // Top Right
100                         glTexCoord2f(.5,-.25);glVertex3f(4 - i, 11, -20);       // Bottom Rigth
101                         glTexCoord2f(.25,-.25);glVertex3f(3 - i, 11, -20);      // Bottom Left
102                         break;
103                         // draw fps digit 6
104                 case 6:
105                         glTexCoord2f(.5,-.5);glVertex3f(3 - i, 10, -20);        // Top Left
106                         glTexCoord2f(.75,-.5);glVertex3f(4 - i,10, -20);        // Top Right
107                         glTexCoord2f(.75,-.25);glVertex3f(4 - i, 11, -20);      // Bottom Rigth
108                         glTexCoord2f(.5,-.25);glVertex3f(3 - i, 11, -20);       // Bottom Left
109                         break;
110                         // draw fps digit 7
111                 case 7:
112                         glTexCoord2f(.75,-.5);glVertex3f(3 - i, 10, -20);       // Top Left
113                         glTexCoord2f(1,-.5);glVertex3f(4 - i,10, -20);          // Top Right
114                         glTexCoord2f(1,-.25);glVertex3f(4 - i, 11, -20);        // Bottom Rigth
115                         glTexCoord2f(.75,-.25);glVertex3f(3 - i, 11, -20);      // Bottom Left
116                         break;
117                         // draw fps digit 8
118                 case 8:
119                         glTexCoord2f(0,-.75);glVertex3f(3 - i, 10, -20);        // Top Left
120                         glTexCoord2f(.25,-.75);glVertex3f(4 - i,10, -20);       // Top Right
121                         glTexCoord2f(.25,-.5);glVertex3f(4 - i, 11, -20);       // Bottom Rigth
122                         glTexCoord2f(0,-.5);glVertex3f(3 - i, 11, -20);         // Bottom Left
123                         break;
124                         // draw fps digit 9
125                 case 9:
126                         glTexCoord2f(.25,-.75);glVertex3f(3 - i, 10, -20);      // Top Left
127                         glTexCoord2f(.5,-.75);glVertex3f(4 - i,10, -20);        // Top Right
128                         glTexCoord2f(.5,-.5);glVertex3f(4 - i, 11, -20);        // Bottom Rigth
129                         glTexCoord2f(.25,-.5);glVertex3f(3 - i, 11, -20);       // Bottom Left
130                         break;
131                 }
132                 glEnd();
133         }
134         // Draw the text "FPS" on screen
135         glBegin(GL_QUADS);
136         glNormal3f(0, 0, 1);
137         glColor3f(1, 1, 1);
138         glTexCoord2f(.5,-.75);glVertex3f(4 , 10, -20);  // Top Left
139         glTexCoord2f(1,-.75);glVertex3f(6 ,10, -20);    // Top Right
140         glTexCoord2f(1,-.5);glVertex3f(6 , 11, -20);    // Bottom Rigth
141         glTexCoord2f(.5,-.5);glVertex3f(4 , 11, -20);   // Bottom Left
142         glEnd();
143         glDisable(GL_BLEND);
144         // disable texture
145         glDisable(GL_TEXTURE_2D);
146 }
147
148 // render score counter on screen
149 void render_score()
150 {
151         for (int i = 0; i < 8; ++i)
152         {
153                 glEnable(GL_BLEND);
154                 glBindTexture( GL_TEXTURE_2D, textures_digits_1 );
155                 glEnable(GL_TEXTURE_2D);
156                 glBegin(GL_QUADS);
157                 glNormal3f(0, 0, 1);
158                 glColor3f(1, 1, 1);
159
160                 switch(draw_score[i])
161                 {
162                         // draw fps digit 0
163                 case 0:
164                         glTexCoord2f(0,-.25);glVertex3f(5 - i, -2, -12);        // Top Left
165                         glTexCoord2f(.25,-.25);glVertex3f(6 - i, -2, -12);      // Top Right
166                         glTexCoord2f(.25,0);glVertex3f(6 - i, -1, -12);         // Bottom Rigth
167                         glTexCoord2f(0,0);glVertex3f(5 - i, -1, -12);           // Bottom Left
168                         break;
169                         // draw fps digit 1
170                 case 1:
171                         glTexCoord2f(.25,-.25);glVertex3f(5 - i, -2, -12);      // Top Left
172                         glTexCoord2f(.5,-.25);glVertex3f(6 - i, -2, -12);       // Top Right
173                         glTexCoord2f(.5,0);glVertex3f(6 - i, -1, -12);          // Bottom Rigth
174                         glTexCoord2f(.25,0);glVertex3f(5 - i, -1, -12);         // Bottom Left
175                         break;
176                         // draw fps digit 2
177                 case 2:
178                         glTexCoord2f(.5,-.25);glVertex3f(5 - i, -2, -12);       // Top Left
179                         glTexCoord2f(.75,-.25);glVertex3f(6 - i, -2, -12);      // Top Right
180                         glTexCoord2f(.75,0);glVertex3f(6 - i, -1, -12);         // Bottom Rigth
181                         glTexCoord2f(.5,0);glVertex3f(5 - i, -1, -12);          // Bottom Left
182                         break;
183                         // draw fps digit 3
184                 case 3:
185                         glTexCoord2f(.75,-.25);glVertex3f(5 - i, -2, -12);      // Top Left
186                         glTexCoord2f(1,-.25);glVertex3f(6 - i, -2, -12);        // Top Right
187                         glTexCoord2f(1,0);glVertex3f(6 - i, -1, -12);           // Bottom Rigth
188                         glTexCoord2f(.75,0);glVertex3f(5 - i, -1, -12);         // Bottom Left
189                         break;
190                         // draw fps digit 4
191                 case 4:
192                         glTexCoord2f(0,-.5);glVertex3f(5 - i, -2, -12);         // Top Left
193                         glTexCoord2f(.25,-.5);glVertex3f(6 - i, -2, -12);       // Top Right
194                         glTexCoord2f(.25,-.25);glVertex3f(6 - i, -1, -12);      // Bottom Rigth
195                         glTexCoord2f(0,-.25);glVertex3f(5 - i, -1, -12);        // Bottom Left
196                         break;
197                         // draw fps digit 5
198                 case 5:
199                         glTexCoord2f(.25,-.5);glVertex3f(5 - i, -2, -12);       // Top Left
200                         glTexCoord2f(.5,-.5);glVertex3f(6 - i, -2, -12);        // Top Right
201                         glTexCoord2f(.5,-.25);glVertex3f(6 - i, -1, -12);       // Bottom Rigth
202                         glTexCoord2f(.25,-.25);glVertex3f(5 - i, -1, -12);      // Bottom Left
203                         break;
204                         // draw fps digit 6
205                 case 6:
206                         glTexCoord2f(.5,-.5);glVertex3f(5 - i, -2, -12);        // Top Left
207                         glTexCoord2f(.75,-.5);glVertex3f(6 - i, -2, -12);       // Top Right
208                         glTexCoord2f(.75,-.25);glVertex3f(6 - i, -1, -12);      // Bottom Rigth
209                         glTexCoord2f(.5,-.25);glVertex3f(5 - i, -1, -12);       // Bottom Left
210                         break;
211                         // draw fps digit 7
212                 case 7:
213                         glTexCoord2f(.75,-.5);glVertex3f(5 - i, -2, -12);       // Top Left
214                         glTexCoord2f(1,-.5);glVertex3f(6 - i, -2, -12);         // Top Right
215                         glTexCoord2f(1,-.25);glVertex3f(6 - i, -1, -12);        // Bottom Rigth
216                         glTexCoord2f(.75,-.25);glVertex3f(5 - i, -1, -12);      // Bottom Left
217                         break;
218                         // draw fps digit 8
219                 case 8:
220                         glTexCoord2f(0,-.75);glVertex3f(5 - i, -2, -12);        // Top Left
221                         glTexCoord2f(.25,-.75);glVertex3f(6 - i, -2, -12);      // Top Right
222                         glTexCoord2f(.25,-.5);glVertex3f(6 - i, -1, -12);       // Bottom Rigth
223                         glTexCoord2f(0,-.5);glVertex3f(5 - i, -1, -12);         // Bottom Left
224                         break;
225                         // draw fps digit 9
226                 case 9:
227                         glTexCoord2f(.25,-.75);glVertex3f(5 - i, -2, -12);      // Top Left
228                         glTexCoord2f(.5,-.75);glVertex3f(6 - i, -2, -12);       // Top Right
229                         glTexCoord2f(.5,-.5);glVertex3f(6 - i, -1, -12);        // Bottom Rigth
230                         glTexCoord2f(.25,-.5);glVertex3f(5 - i, -1, -12);       // Bottom Left
231                         break;
232                 }
233                 glEnd();
234                 glDisable(GL_BLEND);
235                 // disable texture
236                 glDisable(GL_TEXTURE_2D);
237         }
238 }