3 * Daniel Nelson - 9/5/0
5 * Copyright (C) 2000 Daniel Nelson
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
25 * Generates the display list and textures for the little sparkles!
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
);
65 if (x
< 0.0f
) a
= PI
- a
;
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
);
74 case MT_FIVE_POINTED_STAR
:
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
);
83 case MT_SIX_POINTED_STAR
:
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
);
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
);
101 case MT_MULTIPLIER_ONE_STAR
:
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
);
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
);
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
);
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
);
134 case MT_MULTIPLIER_THREE_STAR
:
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
);
139 texture
[s
][t
][0] = u
;
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
;
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
);