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.
35 #include "Displayer.h"
36 #include "MetaState.h"
41 inline void Displayer::drawDigit ( GLfloat alpha
)
43 glColor4f(0.3f
, 0.3f
, 1.0f
, alpha
);
45 glBegin(GL_TRIANGLE_STRIP
);
47 glTexCoord2f(0.0f
, 1.0f
);
48 glVertex3f(-DC_CLOCK_DIGIT_LENGTH
, -DC_CLOCK_DIGIT_LENGTH
, 0.0f
);
49 glColor4f(0.5f
, 0.5f
, 1.0f
, alpha
);
50 glTexCoord2f(1.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(0.0f
, 0.0f
);
54 glVertex3f(-DC_CLOCK_DIGIT_LENGTH
, DC_CLOCK_DIGIT_LENGTH
, 0.0f
);
55 glColor4f(1.0f
, 1.0f
, 1.0f
, alpha
);
56 glTexCoord2f(1.0f
, 0.0f
);
57 glVertex3f(DC_CLOCK_DIGIT_LENGTH
, DC_CLOCK_DIGIT_LENGTH
, 0.0f
);
62 inline void Displayer::drawLeftBar ( GLfloat b
, GLfloat t
, GLfloat color
[3] )
64 if (t
< DC_LOSEBAR_FADE_TEX_LENGTH
/ 2.0f
) return;
66 glBegin(GL_TRIANGLE_STRIP
);
69 glTexCoord2f(0.0f
, 0.0f
);
70 glVertex3f(-DC_LOSEBAR_LENGTH
/ 2.0f
, DC_LOSEBAR_HEIGHT
/ 2.0f
, 0.0f
);
71 glTexCoord2f(t
- (DC_LOSEBAR_FADE_TEX_LENGTH
/ 2.0f
), 0.0f
);
72 glVertex3f(b
- (DC_LOSEBAR_FADE_LENGTH
/ 2.0f
), DC_LOSEBAR_HEIGHT
/ 2,
74 glTexCoord2f(0.0f
, 1.0f
);
75 glVertex3f(-DC_LOSEBAR_LENGTH
/ 2.0f
, -DC_LOSEBAR_HEIGHT
/ 2.0f
, 0.0f
);
76 glTexCoord2f(t
- (DC_LOSEBAR_FADE_TEX_LENGTH
/ 2.0f
), 1.0f
);
77 glVertex3f(b
- (DC_LOSEBAR_FADE_LENGTH
/ 2.0f
), -DC_LOSEBAR_HEIGHT
/ 2.0f
,
83 inline void Displayer::drawRightBar ( GLfloat b
, GLfloat t
, GLfloat color
[3] )
85 if (t
> 1.0f
- DC_LOSEBAR_FADE_TEX_LENGTH
/ 2.0f
) return;
87 glBegin(GL_TRIANGLE_STRIP
);
90 glTexCoord2f(t
+ (DC_LOSEBAR_FADE_TEX_LENGTH
/ 2.0f
), 0.0f
);
91 glVertex3f(b
+ (DC_LOSEBAR_FADE_LENGTH
/ 2.0f
), DC_LOSEBAR_HEIGHT
/ 2.0f
,
93 glTexCoord2f(1.0f
, 0.0f
);
94 glVertex3f(DC_LOSEBAR_LENGTH
/ 2.0f
, DC_LOSEBAR_HEIGHT
/ 2.0f
, 0.0f
);
95 glTexCoord2f(t
+ (DC_LOSEBAR_FADE_TEX_LENGTH
/ 2.0f
), 1.0f
);
96 glVertex3f(b
+ (DC_LOSEBAR_FADE_LENGTH
/ 2.0f
), -DC_LOSEBAR_HEIGHT
/ 2.0f
,
98 glTexCoord2f(1.0f
, 1.0f
);
99 glVertex3f(DC_LOSEBAR_LENGTH
/ 2.0f
, -DC_LOSEBAR_HEIGHT
/ 2.0f
, 0.0f
);
104 inline void Displayer::drawCenterBar ( GLfloat b
, GLfloat t
, GLfloat color1
[3],
107 glBegin(GL_TRIANGLE_STRIP
);
110 glTexCoord2f(t
- (DC_LOSEBAR_FADE_TEX_LENGTH
/ 2.0f
), 0.0f
);
111 glVertex3f(b
- (DC_LOSEBAR_FADE_LENGTH
/ 2.0f
), DC_LOSEBAR_HEIGHT
/ 2.0f
,
114 glTexCoord2f(t
+ (DC_LOSEBAR_FADE_TEX_LENGTH
/ 2.0f
), 0.0f
);
115 glVertex3f(b
+ (DC_LOSEBAR_FADE_LENGTH
/ 2.0f
), DC_LOSEBAR_HEIGHT
/ 2.0f
,
118 glTexCoord2f(t
- (DC_LOSEBAR_FADE_TEX_LENGTH
/ 2.0f
), 1.0f
);
119 glVertex3f(b
- (DC_LOSEBAR_FADE_LENGTH
/ 2.0f
), -DC_LOSEBAR_HEIGHT
/ 2.0f
,
122 glTexCoord2f(t
+ (DC_LOSEBAR_FADE_TEX_LENGTH
/ 2.0f
), 1.0f
);
123 glVertex3f(b
+ (DC_LOSEBAR_FADE_LENGTH
/ 2.0f
), -DC_LOSEBAR_HEIGHT
/ 2.0f
,
129 inline void Displayer::drawFullBar ( GLfloat color
[3] )
131 glBegin(GL_TRIANGLE_STRIP
);
134 glTexCoord2f(0.0f
, 0.0f
);
135 glVertex3f(-DC_LOSEBAR_LENGTH
/ 2.0f
, DC_LOSEBAR_HEIGHT
/ 2.0f
, 0.0f
);
136 glTexCoord2f(1.0f
, 0.0f
);
137 glVertex3f(DC_LOSEBAR_LENGTH
/ 2.0f
, DC_LOSEBAR_HEIGHT
/ 2.0f
, 0.0f
);
138 glTexCoord2f(0.0f
, 1.0f
);
139 glVertex3f(-DC_LOSEBAR_LENGTH
/ 2.0f
, -DC_LOSEBAR_HEIGHT
/ 2.0f
, 0.0f
);
140 glTexCoord2f(1.0f
, 1.0f
);
141 glVertex3f(DC_LOSEBAR_LENGTH
/ 2.0f
, -DC_LOSEBAR_HEIGHT
/ 2.0f
, 0.0f
);
146 void Displayer::drawExternalCandy ( )
150 glTexEnvi(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_MODE
, GL_BLEND
);
152 GLfloat b
= (DC_LOSEBAR_LENGTH
+ DC_LOSEBAR_FADE_LENGTH
)
153 * (LoseBar::bar
- 0.5f
);
154 GLfloat t
= LoseBar::bar
* (1.0f
+ DC_LOSEBAR_FADE_TEX_LENGTH
)
155 - 0.5f
* DC_LOSEBAR_FADE_TEX_LENGTH
;
157 glBindTexture(GL_TEXTURE_2D
, losebar_texture
);
161 glTranslatef(DC_LEFT_EXTERNAL_CENTER
, DC_LOSEBAR_OFFSET_Y
,
162 DC_EXTERNAL_OFFSET_Z
);
164 GLfloat color1
[3], color2
[3];
167 switch (LoseBar::state
) {
169 color1
[0] = DC_LOSEBAR_INACTIVE_RED
;
170 color1
[1] = DC_LOSEBAR_INACTIVE_GREEN
;
171 color1
[2] = DC_LOSEBAR_INACTIVE_BLUE
;
177 color1
[0] = DC_LOSEBAR_LOW_ALERT_RED
;
178 color1
[1] = DC_LOSEBAR_LOW_ALERT_GREEN
;
179 color1
[2] = DC_LOSEBAR_LOW_ALERT_BLUE
;
181 color2
[0] = DC_LOSEBAR_INACTIVE_RED
;
182 color2
[1] = DC_LOSEBAR_INACTIVE_GREEN
;
183 color2
[2] = DC_LOSEBAR_INACTIVE_BLUE
;
185 drawLeftBar(b
, t
, color1
);
186 drawCenterBar(b
, t
, color1
, color2
);
187 drawRightBar(b
, t
, color2
);
191 color1
[0] = DC_LOSEBAR_HIGH_ALERT_RED
;
192 color1
[1] = DC_LOSEBAR_HIGH_ALERT_GREEN
;
193 color1
[2] = DC_LOSEBAR_HIGH_ALERT_BLUE
;
195 color2
[0] = DC_LOSEBAR_LOW_ALERT_RED
;
196 color2
[1] = DC_LOSEBAR_LOW_ALERT_GREEN
;
197 color2
[2] = DC_LOSEBAR_LOW_ALERT_BLUE
;
199 drawLeftBar(b
, t
, color1
);
200 drawCenterBar(b
, t
, color1
, color2
);
201 drawRightBar(b
, t
, color2
);
204 case LB_FADE_LOW_TO_INACTIVE
:
205 fade
= LoseBar::fade_timer
* (1.0f
/ (GLfloat
) DC_LOSEBAR_FADE_TIME
);
207 color1
[0] = DC_LOSEBAR_INACTIVE_RED
208 + fade
* (DC_LOSEBAR_LOW_ALERT_RED
- DC_LOSEBAR_INACTIVE_RED
);
209 color1
[1] = DC_LOSEBAR_INACTIVE_GREEN
210 + fade
* (DC_LOSEBAR_LOW_ALERT_GREEN
- DC_LOSEBAR_INACTIVE_GREEN
);
211 color1
[2] = DC_LOSEBAR_INACTIVE_BLUE
212 + fade
* (DC_LOSEBAR_LOW_ALERT_BLUE
- DC_LOSEBAR_INACTIVE_BLUE
);
214 color2
[0] = DC_LOSEBAR_INACTIVE_RED
;
215 color2
[1] = DC_LOSEBAR_INACTIVE_GREEN
;
216 color2
[2] = DC_LOSEBAR_INACTIVE_BLUE
;
218 drawLeftBar(b
, t
, color1
);
219 drawCenterBar(b
, t
, color1
, color2
);
220 drawRightBar(b
, t
, color2
);
223 case LB_FADE_HIGH_TO_INACTIVE
:
224 fade
= LoseBar::fade_timer
* (1.0f
/ (GLfloat
) DC_LOSEBAR_FADE_TIME
);
226 color1
[0] = DC_LOSEBAR_INACTIVE_RED
227 + fade
* (DC_LOSEBAR_HIGH_ALERT_RED
- DC_LOSEBAR_INACTIVE_RED
);
228 color1
[1] = DC_LOSEBAR_INACTIVE_GREEN
229 + fade
* (DC_LOSEBAR_HIGH_ALERT_GREEN
- DC_LOSEBAR_INACTIVE_GREEN
);
230 color1
[2] = DC_LOSEBAR_INACTIVE_BLUE
231 + fade
* (DC_LOSEBAR_HIGH_ALERT_BLUE
- DC_LOSEBAR_INACTIVE_BLUE
);
233 color2
[0] = DC_LOSEBAR_INACTIVE_RED
234 + fade
* (DC_LOSEBAR_LOW_ALERT_RED
- DC_LOSEBAR_INACTIVE_RED
);
235 color2
[1] = DC_LOSEBAR_INACTIVE_GREEN
236 + fade
* (DC_LOSEBAR_LOW_ALERT_GREEN
- DC_LOSEBAR_INACTIVE_GREEN
);
237 color2
[2] = DC_LOSEBAR_INACTIVE_BLUE
238 + fade
* (DC_LOSEBAR_LOW_ALERT_BLUE
- DC_LOSEBAR_INACTIVE_BLUE
);
240 drawLeftBar(b
, t
, color1
);
241 drawCenterBar(b
, t
, color1
, color2
);
242 drawRightBar(b
, t
, color2
);
245 case LB_FADE_RESET_HIGH
:
246 fade
= LoseBar::fade_timer
* (1.0f
/ (GLfloat
) DC_LOSEBAR_FADE_TIME
);
248 color1
[0] = DC_LOSEBAR_LOW_ALERT_RED
249 + fade
* (DC_LOSEBAR_HIGH_ALERT_RED
- DC_LOSEBAR_LOW_ALERT_RED
);
250 color1
[1] = DC_LOSEBAR_LOW_ALERT_GREEN
251 + fade
* (DC_LOSEBAR_HIGH_ALERT_GREEN
- DC_LOSEBAR_LOW_ALERT_GREEN
);
252 color1
[2] = DC_LOSEBAR_LOW_ALERT_BLUE
253 + fade
* (DC_LOSEBAR_HIGH_ALERT_BLUE
- DC_LOSEBAR_LOW_ALERT_BLUE
);
255 color2
[0] = DC_LOSEBAR_LOW_ALERT_RED
;
256 color2
[1] = DC_LOSEBAR_LOW_ALERT_GREEN
;
257 color2
[2] = DC_LOSEBAR_LOW_ALERT_BLUE
;
259 drawLeftBar(b
, t
, color1
);
260 drawCenterBar(b
, t
, color1
, color2
);
261 drawRightBar(b
, t
, color2
);
267 glTexEnvi(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_MODE
, GL_MODULATE
);
269 if ((!(MetaState::mode
& CM_REALLY_LOW_GRAPHICS
)) || (Game::state
& GS_PAUSED
) || (Game::state
& GS_WON
) || (Game::state
& GS_LOST
)) {
271 if (MetaState::mode
& (CM_SERVER
| CM_CLIENT
)) {
275 glTranslatef(DC_LEFT_EXTERNAL_CENTER
- DC_CLOCK_DIGIT_OFFSET
/ 2,
276 DC_CLOCK_OFFSET_Y
, DC_EXTERNAL_OFFSET_Z
);
278 glBindTexture(GL_TEXTURE_2D
, clock_digit_textures
[10]);
281 glTranslatef(DC_CLOCK_CENTER_OFFSET
/ 2.0f
282 + 3.0f
* DC_CLOCK_DIGIT_OFFSET
/ 2.0f
, 0.0f
, 0.0f
);
284 GLfloat alpha
= Clock::tick
* (1.0f
/ (GLfloat
) GC_STEPS_PER_SECOND
);
286 glBindTexture(GL_TEXTURE_2D
, clock_digit_textures
[Clock::digits
[0]]);
287 if (Clock::digits
[0] != Clock::previous_digits
[0]) {
289 glBindTexture(GL_TEXTURE_2D
,
290 clock_digit_textures
[Clock::previous_digits
[0]]);
291 drawDigit(1.0f
- alpha
);
292 texture_bound
= Clock::previous_digits
[0];
295 texture_bound
= Clock::digits
[0];
298 glTranslatef(-DC_CLOCK_DIGIT_OFFSET
, 0.0f
, 0.0f
);
300 if (Clock::digits
[1] != texture_bound
)
301 glBindTexture(GL_TEXTURE_2D
, clock_digit_textures
[Clock::digits
[1]]);
302 if (Clock::digits
[1] == Clock::previous_digits
[1]) {
304 texture_bound
= Clock::digits
[1];
307 glBindTexture(GL_TEXTURE_2D
,
308 clock_digit_textures
[Clock::previous_digits
[1]]);
309 drawDigit(1.0f
- alpha
);
310 texture_bound
= Clock::previous_digits
[1];
313 glTranslatef(-DC_CLOCK_DIGIT_OFFSET
- DC_CLOCK_CENTER_OFFSET
, 0.0f
, 0.0f
);
315 if (Clock::digits
[2] != texture_bound
)
316 glBindTexture(GL_TEXTURE_2D
, clock_digit_textures
[Clock::digits
[2]]);
317 if (Clock::digits
[2] == Clock::previous_digits
[2]) {
319 texture_bound
= Clock::digits
[2];
322 glBindTexture(GL_TEXTURE_2D
,
323 clock_digit_textures
[Clock::previous_digits
[2]]);
324 drawDigit(1.0f
- alpha
);
325 texture_bound
= Clock::previous_digits
[2];
328 if (Clock::digits
[3] || Clock::previous_digits
[3]) {
329 glTranslatef(-DC_CLOCK_DIGIT_OFFSET
, 0.0f
, 0.0f
);
331 if (Clock::digits
[3] == Clock::previous_digits
[3]) {
332 if (texture_bound
!= Clock::digits
[3])
333 glBindTexture(GL_TEXTURE_2D
,
334 clock_digit_textures
[Clock::digits
[3]]);
337 if (Clock::digits
[3]) {
338 if (texture_bound
!= Clock::digits
[3])
339 glBindTexture(GL_TEXTURE_2D
,
340 clock_digit_textures
[Clock::digits
[3]]);
342 texture_bound
= Clock::digits
[3];
344 if (Clock::previous_digits
[3]) {
345 if (texture_bound
!= Clock::previous_digits
[3])
346 glBindTexture(GL_TEXTURE_2D
,
347 clock_digit_textures
[Clock::previous_digits
[3]]);
348 drawDigit(1.0f
- alpha
);
360 glTranslatef(DC_LEFT_EXTERNAL_CENTER
+ ((Score::n_digits_displayed
- 1)
361 * DC_CLOCK_DIGIT_OFFSET
) / 2, DC_CLOCK_OFFSET_Y
, DC_EXTERNAL_OFFSET_Z
);
363 GLfloat alpha
= 1.0f
- (GLfloat
) Score::fade_timer
364 * Score::inverse_timer_start
;
366 glBindTexture(GL_TEXTURE_2D
,
367 clock_digit_textures
[Score::digits
[0]]);
368 texture_bound
= Score::digits
[0];
370 if (Score::fade_timer
&& Score::previous_digits
[0]
371 != Score::digits
[0]) {
372 glBindTexture(GL_TEXTURE_2D
,
373 clock_digit_textures
[Score::previous_digits
[0]]);
374 texture_bound
= Score::previous_digits
[0];
375 drawDigit(1.0f
- alpha
);
378 for (int n
= 1; n
< Score::n_digits_displayed
; n
++) {
379 glTranslatef(-DC_CLOCK_DIGIT_OFFSET
, 0.0f
, 0.0f
);
380 if (texture_bound
!= Score::digits
[n
]) {
381 glBindTexture(GL_TEXTURE_2D
, clock_digit_textures
[Score::digits
[n
]]);
382 texture_bound
= Score::digits
[n
];
384 if (Score::fade_timer
&& Score::previous_digits
[n
]
385 != Score::digits
[n
]) {
387 glBindTexture(GL_TEXTURE_2D
,
388 clock_digit_textures
[Score::previous_digits
[n
]]);
389 texture_bound
= Score::previous_digits
[n
];
390 drawDigit(1.0f
- alpha
);
398 glColor4f(1.0f
, 1.0f
, 1.0f
, 1.0f
);
404 glBindTexture(GL_TEXTURE_2D
, logo_texture
);
405 glCallList(logo_list
);
410 glBindTexture(GL_TEXTURE_2D
, name_texture
);
411 glTranslatef(DC_LEFT_EXTERNAL_CENTER
, DC_NAME_OFFSET_Y
,
412 DC_EXTERNAL_OFFSET_Z
);
413 glScalef(DC_NAME_SCALE
, DC_NAME_SCALE
, 1.0f
);
414 glCallList(message_2x1_list
);