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
)) ||
272 (MetaState::mode
& (CM_AI
))) {
276 glTranslatef(DC_LEFT_EXTERNAL_CENTER
- DC_CLOCK_DIGIT_OFFSET
/ 2,
277 DC_CLOCK_OFFSET_Y
, DC_EXTERNAL_OFFSET_Z
);
279 glBindTexture(GL_TEXTURE_2D
, clock_digit_textures
[10]);
282 glTranslatef(DC_CLOCK_CENTER_OFFSET
/ 2.0f
283 + 3.0f
* DC_CLOCK_DIGIT_OFFSET
/ 2.0f
, 0.0f
, 0.0f
);
285 GLfloat alpha
= Clock::tick
* (1.0f
/ (GLfloat
) GC_STEPS_PER_SECOND
);
287 glBindTexture(GL_TEXTURE_2D
, clock_digit_textures
[Clock::digits
[0]]);
288 if (Clock::digits
[0] != Clock::previous_digits
[0]) {
290 glBindTexture(GL_TEXTURE_2D
,
291 clock_digit_textures
[Clock::previous_digits
[0]]);
292 drawDigit(1.0f
- alpha
);
293 texture_bound
= Clock::previous_digits
[0];
296 texture_bound
= Clock::digits
[0];
299 glTranslatef(-DC_CLOCK_DIGIT_OFFSET
, 0.0f
, 0.0f
);
301 if (Clock::digits
[1] != texture_bound
)
302 glBindTexture(GL_TEXTURE_2D
, clock_digit_textures
[Clock::digits
[1]]);
303 if (Clock::digits
[1] == Clock::previous_digits
[1]) {
305 texture_bound
= Clock::digits
[1];
308 glBindTexture(GL_TEXTURE_2D
,
309 clock_digit_textures
[Clock::previous_digits
[1]]);
310 drawDigit(1.0f
- alpha
);
311 texture_bound
= Clock::previous_digits
[1];
314 glTranslatef(-DC_CLOCK_DIGIT_OFFSET
- DC_CLOCK_CENTER_OFFSET
, 0.0f
, 0.0f
);
316 if (Clock::digits
[2] != texture_bound
)
317 glBindTexture(GL_TEXTURE_2D
, clock_digit_textures
[Clock::digits
[2]]);
318 if (Clock::digits
[2] == Clock::previous_digits
[2]) {
320 texture_bound
= Clock::digits
[2];
323 glBindTexture(GL_TEXTURE_2D
,
324 clock_digit_textures
[Clock::previous_digits
[2]]);
325 drawDigit(1.0f
- alpha
);
326 texture_bound
= Clock::previous_digits
[2];
329 if (Clock::digits
[3] || Clock::previous_digits
[3]) {
330 glTranslatef(-DC_CLOCK_DIGIT_OFFSET
, 0.0f
, 0.0f
);
332 if (Clock::digits
[3] == Clock::previous_digits
[3]) {
333 if (texture_bound
!= Clock::digits
[3])
334 glBindTexture(GL_TEXTURE_2D
,
335 clock_digit_textures
[Clock::digits
[3]]);
338 if (Clock::digits
[3]) {
339 if (texture_bound
!= Clock::digits
[3])
340 glBindTexture(GL_TEXTURE_2D
,
341 clock_digit_textures
[Clock::digits
[3]]);
343 texture_bound
= Clock::digits
[3];
345 if (Clock::previous_digits
[3]) {
346 if (texture_bound
!= Clock::previous_digits
[3])
347 glBindTexture(GL_TEXTURE_2D
,
348 clock_digit_textures
[Clock::previous_digits
[3]]);
349 drawDigit(1.0f
- alpha
);
361 glTranslatef(DC_LEFT_EXTERNAL_CENTER
+ ((Score::n_digits_displayed
- 1)
362 * DC_CLOCK_DIGIT_OFFSET
) / 2, DC_CLOCK_OFFSET_Y
, DC_EXTERNAL_OFFSET_Z
);
364 GLfloat alpha
= 1.0f
- (GLfloat
) Score::fade_timer
365 * Score::inverse_timer_start
;
367 glBindTexture(GL_TEXTURE_2D
,
368 clock_digit_textures
[Score::digits
[0]]);
369 texture_bound
= Score::digits
[0];
371 if (Score::fade_timer
&& Score::previous_digits
[0]
372 != Score::digits
[0]) {
373 glBindTexture(GL_TEXTURE_2D
,
374 clock_digit_textures
[Score::previous_digits
[0]]);
375 texture_bound
= Score::previous_digits
[0];
376 drawDigit(1.0f
- alpha
);
379 for (int n
= 1; n
< Score::n_digits_displayed
; n
++) {
380 glTranslatef(-DC_CLOCK_DIGIT_OFFSET
, 0.0f
, 0.0f
);
381 if (texture_bound
!= Score::digits
[n
]) {
382 glBindTexture(GL_TEXTURE_2D
, clock_digit_textures
[Score::digits
[n
]]);
383 texture_bound
= Score::digits
[n
];
385 if (Score::fade_timer
&& Score::previous_digits
[n
]
386 != Score::digits
[n
]) {
388 glBindTexture(GL_TEXTURE_2D
,
389 clock_digit_textures
[Score::previous_digits
[n
]]);
390 texture_bound
= Score::previous_digits
[n
];
391 drawDigit(1.0f
- alpha
);
399 glColor4f(1.0f
, 1.0f
, 1.0f
, 1.0f
);
405 glBindTexture(GL_TEXTURE_2D
, logo_texture
);
406 glCallList(logo_list
);
411 glBindTexture(GL_TEXTURE_2D
, name_texture
);
412 glTranslatef(DC_LEFT_EXTERNAL_CENTER
, DC_NAME_OFFSET_Y
,
413 DC_EXTERNAL_OFFSET_Z
);
414 glScalef(DC_NAME_SCALE
, DC_NAME_SCALE
, 1.0f
);
415 glCallList(message_2x1_list
);