3 * Daniel Nelson - 10/27/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 various messages.
35 #include "Displayer.h"
36 #include "Communicator.h"
37 #include "CelebrationManager.h"
38 #include "MessageManager.h"
39 #include "WinRecord.h"
41 void Displayer::readyMessage ( int message
)
43 * Ready the message texture for displaying. Note that messages and the count
44 * down use the same texture. Thus, both can not be active at once.
47 glGenTextures(1, &message_texture
);
49 glBindTexture(GL_TEXTURE_2D
, message_texture
);
51 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_S
, GL_REPEAT
);
52 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_T
, GL_REPEAT
);
53 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_LINEAR
);
54 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_LINEAR
);
56 glTexImage2D(GL_TEXTURE_2D
, 0, GL_ALPHA
, message_width
[message
],
57 message_height
[message
], GL_FALSE
, GL_ALPHA
, GL_UNSIGNED_BYTE
,
58 message_texture_data
[message
]);
61 void Displayer::nextMessage ( int message
)
63 * Replace the current message texture. Note that it is assumed that the
64 * caller knows what's going on as far as message texture sizes. Thus, changing
65 * the message texture sizes may break code.
68 glBindTexture(GL_TEXTURE_2D
, message_texture
);
70 glTexSubImage2D(GL_TEXTURE_2D
, 0, 0, 0, message_width
[message
],
71 message_height
[message
], GL_ALPHA
, GL_UNSIGNED_BYTE
,
72 message_texture_data
[message
]);
75 void Displayer::freeMessage ( )
77 * Deallocate the message texture.
80 glDeleteTextures(1, &message_texture
);
83 void Displayer::drawMessage ( )
85 glBindTexture(GL_TEXTURE_2D
, message_texture
);
90 if (MessageManager::mode
& MM_NORMAL
) {
92 glColor4f(1.0f
, 1.0f
, 1.0f
, message_alpha
[MessageManager::time_step
]);
94 if ((MetaState::mode
& CM_SOLO
) && (MetaState::state
& MS_BOTH_KEY_WAIT
))
95 glTranslatef(0.0f
, DC_PLAY_OFFSET_Y
+ DC_GRID_ELEMENT_LENGTH
96 * 2.0f
* GC_SAFE_HEIGHT
/ 3.0f
, DC_PLAY_OFFSET_Z
);
98 glTranslatef(0.0f
, DC_PLAY_OFFSET_Y
+ DC_GRID_ELEMENT_LENGTH
99 * GC_SAFE_HEIGHT
/ 2.0f
, DC_PLAY_OFFSET_Z
);
101 glScalef(DC_MESSAGE_SCALE
, DC_MESSAGE_SCALE
, 1.0f
);
103 if (MessageManager::message_shape
& MS_1x1
)
104 glCallList(message_1x1_list
);
105 else if (MessageManager::message_shape
& MS_2x1
)
106 glCallList(message_2x1_list
);
108 glCallList(message_4x1_list
);
113 if (WinRecord::won
) {
116 color
[0] = DC_WIN_MESSAGE_RED
;
117 color
[1] = DC_WIN_MESSAGE_GREEN
;
118 color
[2] = DC_WIN_MESSAGE_BLUE
;
119 if (CelebrationManager::win_alpha
== 1.0f
)
123 = CelebrationManager::win_alpha
* CelebrationManager::win_alpha
;
124 color
[3] *= color
[3];
127 if (CelebrationManager::win_flash1
) {
128 GLfloat flash
= CelebrationManager::win_flash1
129 * (2.0f
/ (GLfloat
) DC_WIN_FLASH_1_TIME
);
130 if (flash
> 1.0f
) flash
= 2.0f
- flash
;
132 color
[1] += (1.0f
- DC_WIN_MESSAGE_GREEN
) * flash
;
133 color
[2] += (1.0f
- DC_WIN_MESSAGE_BLUE
) * flash
;
136 if (CelebrationManager::win_flash2
) {
137 GLfloat flash
= CelebrationManager::win_flash2
138 * (2.0f
/ (GLfloat
) DC_WIN_FLASH_2_TIME
);
139 if (flash
> 1.0f
) flash
= 2.0f
- flash
;
141 color
[1] -= (1.0f
- DC_WIN_MESSAGE_GREEN
) * flash
;
142 color
[2] += (1.0f
- DC_WIN_MESSAGE_BLUE
) * flash
;
147 if (MetaState::mode
& CM_SOLO
)
148 glTranslatef(0.0f
, DC_PLAY_OFFSET_Y
+ DC_GRID_ELEMENT_LENGTH
149 * 0.75f
* GC_SAFE_HEIGHT
, DC_PLAY_OFFSET_Z
);
151 glTranslatef(0.0f
, DC_PLAY_OFFSET_Y
+ DC_GRID_ELEMENT_LENGTH
152 * GC_SAFE_HEIGHT
/ 2.0f
, DC_PLAY_OFFSET_Z
);
154 glScalef(CelebrationManager::win_scale
* DC_MESSAGE_SCALE
,
155 CelebrationManager::win_scale
* DC_MESSAGE_SCALE
, 1.0f
);
157 glCallList(message_1x1_list
);
161 glColor3f(DC_LOSS_MESSAGE_RED
, DC_LOSS_MESSAGE_GREEN
,
162 DC_LOSS_MESSAGE_BLUE
);
164 glTranslatef(0.0f
, CelebrationManager::loss_height
+ (DC_PLAY_OFFSET_Y
165 + DC_GRID_ELEMENT_LENGTH
* GC_SAFE_HEIGHT
/ 2.0f
), DC_PLAY_OFFSET_Z
);
167 if (!CelebrationManager::loss_rescale
)
168 glScalef(DC_MESSAGE_SCALE
, DC_MESSAGE_SCALE
, 1.0f
);
170 glScalef(DC_MESSAGE_SCALE
* DC_GAME_OVER_SCALE_RATIO
,
171 DC_MESSAGE_SCALE
* DC_GAME_OVER_SCALE_RATIO
, 1.0f
);
173 glCallList(message_1x1_list
);