2 * DrawExternalCandy.cxx
3 * Daniel Nelson - 10/13/0
5 * Copyright (C) 2000 Daniel Nelson
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 * Daniel Nelson - aluminumangel.org
25 * Draws everything dumb outside of the play area.
38 #include "Displayer.h"
39 #include "MetaState.h"
44 inline void Displayer::drawDigit ( GLfloat alpha
)
46 glColor4f(0.3f
, 0.3f
, 1.0f
, alpha
);
48 glBegin(GL_TRIANGLE_STRIP
);
50 glTexCoord2f(0.0f
, 1.0f
);
51 glVertex3f(-DC_CLOCK_DIGIT_LENGTH
, -DC_CLOCK_DIGIT_LENGTH
, 0.0f
);
52 glColor4f(0.5f
, 0.5f
, 1.0f
, alpha
);
53 glTexCoord2f(1.0f
, 1.0f
);
54 glVertex3f(DC_CLOCK_DIGIT_LENGTH
, -DC_CLOCK_DIGIT_LENGTH
, 0.0f
);
55 glColor4f(0.5f
, 0.5f
, 1.0f
, alpha
);
56 glTexCoord2f(0.0f
, 0.0f
);
57 glVertex3f(-DC_CLOCK_DIGIT_LENGTH
, DC_CLOCK_DIGIT_LENGTH
, 0.0f
);
58 glColor4f(1.0f
, 1.0f
, 1.0f
, alpha
);
59 glTexCoord2f(1.0f
, 0.0f
);
60 glVertex3f(DC_CLOCK_DIGIT_LENGTH
, DC_CLOCK_DIGIT_LENGTH
, 0.0f
);
65 inline void Displayer::drawLeftBar ( GLfloat b
, GLfloat t
, GLfloat color
[3] )
67 if (t
< DC_LOSEBAR_FADE_TEX_LENGTH
/ 2.0f
) return;
69 glBegin(GL_TRIANGLE_STRIP
);
72 glTexCoord2f(0.0f
, 0.0f
);
73 glVertex3f(-DC_LOSEBAR_LENGTH
/ 2.0f
, DC_LOSEBAR_HEIGHT
/ 2.0f
, 0.0f
);
74 glTexCoord2f(t
- (DC_LOSEBAR_FADE_TEX_LENGTH
/ 2.0f
), 0.0f
);
75 glVertex3f(b
- (DC_LOSEBAR_FADE_LENGTH
/ 2.0f
), DC_LOSEBAR_HEIGHT
/ 2,
77 glTexCoord2f(0.0f
, 1.0f
);
78 glVertex3f(-DC_LOSEBAR_LENGTH
/ 2.0f
, -DC_LOSEBAR_HEIGHT
/ 2.0f
, 0.0f
);
79 glTexCoord2f(t
- (DC_LOSEBAR_FADE_TEX_LENGTH
/ 2.0f
), 1.0f
);
80 glVertex3f(b
- (DC_LOSEBAR_FADE_LENGTH
/ 2.0f
), -DC_LOSEBAR_HEIGHT
/ 2.0f
,
86 inline void Displayer::drawRightBar ( GLfloat b
, GLfloat t
, GLfloat color
[3] )
88 if (t
> 1.0f
- DC_LOSEBAR_FADE_TEX_LENGTH
/ 2.0f
) return;
90 glBegin(GL_TRIANGLE_STRIP
);
93 glTexCoord2f(t
+ (DC_LOSEBAR_FADE_TEX_LENGTH
/ 2.0f
), 0.0f
);
94 glVertex3f(b
+ (DC_LOSEBAR_FADE_LENGTH
/ 2.0f
), DC_LOSEBAR_HEIGHT
/ 2.0f
,
96 glTexCoord2f(1.0f
, 0.0f
);
97 glVertex3f(DC_LOSEBAR_LENGTH
/ 2.0f
, DC_LOSEBAR_HEIGHT
/ 2.0f
, 0.0f
);
98 glTexCoord2f(t
+ (DC_LOSEBAR_FADE_TEX_LENGTH
/ 2.0f
), 1.0f
);
99 glVertex3f(b
+ (DC_LOSEBAR_FADE_LENGTH
/ 2.0f
), -DC_LOSEBAR_HEIGHT
/ 2.0f
,
101 glTexCoord2f(1.0f
, 1.0f
);
102 glVertex3f(DC_LOSEBAR_LENGTH
/ 2.0f
, -DC_LOSEBAR_HEIGHT
/ 2.0f
, 0.0f
);
107 inline void Displayer::drawCenterBar ( GLfloat b
, GLfloat t
, GLfloat color1
[3],
110 glBegin(GL_TRIANGLE_STRIP
);
113 glTexCoord2f(t
- (DC_LOSEBAR_FADE_TEX_LENGTH
/ 2.0f
), 0.0f
);
114 glVertex3f(b
- (DC_LOSEBAR_FADE_LENGTH
/ 2.0f
), DC_LOSEBAR_HEIGHT
/ 2.0f
,
117 glTexCoord2f(t
+ (DC_LOSEBAR_FADE_TEX_LENGTH
/ 2.0f
), 0.0f
);
118 glVertex3f(b
+ (DC_LOSEBAR_FADE_LENGTH
/ 2.0f
), DC_LOSEBAR_HEIGHT
/ 2.0f
,
121 glTexCoord2f(t
- (DC_LOSEBAR_FADE_TEX_LENGTH
/ 2.0f
), 1.0f
);
122 glVertex3f(b
- (DC_LOSEBAR_FADE_LENGTH
/ 2.0f
), -DC_LOSEBAR_HEIGHT
/ 2.0f
,
125 glTexCoord2f(t
+ (DC_LOSEBAR_FADE_TEX_LENGTH
/ 2.0f
), 1.0f
);
126 glVertex3f(b
+ (DC_LOSEBAR_FADE_LENGTH
/ 2.0f
), -DC_LOSEBAR_HEIGHT
/ 2.0f
,
132 inline void Displayer::drawFullBar ( GLfloat color
[3] )
134 glBegin(GL_TRIANGLE_STRIP
);
137 glTexCoord2f(0.0f
, 0.0f
);
138 glVertex3f(-DC_LOSEBAR_LENGTH
/ 2.0f
, DC_LOSEBAR_HEIGHT
/ 2.0f
, 0.0f
);
139 glTexCoord2f(1.0f
, 0.0f
);
140 glVertex3f(DC_LOSEBAR_LENGTH
/ 2.0f
, DC_LOSEBAR_HEIGHT
/ 2.0f
, 0.0f
);
141 glTexCoord2f(0.0f
, 1.0f
);
142 glVertex3f(-DC_LOSEBAR_LENGTH
/ 2.0f
, -DC_LOSEBAR_HEIGHT
/ 2.0f
, 0.0f
);
143 glTexCoord2f(1.0f
, 1.0f
);
144 glVertex3f(DC_LOSEBAR_LENGTH
/ 2.0f
, -DC_LOSEBAR_HEIGHT
/ 2.0f
, 0.0f
);
149 void Displayer::drawExternalCandy ( )
153 glTexEnvi(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_MODE
, GL_BLEND
);
155 GLfloat b
= (DC_LOSEBAR_LENGTH
+ DC_LOSEBAR_FADE_LENGTH
)
156 * (LoseBar::bar
- 0.5f
);
157 GLfloat t
= LoseBar::bar
* (1.0f
+ DC_LOSEBAR_FADE_TEX_LENGTH
)
158 - 0.5f
* DC_LOSEBAR_FADE_TEX_LENGTH
;
160 glBindTexture(GL_TEXTURE_2D
, losebar_texture
);
164 glTranslatef(DC_LEFT_EXTERNAL_CENTER
, DC_LOSEBAR_OFFSET_Y
,
165 DC_EXTERNAL_OFFSET_Z
);
167 GLfloat color1
[3], color2
[3];
170 switch (LoseBar::state
) {
172 color1
[0] = DC_LOSEBAR_INACTIVE_RED
;
173 color1
[1] = DC_LOSEBAR_INACTIVE_GREEN
;
174 color1
[2] = DC_LOSEBAR_INACTIVE_BLUE
;
180 color1
[0] = DC_LOSEBAR_LOW_ALERT_RED
;
181 color1
[1] = DC_LOSEBAR_LOW_ALERT_GREEN
;
182 color1
[2] = DC_LOSEBAR_LOW_ALERT_BLUE
;
184 color2
[0] = DC_LOSEBAR_INACTIVE_RED
;
185 color2
[1] = DC_LOSEBAR_INACTIVE_GREEN
;
186 color2
[2] = DC_LOSEBAR_INACTIVE_BLUE
;
188 drawLeftBar(b
, t
, color1
);
189 drawCenterBar(b
, t
, color1
, color2
);
190 drawRightBar(b
, t
, color2
);
194 color1
[0] = DC_LOSEBAR_HIGH_ALERT_RED
;
195 color1
[1] = DC_LOSEBAR_HIGH_ALERT_GREEN
;
196 color1
[2] = DC_LOSEBAR_HIGH_ALERT_BLUE
;
198 color2
[0] = DC_LOSEBAR_LOW_ALERT_RED
;
199 color2
[1] = DC_LOSEBAR_LOW_ALERT_GREEN
;
200 color2
[2] = DC_LOSEBAR_LOW_ALERT_BLUE
;
202 drawLeftBar(b
, t
, color1
);
203 drawCenterBar(b
, t
, color1
, color2
);
204 drawRightBar(b
, t
, color2
);
207 case LB_FADE_LOW_TO_INACTIVE
:
208 fade
= LoseBar::fade_timer
* (1.0f
/ (GLfloat
) DC_LOSEBAR_FADE_TIME
);
210 color1
[0] = DC_LOSEBAR_INACTIVE_RED
211 + fade
* (DC_LOSEBAR_LOW_ALERT_RED
- DC_LOSEBAR_INACTIVE_RED
);
212 color1
[1] = DC_LOSEBAR_INACTIVE_GREEN
213 + fade
* (DC_LOSEBAR_LOW_ALERT_GREEN
- DC_LOSEBAR_INACTIVE_GREEN
);
214 color1
[2] = DC_LOSEBAR_INACTIVE_BLUE
215 + fade
* (DC_LOSEBAR_LOW_ALERT_BLUE
- DC_LOSEBAR_INACTIVE_BLUE
);
217 color2
[0] = DC_LOSEBAR_INACTIVE_RED
;
218 color2
[1] = DC_LOSEBAR_INACTIVE_GREEN
;
219 color2
[2] = DC_LOSEBAR_INACTIVE_BLUE
;
221 drawLeftBar(b
, t
, color1
);
222 drawCenterBar(b
, t
, color1
, color2
);
223 drawRightBar(b
, t
, color2
);
226 case LB_FADE_HIGH_TO_INACTIVE
:
227 fade
= LoseBar::fade_timer
* (1.0f
/ (GLfloat
) DC_LOSEBAR_FADE_TIME
);
229 color1
[0] = DC_LOSEBAR_INACTIVE_RED
230 + fade
* (DC_LOSEBAR_HIGH_ALERT_RED
- DC_LOSEBAR_INACTIVE_RED
);
231 color1
[1] = DC_LOSEBAR_INACTIVE_GREEN
232 + fade
* (DC_LOSEBAR_HIGH_ALERT_GREEN
- DC_LOSEBAR_INACTIVE_GREEN
);
233 color1
[2] = DC_LOSEBAR_INACTIVE_BLUE
234 + fade
* (DC_LOSEBAR_HIGH_ALERT_BLUE
- DC_LOSEBAR_INACTIVE_BLUE
);
236 color2
[0] = DC_LOSEBAR_INACTIVE_RED
237 + fade
* (DC_LOSEBAR_LOW_ALERT_RED
- DC_LOSEBAR_INACTIVE_RED
);
238 color2
[1] = DC_LOSEBAR_INACTIVE_GREEN
239 + fade
* (DC_LOSEBAR_LOW_ALERT_GREEN
- DC_LOSEBAR_INACTIVE_GREEN
);
240 color2
[2] = DC_LOSEBAR_INACTIVE_BLUE
241 + fade
* (DC_LOSEBAR_LOW_ALERT_BLUE
- DC_LOSEBAR_INACTIVE_BLUE
);
243 drawLeftBar(b
, t
, color1
);
244 drawCenterBar(b
, t
, color1
, color2
);
245 drawRightBar(b
, t
, color2
);
248 case LB_FADE_RESET_HIGH
:
249 fade
= LoseBar::fade_timer
* (1.0f
/ (GLfloat
) DC_LOSEBAR_FADE_TIME
);
251 color1
[0] = DC_LOSEBAR_LOW_ALERT_RED
252 + fade
* (DC_LOSEBAR_HIGH_ALERT_RED
- DC_LOSEBAR_LOW_ALERT_RED
);
253 color1
[1] = DC_LOSEBAR_LOW_ALERT_GREEN
254 + fade
* (DC_LOSEBAR_HIGH_ALERT_GREEN
- DC_LOSEBAR_LOW_ALERT_GREEN
);
255 color1
[2] = DC_LOSEBAR_LOW_ALERT_BLUE
256 + fade
* (DC_LOSEBAR_HIGH_ALERT_BLUE
- DC_LOSEBAR_LOW_ALERT_BLUE
);
258 color2
[0] = DC_LOSEBAR_LOW_ALERT_RED
;
259 color2
[1] = DC_LOSEBAR_LOW_ALERT_GREEN
;
260 color2
[2] = DC_LOSEBAR_LOW_ALERT_BLUE
;
262 drawLeftBar(b
, t
, color1
);
263 drawCenterBar(b
, t
, color1
, color2
);
264 drawRightBar(b
, t
, color2
);
270 glTexEnvi(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_MODE
, GL_MODULATE
);
272 if ((!(MetaState::mode
& CM_REALLY_LOW_GRAPHICS
)) || (Game::state
& GS_PAUSED
) || (Game::state
& GS_WON
) || (Game::state
& GS_LOST
)) {
274 if (MetaState::mode
& (CM_SERVER
| CM_CLIENT
)) {
278 glTranslatef(DC_LEFT_EXTERNAL_CENTER
- DC_CLOCK_DIGIT_OFFSET
/ 2,
279 DC_CLOCK_OFFSET_Y
, DC_EXTERNAL_OFFSET_Z
);
281 glBindTexture(GL_TEXTURE_2D
, clock_digit_textures
[10]);
284 glTranslatef(DC_CLOCK_CENTER_OFFSET
/ 2.0f
285 + 3.0f
* DC_CLOCK_DIGIT_OFFSET
/ 2.0f
, 0.0f
, 0.0f
);
287 GLfloat alpha
= Clock::tick
* (1.0f
/ (GLfloat
) GC_STEPS_PER_SECOND
);
289 glBindTexture(GL_TEXTURE_2D
, clock_digit_textures
[Clock::digits
[0]]);
290 if (Clock::digits
[0] != Clock::previous_digits
[0]) {
292 glBindTexture(GL_TEXTURE_2D
,
293 clock_digit_textures
[Clock::previous_digits
[0]]);
294 drawDigit(1.0f
- alpha
);
295 texture_bound
= Clock::previous_digits
[0];
298 texture_bound
= Clock::digits
[0];
301 glTranslatef(-DC_CLOCK_DIGIT_OFFSET
, 0.0f
, 0.0f
);
303 if (Clock::digits
[1] != texture_bound
)
304 glBindTexture(GL_TEXTURE_2D
, clock_digit_textures
[Clock::digits
[1]]);
305 if (Clock::digits
[1] == Clock::previous_digits
[1]) {
307 texture_bound
= Clock::digits
[1];
310 glBindTexture(GL_TEXTURE_2D
,
311 clock_digit_textures
[Clock::previous_digits
[1]]);
312 drawDigit(1.0f
- alpha
);
313 texture_bound
= Clock::previous_digits
[1];
316 glTranslatef(-DC_CLOCK_DIGIT_OFFSET
- DC_CLOCK_CENTER_OFFSET
, 0.0f
, 0.0f
);
318 if (Clock::digits
[2] != texture_bound
)
319 glBindTexture(GL_TEXTURE_2D
, clock_digit_textures
[Clock::digits
[2]]);
320 if (Clock::digits
[2] == Clock::previous_digits
[2]) {
322 texture_bound
= Clock::digits
[2];
325 glBindTexture(GL_TEXTURE_2D
,
326 clock_digit_textures
[Clock::previous_digits
[2]]);
327 drawDigit(1.0f
- alpha
);
328 texture_bound
= Clock::previous_digits
[2];
331 if (Clock::digits
[3] || Clock::previous_digits
[3]) {
332 glTranslatef(-DC_CLOCK_DIGIT_OFFSET
, 0.0f
, 0.0f
);
334 if (Clock::digits
[3] == Clock::previous_digits
[3]) {
335 if (texture_bound
!= Clock::digits
[3])
336 glBindTexture(GL_TEXTURE_2D
,
337 clock_digit_textures
[Clock::digits
[3]]);
340 if (Clock::digits
[3]) {
341 if (texture_bound
!= Clock::digits
[3])
342 glBindTexture(GL_TEXTURE_2D
,
343 clock_digit_textures
[Clock::digits
[3]]);
345 texture_bound
= Clock::digits
[3];
347 if (Clock::previous_digits
[3]) {
348 if (texture_bound
!= Clock::previous_digits
[3])
349 glBindTexture(GL_TEXTURE_2D
,
350 clock_digit_textures
[Clock::previous_digits
[3]]);
351 drawDigit(1.0f
- alpha
);
363 glTranslatef(DC_LEFT_EXTERNAL_CENTER
+ ((Score::n_digits_displayed
- 1)
364 * DC_CLOCK_DIGIT_OFFSET
) / 2, DC_CLOCK_OFFSET_Y
, DC_EXTERNAL_OFFSET_Z
);
366 GLfloat alpha
= 1.0f
- (GLfloat
) Score::fade_timer
367 * Score::inverse_timer_start
;
369 glBindTexture(GL_TEXTURE_2D
,
370 clock_digit_textures
[Score::digits
[0]]);
371 texture_bound
= Score::digits
[0];
373 if (Score::fade_timer
&& Score::previous_digits
[0]
374 != Score::digits
[0]) {
375 glBindTexture(GL_TEXTURE_2D
,
376 clock_digit_textures
[Score::previous_digits
[0]]);
377 texture_bound
= Score::previous_digits
[0];
378 drawDigit(1.0f
- alpha
);
381 for (int n
= 1; n
< Score::n_digits_displayed
; n
++) {
382 glTranslatef(-DC_CLOCK_DIGIT_OFFSET
, 0.0f
, 0.0f
);
383 if (texture_bound
!= Score::digits
[n
]) {
384 glBindTexture(GL_TEXTURE_2D
, clock_digit_textures
[Score::digits
[n
]]);
385 texture_bound
= Score::digits
[n
];
387 if (Score::fade_timer
&& Score::previous_digits
[n
]
388 != Score::digits
[n
]) {
390 glBindTexture(GL_TEXTURE_2D
,
391 clock_digit_textures
[Score::previous_digits
[n
]]);
392 texture_bound
= Score::previous_digits
[n
];
393 drawDigit(1.0f
- alpha
);
401 glColor4f(1.0f
, 1.0f
, 1.0f
, 1.0f
);
407 glBindTexture(GL_TEXTURE_2D
, logo_texture
);
408 glCallList(logo_list
);
413 glBindTexture(GL_TEXTURE_2D
, name_texture
);
414 glTranslatef(DC_LEFT_EXTERNAL_CENTER
, DC_NAME_OFFSET_Y
,
415 DC_EXTERNAL_OFFSET_Z
);
416 glScalef(DC_NAME_SCALE
, DC_NAME_SCALE
, 1.0f
);
417 glCallList(message_2x1_list
);