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.
33 #include "Displayer.h"
34 #include "MetaState.h"
39 inline void Displayer::drawDigit ( GLfloat alpha
)
41 glColor4f(0.3f
, 0.3f
, 1.0f
, alpha
);
43 glBegin(GL_TRIANGLE_STRIP
);
45 glTexCoord2f(0.0f
, 1.0f
);
46 glVertex3f(-DC_CLOCK_DIGIT_LENGTH
, -DC_CLOCK_DIGIT_LENGTH
, 0.0f
);
47 glColor4f(0.5f
, 0.5f
, 1.0f
, alpha
);
48 glTexCoord2f(1.0f
, 1.0f
);
49 glVertex3f(DC_CLOCK_DIGIT_LENGTH
, -DC_CLOCK_DIGIT_LENGTH
, 0.0f
);
50 glColor4f(0.5f
, 0.5f
, 1.0f
, alpha
);
51 glTexCoord2f(0.0f
, 0.0f
);
52 glVertex3f(-DC_CLOCK_DIGIT_LENGTH
, DC_CLOCK_DIGIT_LENGTH
, 0.0f
);
53 glColor4f(1.0f
, 1.0f
, 1.0f
, alpha
);
54 glTexCoord2f(1.0f
, 0.0f
);
55 glVertex3f(DC_CLOCK_DIGIT_LENGTH
, DC_CLOCK_DIGIT_LENGTH
, 0.0f
);
60 inline void Displayer::drawLeftBar ( GLfloat b
, GLfloat t
, GLfloat color
[3] )
62 if (t
< DC_LOSEBAR_FADE_TEX_LENGTH
/ 2.0f
) return;
64 glBegin(GL_TRIANGLE_STRIP
);
67 glTexCoord2f(0.0f
, 0.0f
);
68 glVertex3f(-DC_LOSEBAR_LENGTH
/ 2.0f
, DC_LOSEBAR_HEIGHT
/ 2.0f
, 0.0f
);
69 glTexCoord2f(t
- (DC_LOSEBAR_FADE_TEX_LENGTH
/ 2.0f
), 0.0f
);
70 glVertex3f(b
- (DC_LOSEBAR_FADE_LENGTH
/ 2.0f
), DC_LOSEBAR_HEIGHT
/ 2,
72 glTexCoord2f(0.0f
, 1.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
), 1.0f
);
75 glVertex3f(b
- (DC_LOSEBAR_FADE_LENGTH
/ 2.0f
), -DC_LOSEBAR_HEIGHT
/ 2.0f
,
81 inline void Displayer::drawRightBar ( GLfloat b
, GLfloat t
, GLfloat color
[3] )
83 if (t
> 1.0f
- DC_LOSEBAR_FADE_TEX_LENGTH
/ 2.0f
) return;
85 glBegin(GL_TRIANGLE_STRIP
);
88 glTexCoord2f(t
+ (DC_LOSEBAR_FADE_TEX_LENGTH
/ 2.0f
), 0.0f
);
89 glVertex3f(b
+ (DC_LOSEBAR_FADE_LENGTH
/ 2.0f
), DC_LOSEBAR_HEIGHT
/ 2.0f
,
91 glTexCoord2f(1.0f
, 0.0f
);
92 glVertex3f(DC_LOSEBAR_LENGTH
/ 2.0f
, DC_LOSEBAR_HEIGHT
/ 2.0f
, 0.0f
);
93 glTexCoord2f(t
+ (DC_LOSEBAR_FADE_TEX_LENGTH
/ 2.0f
), 1.0f
);
94 glVertex3f(b
+ (DC_LOSEBAR_FADE_LENGTH
/ 2.0f
), -DC_LOSEBAR_HEIGHT
/ 2.0f
,
96 glTexCoord2f(1.0f
, 1.0f
);
97 glVertex3f(DC_LOSEBAR_LENGTH
/ 2.0f
, -DC_LOSEBAR_HEIGHT
/ 2.0f
, 0.0f
);
102 inline void Displayer::drawCenterBar ( GLfloat b
, GLfloat t
, GLfloat color1
[3],
105 glBegin(GL_TRIANGLE_STRIP
);
108 glTexCoord2f(t
- (DC_LOSEBAR_FADE_TEX_LENGTH
/ 2.0f
), 0.0f
);
109 glVertex3f(b
- (DC_LOSEBAR_FADE_LENGTH
/ 2.0f
), DC_LOSEBAR_HEIGHT
/ 2.0f
,
112 glTexCoord2f(t
+ (DC_LOSEBAR_FADE_TEX_LENGTH
/ 2.0f
), 0.0f
);
113 glVertex3f(b
+ (DC_LOSEBAR_FADE_LENGTH
/ 2.0f
), DC_LOSEBAR_HEIGHT
/ 2.0f
,
116 glTexCoord2f(t
- (DC_LOSEBAR_FADE_TEX_LENGTH
/ 2.0f
), 1.0f
);
117 glVertex3f(b
- (DC_LOSEBAR_FADE_LENGTH
/ 2.0f
), -DC_LOSEBAR_HEIGHT
/ 2.0f
,
120 glTexCoord2f(t
+ (DC_LOSEBAR_FADE_TEX_LENGTH
/ 2.0f
), 1.0f
);
121 glVertex3f(b
+ (DC_LOSEBAR_FADE_LENGTH
/ 2.0f
), -DC_LOSEBAR_HEIGHT
/ 2.0f
,
127 inline void Displayer::drawFullBar ( GLfloat color
[3] )
129 glBegin(GL_TRIANGLE_STRIP
);
132 glTexCoord2f(0.0f
, 0.0f
);
133 glVertex3f(-DC_LOSEBAR_LENGTH
/ 2.0f
, DC_LOSEBAR_HEIGHT
/ 2.0f
, 0.0f
);
134 glTexCoord2f(1.0f
, 0.0f
);
135 glVertex3f(DC_LOSEBAR_LENGTH
/ 2.0f
, DC_LOSEBAR_HEIGHT
/ 2.0f
, 0.0f
);
136 glTexCoord2f(0.0f
, 1.0f
);
137 glVertex3f(-DC_LOSEBAR_LENGTH
/ 2.0f
, -DC_LOSEBAR_HEIGHT
/ 2.0f
, 0.0f
);
138 glTexCoord2f(1.0f
, 1.0f
);
139 glVertex3f(DC_LOSEBAR_LENGTH
/ 2.0f
, -DC_LOSEBAR_HEIGHT
/ 2.0f
, 0.0f
);
144 void Displayer::drawExternalCandy ( )
148 glTexEnvi(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_MODE
, GL_BLEND
);
150 GLfloat b
= (DC_LOSEBAR_LENGTH
+ DC_LOSEBAR_FADE_LENGTH
)
151 * (LoseBar::bar
- 0.5f
);
152 GLfloat t
= LoseBar::bar
* (1.0f
+ DC_LOSEBAR_FADE_TEX_LENGTH
)
153 - 0.5f
* DC_LOSEBAR_FADE_TEX_LENGTH
;
155 glBindTexture(GL_TEXTURE_2D
, losebar_texture
);
159 glTranslatef(DC_LEFT_EXTERNAL_CENTER
, DC_LOSEBAR_OFFSET_Y
,
160 DC_EXTERNAL_OFFSET_Z
);
162 GLfloat color1
[3], color2
[3];
165 switch (LoseBar::state
) {
167 color1
[0] = DC_LOSEBAR_INACTIVE_RED
;
168 color1
[1] = DC_LOSEBAR_INACTIVE_GREEN
;
169 color1
[2] = DC_LOSEBAR_INACTIVE_BLUE
;
175 color1
[0] = DC_LOSEBAR_LOW_ALERT_RED
;
176 color1
[1] = DC_LOSEBAR_LOW_ALERT_GREEN
;
177 color1
[2] = DC_LOSEBAR_LOW_ALERT_BLUE
;
179 color2
[0] = DC_LOSEBAR_INACTIVE_RED
;
180 color2
[1] = DC_LOSEBAR_INACTIVE_GREEN
;
181 color2
[2] = DC_LOSEBAR_INACTIVE_BLUE
;
183 drawLeftBar(b
, t
, color1
);
184 drawCenterBar(b
, t
, color1
, color2
);
185 drawRightBar(b
, t
, color2
);
189 color1
[0] = DC_LOSEBAR_HIGH_ALERT_RED
;
190 color1
[1] = DC_LOSEBAR_HIGH_ALERT_GREEN
;
191 color1
[2] = DC_LOSEBAR_HIGH_ALERT_BLUE
;
193 color2
[0] = DC_LOSEBAR_LOW_ALERT_RED
;
194 color2
[1] = DC_LOSEBAR_LOW_ALERT_GREEN
;
195 color2
[2] = DC_LOSEBAR_LOW_ALERT_BLUE
;
197 drawLeftBar(b
, t
, color1
);
198 drawCenterBar(b
, t
, color1
, color2
);
199 drawRightBar(b
, t
, color2
);
202 case LB_FADE_LOW_TO_INACTIVE
:
203 fade
= LoseBar::fade_timer
* (1.0f
/ (GLfloat
) DC_LOSEBAR_FADE_TIME
);
205 color1
[0] = DC_LOSEBAR_INACTIVE_RED
206 + fade
* (DC_LOSEBAR_LOW_ALERT_RED
- DC_LOSEBAR_INACTIVE_RED
);
207 color1
[1] = DC_LOSEBAR_INACTIVE_GREEN
208 + fade
* (DC_LOSEBAR_LOW_ALERT_GREEN
- DC_LOSEBAR_INACTIVE_GREEN
);
209 color1
[2] = DC_LOSEBAR_INACTIVE_BLUE
210 + fade
* (DC_LOSEBAR_LOW_ALERT_BLUE
- DC_LOSEBAR_INACTIVE_BLUE
);
212 color2
[0] = DC_LOSEBAR_INACTIVE_RED
;
213 color2
[1] = DC_LOSEBAR_INACTIVE_GREEN
;
214 color2
[2] = DC_LOSEBAR_INACTIVE_BLUE
;
216 drawLeftBar(b
, t
, color1
);
217 drawCenterBar(b
, t
, color1
, color2
);
218 drawRightBar(b
, t
, color2
);
221 case LB_FADE_HIGH_TO_INACTIVE
:
222 fade
= LoseBar::fade_timer
* (1.0f
/ (GLfloat
) DC_LOSEBAR_FADE_TIME
);
224 color1
[0] = DC_LOSEBAR_INACTIVE_RED
225 + fade
* (DC_LOSEBAR_HIGH_ALERT_RED
- DC_LOSEBAR_INACTIVE_RED
);
226 color1
[1] = DC_LOSEBAR_INACTIVE_GREEN
227 + fade
* (DC_LOSEBAR_HIGH_ALERT_GREEN
- DC_LOSEBAR_INACTIVE_GREEN
);
228 color1
[2] = DC_LOSEBAR_INACTIVE_BLUE
229 + fade
* (DC_LOSEBAR_HIGH_ALERT_BLUE
- DC_LOSEBAR_INACTIVE_BLUE
);
231 color2
[0] = DC_LOSEBAR_INACTIVE_RED
232 + fade
* (DC_LOSEBAR_LOW_ALERT_RED
- DC_LOSEBAR_INACTIVE_RED
);
233 color2
[1] = DC_LOSEBAR_INACTIVE_GREEN
234 + fade
* (DC_LOSEBAR_LOW_ALERT_GREEN
- DC_LOSEBAR_INACTIVE_GREEN
);
235 color2
[2] = DC_LOSEBAR_INACTIVE_BLUE
236 + fade
* (DC_LOSEBAR_LOW_ALERT_BLUE
- DC_LOSEBAR_INACTIVE_BLUE
);
238 drawLeftBar(b
, t
, color1
);
239 drawCenterBar(b
, t
, color1
, color2
);
240 drawRightBar(b
, t
, color2
);
243 case LB_FADE_RESET_HIGH
:
244 fade
= LoseBar::fade_timer
* (1.0f
/ (GLfloat
) DC_LOSEBAR_FADE_TIME
);
246 color1
[0] = DC_LOSEBAR_LOW_ALERT_RED
247 + fade
* (DC_LOSEBAR_HIGH_ALERT_RED
- DC_LOSEBAR_LOW_ALERT_RED
);
248 color1
[1] = DC_LOSEBAR_LOW_ALERT_GREEN
249 + fade
* (DC_LOSEBAR_HIGH_ALERT_GREEN
- DC_LOSEBAR_LOW_ALERT_GREEN
);
250 color1
[2] = DC_LOSEBAR_LOW_ALERT_BLUE
251 + fade
* (DC_LOSEBAR_HIGH_ALERT_BLUE
- DC_LOSEBAR_LOW_ALERT_BLUE
);
253 color2
[0] = DC_LOSEBAR_LOW_ALERT_RED
;
254 color2
[1] = DC_LOSEBAR_LOW_ALERT_GREEN
;
255 color2
[2] = DC_LOSEBAR_LOW_ALERT_BLUE
;
257 drawLeftBar(b
, t
, color1
);
258 drawCenterBar(b
, t
, color1
, color2
);
259 drawRightBar(b
, t
, color2
);
265 glTexEnvi(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_MODE
, GL_MODULATE
);
267 if ((!(MetaState::mode
& CM_REALLY_LOW_GRAPHICS
)) || (Game::state
& GS_PAUSED
) || (Game::state
& GS_WON
) || (Game::state
& GS_LOST
)) {
269 if ((MetaState::mode
& (CM_SERVER
| CM_CLIENT
)) ||
270 (MetaState::mode
& (CM_AI
))) {
274 glTranslatef(DC_LEFT_EXTERNAL_CENTER
- DC_CLOCK_DIGIT_OFFSET
/ 2,
275 DC_CLOCK_OFFSET_Y
, DC_EXTERNAL_OFFSET_Z
);
277 glBindTexture(GL_TEXTURE_2D
, clock_digit_textures
[10]);
280 glTranslatef(DC_CLOCK_CENTER_OFFSET
/ 2.0f
281 + 3.0f
* DC_CLOCK_DIGIT_OFFSET
/ 2.0f
, 0.0f
, 0.0f
);
283 GLfloat alpha
= Clock::tick
* (1.0f
/ (GLfloat
) GC_STEPS_PER_SECOND
);
285 glBindTexture(GL_TEXTURE_2D
, clock_digit_textures
[Clock::digits
[0]]);
286 if (Clock::digits
[0] != Clock::previous_digits
[0]) {
288 glBindTexture(GL_TEXTURE_2D
,
289 clock_digit_textures
[Clock::previous_digits
[0]]);
290 drawDigit(1.0f
- alpha
);
291 texture_bound
= Clock::previous_digits
[0];
294 texture_bound
= Clock::digits
[0];
297 glTranslatef(-DC_CLOCK_DIGIT_OFFSET
, 0.0f
, 0.0f
);
299 if (Clock::digits
[1] != texture_bound
)
300 glBindTexture(GL_TEXTURE_2D
, clock_digit_textures
[Clock::digits
[1]]);
301 if (Clock::digits
[1] == Clock::previous_digits
[1]) {
303 texture_bound
= Clock::digits
[1];
306 glBindTexture(GL_TEXTURE_2D
,
307 clock_digit_textures
[Clock::previous_digits
[1]]);
308 drawDigit(1.0f
- alpha
);
309 texture_bound
= Clock::previous_digits
[1];
312 glTranslatef(-DC_CLOCK_DIGIT_OFFSET
- DC_CLOCK_CENTER_OFFSET
, 0.0f
, 0.0f
);
314 if (Clock::digits
[2] != texture_bound
)
315 glBindTexture(GL_TEXTURE_2D
, clock_digit_textures
[Clock::digits
[2]]);
316 if (Clock::digits
[2] == Clock::previous_digits
[2]) {
318 texture_bound
= Clock::digits
[2];
321 glBindTexture(GL_TEXTURE_2D
,
322 clock_digit_textures
[Clock::previous_digits
[2]]);
323 drawDigit(1.0f
- alpha
);
324 texture_bound
= Clock::previous_digits
[2];
327 if (Clock::digits
[3] || Clock::previous_digits
[3]) {
328 glTranslatef(-DC_CLOCK_DIGIT_OFFSET
, 0.0f
, 0.0f
);
330 if (Clock::digits
[3] == Clock::previous_digits
[3]) {
331 if (texture_bound
!= Clock::digits
[3])
332 glBindTexture(GL_TEXTURE_2D
,
333 clock_digit_textures
[Clock::digits
[3]]);
336 if (Clock::digits
[3]) {
337 if (texture_bound
!= Clock::digits
[3])
338 glBindTexture(GL_TEXTURE_2D
,
339 clock_digit_textures
[Clock::digits
[3]]);
341 texture_bound
= Clock::digits
[3];
343 if (Clock::previous_digits
[3]) {
344 if (texture_bound
!= Clock::previous_digits
[3])
345 glBindTexture(GL_TEXTURE_2D
,
346 clock_digit_textures
[Clock::previous_digits
[3]]);
347 drawDigit(1.0f
- alpha
);
359 glTranslatef(DC_LEFT_EXTERNAL_CENTER
+ ((Score::n_digits_displayed
- 1)
360 * DC_CLOCK_DIGIT_OFFSET
) / 2, DC_CLOCK_OFFSET_Y
, DC_EXTERNAL_OFFSET_Z
);
362 GLfloat alpha
= 1.0f
- (GLfloat
) Score::fade_timer
363 * Score::inverse_timer_start
;
365 glBindTexture(GL_TEXTURE_2D
,
366 clock_digit_textures
[Score::digits
[0]]);
367 texture_bound
= Score::digits
[0];
369 if (Score::fade_timer
&& Score::previous_digits
[0]
370 != Score::digits
[0]) {
371 glBindTexture(GL_TEXTURE_2D
,
372 clock_digit_textures
[Score::previous_digits
[0]]);
373 texture_bound
= Score::previous_digits
[0];
374 drawDigit(1.0f
- alpha
);
377 for (int n
= 1; n
< Score::n_digits_displayed
; n
++) {
378 glTranslatef(-DC_CLOCK_DIGIT_OFFSET
, 0.0f
, 0.0f
);
379 if (texture_bound
!= Score::digits
[n
]) {
380 glBindTexture(GL_TEXTURE_2D
, clock_digit_textures
[Score::digits
[n
]]);
381 texture_bound
= Score::digits
[n
];
383 if (Score::fade_timer
&& Score::previous_digits
[n
]
384 != Score::digits
[n
]) {
386 glBindTexture(GL_TEXTURE_2D
,
387 clock_digit_textures
[Score::previous_digits
[n
]]);
388 texture_bound
= Score::previous_digits
[n
];
389 drawDigit(1.0f
- alpha
);
397 glColor4f(1.0f
, 1.0f
, 1.0f
, 1.0f
);
403 glBindTexture(GL_TEXTURE_2D
, logo_texture
);
404 glCallList(logo_list
);
409 glBindTexture(GL_TEXTURE_2D
, name_texture
);
410 glTranslatef(DC_LEFT_EXTERNAL_CENTER
, DC_NAME_OFFSET_Y
,
411 DC_EXTERNAL_OFFSET_Z
);
412 glScalef(DC_NAME_SCALE
, DC_NAME_SCALE
, 1.0f
);
413 glCallList(message_2x1_list
);