Didn't set the version as a string
[crack-attack.git] / src / DrawMessages.cxx
blob3206f9e254a49f154b1ebbae738e359feee9aa0c
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 #ifndef _WIN32
31 #else
32 # include <glext.h>
33 #endif
35 using namespace std;
37 #include "Game.h"
38 #include "Displayer.h"
39 #include "Communicator.h"
40 #include "CelebrationManager.h"
41 #include "MessageManager.h"
42 #include "WinRecord.h"
44 void Displayer::readyMessage ( int message )
46 * Ready the message texture for displaying. Note that messages and the count
47 * down use the same texture. Thus, both can not be active at once.
50 glGenTextures(1, &message_texture);
52 glBindTexture(GL_TEXTURE_2D, message_texture);
54 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
55 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
56 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
57 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
59 glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, message_width[message],
60 message_height[message], GL_FALSE, GL_ALPHA, GL_UNSIGNED_BYTE,
61 message_texture_data[message]);
64 void Displayer::nextMessage ( int message )
66 * Replace the current message texture. Note that it is assumed that the
67 * caller knows what's going on as far as message texture sizes. Thus, changing
68 * the message texture sizes may break code.
71 glBindTexture(GL_TEXTURE_2D, message_texture);
73 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, message_width[message],
74 message_height[message], GL_ALPHA, GL_UNSIGNED_BYTE,
75 message_texture_data[message]);
78 void Displayer::freeMessage ( )
80 * Deallocate the message texture.
83 glDeleteTextures(1, &message_texture);
86 void Displayer::drawMessage ( )
88 glBindTexture(GL_TEXTURE_2D, message_texture);
90 glPushMatrix();
92 // normal message
93 if (MessageManager::mode & MM_NORMAL) {
95 glColor4f(1.0f, 1.0f, 1.0f, message_alpha[MessageManager::time_step]);
97 if ((MetaState::mode & CM_SOLO) && (MetaState::state & MS_BOTH_KEY_WAIT))
98 glTranslatef(0.0f, DC_PLAY_OFFSET_Y + DC_GRID_ELEMENT_LENGTH
99 * 2.0f * GC_SAFE_HEIGHT / 3.0f, DC_PLAY_OFFSET_Z);
100 else
101 glTranslatef(0.0f, DC_PLAY_OFFSET_Y + DC_GRID_ELEMENT_LENGTH
102 * GC_SAFE_HEIGHT / 2.0f, DC_PLAY_OFFSET_Z);
104 glScalef(DC_MESSAGE_SCALE, DC_MESSAGE_SCALE, 1.0f);
106 if (MessageManager::message_shape & MS_1x1)
107 glCallList(message_1x1_list);
108 else if (MessageManager::message_shape & MS_2x1)
109 glCallList(message_2x1_list);
110 else
111 glCallList(message_4x1_list);
113 // win/loss message
114 } else {
115 // if we won
116 if (WinRecord::won) {
118 GLfloat color[4];
119 color[0] = DC_WIN_MESSAGE_RED;
120 color[1] = DC_WIN_MESSAGE_GREEN;
121 color[2] = DC_WIN_MESSAGE_BLUE;
122 if (CelebrationManager::win_alpha == 1.0f)
123 color[3] = 1.0f;
124 else {
125 color[3]
126 = CelebrationManager::win_alpha * CelebrationManager::win_alpha;
127 color[3] *= color[3];
130 if (CelebrationManager::win_flash1) {
131 GLfloat flash = CelebrationManager::win_flash1
132 * (2.0f / (GLfloat) DC_WIN_FLASH_1_TIME);
133 if (flash > 1.0f) flash = 2.0f - flash;
134 flash *= flash;
135 color[1] += (1.0f - DC_WIN_MESSAGE_GREEN) * flash;
136 color[2] += (1.0f - DC_WIN_MESSAGE_BLUE) * flash;
139 if (CelebrationManager::win_flash2) {
140 GLfloat flash = CelebrationManager::win_flash2
141 * (2.0f / (GLfloat) DC_WIN_FLASH_2_TIME);
142 if (flash > 1.0f) flash = 2.0f - flash;
143 flash *= flash;
144 color[1] -= (1.0f - DC_WIN_MESSAGE_GREEN) * flash;
145 color[2] += (1.0f - DC_WIN_MESSAGE_BLUE) * flash;
148 glColor4fv(color);
150 if (MetaState::mode & CM_SOLO)
151 glTranslatef(0.0f, DC_PLAY_OFFSET_Y + DC_GRID_ELEMENT_LENGTH
152 * 0.75f * GC_SAFE_HEIGHT, DC_PLAY_OFFSET_Z);
153 else
154 glTranslatef(0.0f, DC_PLAY_OFFSET_Y + DC_GRID_ELEMENT_LENGTH
155 * GC_SAFE_HEIGHT / 2.0f, DC_PLAY_OFFSET_Z);
157 glScalef(CelebrationManager::win_scale * DC_MESSAGE_SCALE,
158 CelebrationManager::win_scale * DC_MESSAGE_SCALE, 1.0f);
160 glCallList(message_1x1_list);
162 // if we lost
163 } else {
164 glColor3f(DC_LOSS_MESSAGE_RED, DC_LOSS_MESSAGE_GREEN,
165 DC_LOSS_MESSAGE_BLUE);
167 glTranslatef(0.0f, CelebrationManager::loss_height + (DC_PLAY_OFFSET_Y
168 + DC_GRID_ELEMENT_LENGTH * GC_SAFE_HEIGHT / 2.0f), DC_PLAY_OFFSET_Z);
170 if (!CelebrationManager::loss_rescale)
171 glScalef(DC_MESSAGE_SCALE, DC_MESSAGE_SCALE, 1.0f);
172 else
173 glScalef(DC_MESSAGE_SCALE * DC_GAME_OVER_SCALE_RATIO,
174 DC_MESSAGE_SCALE * DC_GAME_OVER_SCALE_RATIO, 1.0f);
176 glCallList(message_1x1_list);
180 glPopMatrix();