1 /*
2  * DrawMessages.cxx
3  * Daniel Nelson - 10/27/0
4  *
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.
11  *
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.
16  *
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.
20  *
21  * Daniel Nelson - aluminumangel.org
22  * 174 W. 18th Ave.
23  * Columbus, OH  43210
24  *
25  * Draws various messages.
26  */
27 
28 #include <GL/glut.h>
29 
30 #include "glext.h"
31 
32 using namespace std;
33 
34 #include "Game.h"
35 #include "Displayer.h"
36 #include "Communicator.h"
37 #include "CelebrationManager.h"
38 #include "MessageManager.h"
39 #include "WinRecord.h"
40 
readyMessage(int message)41 void Displayer::readyMessage ( int message )
42 /*
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.
45  */
46 {
47   glGenTextures(1, &message_texture);
48 
49   glBindTexture(GL_TEXTURE_2D, message_texture);
50 
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);
55 
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]);
59 }
60 
nextMessage(int message)61 void Displayer::nextMessage ( int message )
62 /*
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.
66  */
67 {
68   glBindTexture(GL_TEXTURE_2D, message_texture);
69 
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]);
73 }
74 
freeMessage()75 void Displayer::freeMessage (   )
76 /*
77  * Deallocate the message texture.
78  */
79 {
80   glDeleteTextures(1, &message_texture);
81 }
82 
drawMessage()83 void Displayer::drawMessage (   )
84 {
85   glBindTexture(GL_TEXTURE_2D, message_texture);
86 
87   glPushMatrix();
88 
89     // normal message
90     if (MessageManager::mode & MM_NORMAL) {
91 
92       glColor4f(1.0f, 1.0f, 1.0f, message_alpha[MessageManager::time_step]);
93 
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);
97       else
98         glTranslatef(0.0f, DC_PLAY_OFFSET_Y + DC_GRID_ELEMENT_LENGTH
99          * GC_SAFE_HEIGHT / 2.0f, DC_PLAY_OFFSET_Z);
100 
101       glScalef(DC_MESSAGE_SCALE, DC_MESSAGE_SCALE, 1.0f);
102 
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);
107       else
108         glCallList(message_4x1_list);
109 
110     // win/loss message
111     } else {
112       // if we won
113       if (WinRecord::won) {
114 
115         GLfloat color[4];
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)
120           color[3] = 1.0f;
121         else {
122           color[3]
123            = CelebrationManager::win_alpha * CelebrationManager::win_alpha;
124           color[3] *= color[3];
125         }
126 
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;
131           flash *= flash;
132           color[1] += (1.0f - DC_WIN_MESSAGE_GREEN) * flash;
133           color[2] += (1.0f - DC_WIN_MESSAGE_BLUE) * flash;
134         }
135 
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;
140           flash *= flash;
141           color[1] -= (1.0f - DC_WIN_MESSAGE_GREEN) * flash;
142           color[2] += (1.0f - DC_WIN_MESSAGE_BLUE) * flash;
143         }
144 
145         glColor4fv(color);
146 
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);
150         else
151           glTranslatef(0.0f, DC_PLAY_OFFSET_Y + DC_GRID_ELEMENT_LENGTH
152            * GC_SAFE_HEIGHT / 2.0f, DC_PLAY_OFFSET_Z);
153 
154         glScalef(CelebrationManager::win_scale * DC_MESSAGE_SCALE,
155          CelebrationManager::win_scale * DC_MESSAGE_SCALE, 1.0f);
156 
157         glCallList(message_1x1_list);
158 
159       // if we lost
160       } else {
161         glColor3f(DC_LOSS_MESSAGE_RED, DC_LOSS_MESSAGE_GREEN,
162          DC_LOSS_MESSAGE_BLUE);
163 
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);
166 
167         if (!CelebrationManager::loss_rescale)
168           glScalef(DC_MESSAGE_SCALE, DC_MESSAGE_SCALE, 1.0f);
169         else
170           glScalef(DC_MESSAGE_SCALE * DC_GAME_OVER_SCALE_RATIO,
171            DC_MESSAGE_SCALE * DC_GAME_OVER_SCALE_RATIO, 1.0f);
172 
173         glCallList(message_1x1_list);
174       }
175     }
176 
177   glPopMatrix();
178 }
179