Fixes for datatype size on amd64.
[crack-attack.git] / src / obj_sparkle.cxx
blob1e9d0a469094ea780c89cc6dfedc73f4c58be119
1 /*
2 * sparkle.cxx
3 * Daniel Nelson - 9/5/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 * Generates the display list and textures for the little sparkles!
28 #include <GL/glut.h>
29 #include <cmath>
31 #include "glext.h"
33 #include "Game.h"
34 #include "Displayer.h"
36 GLuint Displayer::sparkle_list;
37 GLuint Displayer::mote_textures[DC_NUMBER_MOTE_TYPES];
38 GLuint Displayer::spark_texture;
40 void Displayer::generateSparkleList ( )
42 GLfloat texture[DC_SPARKLE_TEX_LENGTH][DC_SPARKLE_TEX_LENGTH][2];
44 sparkle_list = glGenLists(1);
46 glGenTextures(DC_NUMBER_MOTE_TYPES, mote_textures);
47 spark_texture = mote_textures[MT_FOUR_POINTED_STAR];
49 for (int n = DC_NUMBER_MOTE_TYPES; n--; ) {
51 glBindTexture(GL_TEXTURE_2D, mote_textures[n]);
53 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
54 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
55 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
56 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
58 for (int s = DC_SPARKLE_TEX_LENGTH; s--; )
59 for (int t = DC_SPARKLE_TEX_LENGTH; t--; ) {
60 float x = s * (2.0f / (float) (DC_SPARKLE_TEX_LENGTH - 1)) - 1.0f;
61 float y = t * (2.0f / (float) (DC_SPARKLE_TEX_LENGTH - 1)) - 1.0f;
62 float r = sqrt(x * x + y * y);
63 float a = atan(y / x);
64 float u;
65 if (x < 0.0f) a = PI - a;
67 switch (n) {
68 case MT_FOUR_POINTED_STAR:
69 texture[s][t][0] = 0.3f * (1.0f - 2.5f * fabs(x * x - y * y))
70 * exp(-r * r) / sqrt(r);
71 texture[s][t][1] = 4.5f * texture[s][t][0] * sqrt(r);
72 break;
74 case MT_FIVE_POINTED_STAR:
75 a *= 5.0f / 4.0f;
76 r *= 1.4f;
77 texture[s][t][0] = 0.3f * (1.0f - 2.5f
78 * fabs(pow(r, 2.2f) * cos(a) * cos(a)
79 - pow(r, 2.2f) * sin(a) * sin(a))) * exp(-r * r) / sqrt(r);
80 texture[s][t][1] = 4.5f * texture[s][t][0] * sqrt(r);
81 break;
83 case MT_SIX_POINTED_STAR:
84 a *= 6.0f / 4.0f;
85 r *= 1.4f;
86 texture[s][t][0] = 0.3f * (1.0f - 2.5f
87 * fabs(pow(r, 2.2f) * cos(a) * cos(a)
88 - pow(r, 2.2f) * sin(a) * sin(a))) * exp(-r * r) / sqrt(r);
89 texture[s][t][1] = 4.5f * texture[s][t][0] * sqrt(r);
90 break;
92 case MT_SPECIAL_STAR:
93 a *= 8.0f / 4.0f;
94 r *= 1.4f;
95 texture[s][t][0] = 0.3f * (1.0f - 2.5f
96 * fabs(pow(r, 4.2f) * cos(a) * cos(a)
97 - pow(r, 4.2f) * sin(a) * sin(a))) * exp(-r * r) / sqrt(r);
98 texture[s][t][1] = 4.5f * texture[s][t][0] * sqrt(r);
99 break;
101 case MT_MULTIPLIER_ONE_STAR:
102 a *= 3.0f / 4.0f;
103 r *= 1.9f;
104 texture[s][t][0] = 0.3f * (1.0f - 2.5f
105 * fabs(pow(r, 1.5f) * cos(a) * cos(a)
106 - pow(r, 1.5f) * sin(a) * sin(a))) * exp(-r * r) / sqrt(r);
108 if (r < 1.0f) {
109 a += PI / 4.0f;
110 u = 0.3f * (1.0f - 2.5f * fabs(pow(r, 0.7f) * cos(a) * cos(a)
111 - pow(r, 0.7f) * sin(a) * sin(a))) * exp(-0.3f * r * r) / sqrt(r);
112 if (u > 0.0f) texture[s][t][0] += u;
113 if (texture[s][t][0] > 0.5f)
114 texture[s][t][0] *= 0.3f + 0.7f / (0.5f + texture[s][t][0]);
117 texture[s][t][1] = 4.5f * texture[s][t][0] * sqrt(r);
118 break;
120 case MT_MULTIPLIER_TWO_STAR:
121 texture[s][t][0] = 0.3f * (1.0f - 2.5f * fabs(x * x - y * y))
122 * exp(-r * r) / sqrt(r);
124 a += PI / 4.0f;
125 u = 0.3f * (1.0f - 2.5f * fabs(pow(r, 0.7f) * cos(a) * cos(a)
126 - pow(r, 0.7f) * sin(a) * sin(a))) * exp(-0.1f * r * r) / sqrt(r);
127 if (u > 0.0f) texture[s][t][0] += u;
128 if (texture[s][t][0] > 0.5f)
129 texture[s][t][0] *= 0.3f + 0.7f / (0.5f + texture[s][t][0]);
131 texture[s][t][1] = 4.5f * texture[s][t][0] * sqrt(r);
132 break;
134 case MT_MULTIPLIER_THREE_STAR:
135 a += PI / 4.0f;
136 u = 0.3f * (1.0f - 3.1f * fabs(pow(r, 0.2f) * cos(a) * cos(a)
137 - pow(r, 0.2f) * sin(a) * sin(a))) * exp(-0.1f * r * r) / sqrt(r);
138 if (u > 0.0f)
139 texture[s][t][0] = u;
140 else
141 texture[s][t][0] = 0.0f;
143 texture[s][t][0] += 0.3f * (1.0f - 6.0f * fabs(x * x - y * y))
144 * exp(-0.4 * r * r) / sqrt(2.0 * r);
145 if (texture[s][t][0] > 0.5f)
146 texture[s][t][0] *= 0.3f + 0.7f / (0.5f + texture[s][t][0]);
148 texture[s][t][1] = 4.5f * texture[s][t][0] * sqrt(2 * r);
150 u = 0.15f * exp(-350.0f * (r - 0.9f) * (r - 0.9f))
151 * (1.15f + 0.3f * cos(4.0f * a));
153 if (u > texture[s][t][0]) {
154 texture[s][t][0] = u;
155 texture[s][t][1] = 4.5f * u;
157 break;
161 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE_ALPHA, DC_SPARKLE_TEX_LENGTH,
162 DC_SPARKLE_TEX_LENGTH, GL_FALSE, GL_LUMINANCE_ALPHA, GL_FLOAT, texture);
165 glNewList(sparkle_list, GL_COMPILE);
166 glBegin(GL_TRIANGLE_STRIP);
168 glTexCoord2f(0.0f, 0.0f);
169 glVertex3f(-DC_SPARKLE_LENGTH, -DC_SPARKLE_LENGTH, 0.0f);
170 glTexCoord2f(1.0f, 0.0f);
171 glVertex3f(DC_SPARKLE_LENGTH, -DC_SPARKLE_LENGTH, 0.0f);
172 glTexCoord2f(0.0f, 1.0f);
173 glVertex3f(-DC_SPARKLE_LENGTH, DC_SPARKLE_LENGTH, 0.0f);
174 glTexCoord2f(1.0f, 1.0f);
175 glVertex3f(DC_SPARKLE_LENGTH, DC_SPARKLE_LENGTH, 0.0f);
177 glEnd();
178 glEndList();