Fixes for datatype size on amd64.
[crack-attack.git] / src / DrawMessages.cxx
blob360406de9f4005e9944d3a070c50aa08d7a87656
1 /*
2 * DrawMessages.cxx
3 * Daniel Nelson - 10/27/0
5 * Copyright (C) 2000 Daniel Nelson
6 *
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
22 * 174 W. 18th Ave.
23 * Columbus, OH 43210
25 * Draws various messages.
28 #include <GL/glut.h>
30 #include "glext.h"
32 #include "Game.h"
33 #include "Displayer.h"
34 #include "Communicator.h"
35 #include "CelebrationManager.h"
36 #include "MessageManager.h"
37 #include "WinRecord.h"
39 void Displayer::readyMessage ( int message )
41 * Ready the message texture for displaying. Note that messages and the count
42 * down use the same texture. Thus, both can not be active at once.
45 glGenTextures(1, &message_texture);
47 glBindTexture(GL_TEXTURE_2D, message_texture);
49 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
50 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
51 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
52 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
54 glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, message_width[message],
55 message_height[message], GL_FALSE, GL_ALPHA, GL_UNSIGNED_BYTE,
56 message_texture_data[message]);
59 void Displayer::nextMessage ( int message )
61 * Replace the current message texture. Note that it is assumed that the
62 * caller knows what's going on as far as message texture sizes. Thus, changing
63 * the message texture sizes may break code.
66 glBindTexture(GL_TEXTURE_2D, message_texture);
68 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, message_width[message],
69 message_height[message], GL_ALPHA, GL_UNSIGNED_BYTE,
70 message_texture_data[message]);
73 void Displayer::freeMessage ( )
75 * Deallocate the message texture.
78 glDeleteTextures(1, &message_texture);
81 void Displayer::drawMessage ( )
83 glBindTexture(GL_TEXTURE_2D, message_texture);
85 glPushMatrix();
87 // normal message
88 if (MessageManager::mode & MM_NORMAL) {
90 glColor4f(1.0f, 1.0f, 1.0f, message_alpha[MessageManager::time_step]);
92 if ((MetaState::mode & CM_SOLO) && (MetaState::state & MS_BOTH_KEY_WAIT))
93 glTranslatef(0.0f, DC_PLAY_OFFSET_Y + DC_GRID_ELEMENT_LENGTH
94 * 2.0f * GC_SAFE_HEIGHT / 3.0f, DC_PLAY_OFFSET_Z);
95 else
96 glTranslatef(0.0f, DC_PLAY_OFFSET_Y + DC_GRID_ELEMENT_LENGTH
97 * GC_SAFE_HEIGHT / 2.0f, DC_PLAY_OFFSET_Z);
99 glScalef(DC_MESSAGE_SCALE, DC_MESSAGE_SCALE, 1.0f);
101 if (MessageManager::message_shape & MS_1x1)
102 glCallList(message_1x1_list);
103 else if (MessageManager::message_shape & MS_2x1)
104 glCallList(message_2x1_list);
105 else
106 glCallList(message_4x1_list);
108 // win/loss message
109 } else {
110 // if we won
111 if (WinRecord::won) {
113 GLfloat color[4];
114 color[0] = DC_WIN_MESSAGE_RED;
115 color[1] = DC_WIN_MESSAGE_GREEN;
116 color[2] = DC_WIN_MESSAGE_BLUE;
117 if (CelebrationManager::win_alpha == 1.0f)
118 color[3] = 1.0f;
119 else {
120 color[3]
121 = CelebrationManager::win_alpha * CelebrationManager::win_alpha;
122 color[3] *= color[3];
125 if (CelebrationManager::win_flash1) {
126 GLfloat flash = CelebrationManager::win_flash1
127 * (2.0f / (GLfloat) DC_WIN_FLASH_1_TIME);
128 if (flash > 1.0f) flash = 2.0f - flash;
129 flash *= flash;
130 color[1] += (1.0f - DC_WIN_MESSAGE_GREEN) * flash;
131 color[2] += (1.0f - DC_WIN_MESSAGE_BLUE) * flash;
134 if (CelebrationManager::win_flash2) {
135 GLfloat flash = CelebrationManager::win_flash2
136 * (2.0f / (GLfloat) DC_WIN_FLASH_2_TIME);
137 if (flash > 1.0f) flash = 2.0f - flash;
138 flash *= flash;
139 color[1] -= (1.0f - DC_WIN_MESSAGE_GREEN) * flash;
140 color[2] += (1.0f - DC_WIN_MESSAGE_BLUE) * flash;
143 glColor4fv(color);
145 if (MetaState::mode & CM_SOLO)
146 glTranslatef(0.0f, DC_PLAY_OFFSET_Y + DC_GRID_ELEMENT_LENGTH
147 * 0.75f * GC_SAFE_HEIGHT, DC_PLAY_OFFSET_Z);
148 else
149 glTranslatef(0.0f, DC_PLAY_OFFSET_Y + DC_GRID_ELEMENT_LENGTH
150 * GC_SAFE_HEIGHT / 2.0f, DC_PLAY_OFFSET_Z);
152 glScalef(CelebrationManager::win_scale * DC_MESSAGE_SCALE,
153 CelebrationManager::win_scale * DC_MESSAGE_SCALE, 1.0f);
155 glCallList(message_1x1_list);
157 // if we lost
158 } else {
159 glColor3f(DC_LOSS_MESSAGE_RED, DC_LOSS_MESSAGE_GREEN,
160 DC_LOSS_MESSAGE_BLUE);
162 glTranslatef(0.0f, CelebrationManager::loss_height + (DC_PLAY_OFFSET_Y
163 + DC_GRID_ELEMENT_LENGTH * GC_SAFE_HEIGHT / 2.0f), DC_PLAY_OFFSET_Z);
165 if (!CelebrationManager::loss_rescale)
166 glScalef(DC_MESSAGE_SCALE, DC_MESSAGE_SCALE, 1.0f);
167 else
168 glScalef(DC_MESSAGE_SCALE * DC_GAME_OVER_SCALE_RATIO,
169 DC_MESSAGE_SCALE * DC_GAME_OVER_SCALE_RATIO, 1.0f);
171 glCallList(message_1x1_list);
175 glPopMatrix();