Updated to include tests for Gentoo installation
[crack-attack.git] / src / obj_sparkle.cxx
blobbe63548380523b93e9ab9375ec690b6d0614ef72
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 using namespace std;
35 #include "Game.h"
36 #include "Displayer.h"
38 GLuint Displayer::sparkle_list;
39 GLuint Displayer::mote_textures[DC_NUMBER_MOTE_TYPES];
40 GLuint Displayer::spark_texture;
42 void Displayer::generateSparkleList ( )
44 GLfloat texture[DC_SPARKLE_TEX_LENGTH][DC_SPARKLE_TEX_LENGTH][2];
46 sparkle_list = glGenLists(1);
48 glGenTextures(DC_NUMBER_MOTE_TYPES, mote_textures);
49 spark_texture = mote_textures[MT_FOUR_POINTED_STAR];
51 for (int n = DC_NUMBER_MOTE_TYPES; n--; ) {
53 glBindTexture(GL_TEXTURE_2D, mote_textures[n]);
55 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
56 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
57 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
58 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
60 for (int s = DC_SPARKLE_TEX_LENGTH; s--; )
61 for (int t = DC_SPARKLE_TEX_LENGTH; t--; ) {
62 float x = s * (2.0f / (float) (DC_SPARKLE_TEX_LENGTH - 1)) - 1.0f;
63 float y = t * (2.0f / (float) (DC_SPARKLE_TEX_LENGTH - 1)) - 1.0f;
64 float r = sqrt(x * x + y * y);
65 float a = atan(y / x);
66 float u;
67 if (x < 0.0f) a = PI - a;
69 switch (n) {
70 case MT_FOUR_POINTED_STAR:
71 texture[s][t][0] = 0.3f * (1.0f - 2.5f * fabs(x * x - y * y))
72 * exp(-r * r) / sqrt(r);
73 texture[s][t][1] = 4.5f * texture[s][t][0] * sqrt(r);
74 break;
76 case MT_FIVE_POINTED_STAR:
77 a *= 5.0f / 4.0f;
78 r *= 1.4f;
79 texture[s][t][0] = 0.3f * (1.0f - 2.5f
80 * fabs(pow(r, 2.2f) * cos(a) * cos(a)
81 - pow(r, 2.2f) * sin(a) * sin(a))) * exp(-r * r) / sqrt(r);
82 texture[s][t][1] = 4.5f * texture[s][t][0] * sqrt(r);
83 break;
85 case MT_SIX_POINTED_STAR:
86 a *= 6.0f / 4.0f;
87 r *= 1.4f;
88 texture[s][t][0] = 0.3f * (1.0f - 2.5f
89 * fabs(pow(r, 2.2f) * cos(a) * cos(a)
90 - pow(r, 2.2f) * sin(a) * sin(a))) * exp(-r * r) / sqrt(r);
91 texture[s][t][1] = 4.5f * texture[s][t][0] * sqrt(r);
92 break;
94 case MT_SPECIAL_STAR:
95 a *= 8.0f / 4.0f;
96 r *= 1.4f;
97 texture[s][t][0] = 0.3f * (1.0f - 2.5f
98 * fabs(pow(r, 4.2f) * cos(a) * cos(a)
99 - pow(r, 4.2f) * sin(a) * sin(a))) * exp(-r * r) / sqrt(r);
100 texture[s][t][1] = 4.5f * texture[s][t][0] * sqrt(r);
101 break;
103 case MT_MULTIPLIER_ONE_STAR:
104 a *= 3.0f / 4.0f;
105 r *= 1.9f;
106 texture[s][t][0] = 0.3f * (1.0f - 2.5f
107 * fabs(pow(r, 1.5f) * cos(a) * cos(a)
108 - pow(r, 1.5f) * sin(a) * sin(a))) * exp(-r * r) / sqrt(r);
110 if (r < 1.0f) {
111 a += PI / 4.0f;
112 u = 0.3f * (1.0f - 2.5f * fabs(pow(r, 0.7f) * cos(a) * cos(a)
113 - pow(r, 0.7f) * sin(a) * sin(a))) * exp(-0.3f * r * r) / sqrt(r);
114 if (u > 0.0f) texture[s][t][0] += u;
115 if (texture[s][t][0] > 0.5f)
116 texture[s][t][0] *= 0.3f + 0.7f / (0.5f + texture[s][t][0]);
119 texture[s][t][1] = 4.5f * texture[s][t][0] * sqrt(r);
120 break;
122 case MT_MULTIPLIER_TWO_STAR:
123 texture[s][t][0] = 0.3f * (1.0f - 2.5f * fabs(x * x - y * y))
124 * exp(-r * r) / sqrt(r);
126 a += PI / 4.0f;
127 u = 0.3f * (1.0f - 2.5f * fabs(pow(r, 0.7f) * cos(a) * cos(a)
128 - pow(r, 0.7f) * sin(a) * sin(a))) * exp(-0.1f * r * r) / sqrt(r);
129 if (u > 0.0f) texture[s][t][0] += u;
130 if (texture[s][t][0] > 0.5f)
131 texture[s][t][0] *= 0.3f + 0.7f / (0.5f + texture[s][t][0]);
133 texture[s][t][1] = 4.5f * texture[s][t][0] * sqrt(r);
134 break;
136 case MT_MULTIPLIER_THREE_STAR:
137 a += PI / 4.0f;
138 u = 0.3f * (1.0f - 3.1f * fabs(pow(r, 0.2f) * cos(a) * cos(a)
139 - pow(r, 0.2f) * sin(a) * sin(a))) * exp(-0.1f * r * r) / sqrt(r);
140 if (u > 0.0f)
141 texture[s][t][0] = u;
142 else
143 texture[s][t][0] = 0.0f;
145 texture[s][t][0] += 0.3f * (1.0f - 6.0f * fabs(x * x - y * y))
146 * exp(-0.4 * r * r) / sqrt(2.0 * r);
147 if (texture[s][t][0] > 0.5f)
148 texture[s][t][0] *= 0.3f + 0.7f / (0.5f + texture[s][t][0]);
150 texture[s][t][1] = 4.5f * texture[s][t][0] * sqrt(2 * r);
152 u = 0.15f * exp(-350.0f * (r - 0.9f) * (r - 0.9f))
153 * (1.15f + 0.3f * cos(4.0f * a));
155 if (u > texture[s][t][0]) {
156 texture[s][t][0] = u;
157 texture[s][t][1] = 4.5f * u;
159 break;
163 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE_ALPHA, DC_SPARKLE_TEX_LENGTH,
164 DC_SPARKLE_TEX_LENGTH, GL_FALSE, GL_LUMINANCE_ALPHA, GL_FLOAT, texture);
167 glNewList(sparkle_list, GL_COMPILE);
168 glBegin(GL_TRIANGLE_STRIP);
170 glTexCoord2f(0.0f, 0.0f);
171 glVertex3f(-DC_SPARKLE_LENGTH, -DC_SPARKLE_LENGTH, 0.0f);
172 glTexCoord2f(1.0f, 0.0f);
173 glVertex3f(DC_SPARKLE_LENGTH, -DC_SPARKLE_LENGTH, 0.0f);
174 glTexCoord2f(0.0f, 1.0f);
175 glVertex3f(-DC_SPARKLE_LENGTH, DC_SPARKLE_LENGTH, 0.0f);
176 glTexCoord2f(1.0f, 1.0f);
177 glVertex3f(DC_SPARKLE_LENGTH, DC_SPARKLE_LENGTH, 0.0f);
179 glEnd();
180 glEndList();