2 * Copyright (C) 2003 Robert Kooima
4 * NEVERBALL is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published
6 * by the Free Software Foundation; either version 2 of the License,
7 * or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
28 #define PI 3.1415926535897932
30 /*---------------------------------------------------------------------------*/
32 static GLuint mark_list;
38 mark_list = glGenLists(1);
40 glNewList(mark_list, GL_COMPILE);
42 glBegin(GL_TRIANGLE_FAN);
44 glNormal3f(0.f, 1.f, 0.f);
46 for (i = 0; i < slices; i++)
48 float x = fcosf(-2.f * PI * i / slices);
49 float y = fsinf(-2.f * PI * i / slices);
61 glEnable(GL_COLOR_MATERIAL);
62 glDisable(GL_TEXTURE_2D);
63 glDepthMask(GL_FALSE);
65 glCallList(mark_list);
68 glEnable(GL_TEXTURE_2D);
69 glDisable(GL_COLOR_MATERIAL);
74 if (glIsList(mark_list))
75 glDeleteLists(mark_list, 1);
80 /*---------------------------------------------------------------------------*/
82 static GLuint goal_list;
88 goal_list = glGenLists(1);
90 glNewList(goal_list, GL_COMPILE);
92 glBegin(GL_QUAD_STRIP);
94 for (i = 0; i <= n; i++)
96 float x = fcosf(2.f * PI * i / n);
97 float y = fsinf(2.f * PI * i / n);
99 glColor4f(1.0f, 1.0f, 0.0f, 0.5f);
100 glVertex3f(x, 0.0f, y);
102 glColor4f(1.0f, 1.0f, 0.0f, 0.0f);
103 glVertex3f(x, GOAL_HEIGHT, y);
113 if (glIsList(goal_list))
114 glDeleteLists(goal_list, 1);
121 glCallList(goal_list);
124 /*---------------------------------------------------------------------------*/
126 static GLuint jump_list;
132 jump_list = glGenLists(2);
134 for (k = 0; k < 2; k++)
136 glNewList(jump_list + k, GL_COMPILE);
138 glBegin(GL_QUAD_STRIP);
140 for (i = 0; i <= n; i++)
142 float x = fcosf(2.f * PI * i / n);
143 float y = fsinf(2.f * PI * i / n);
145 glColor4f(0.75f, 0.5f, 1.0f, (k == 0 ? 0.5f : 0.8f));
146 glVertex3f(x, 0.0f, y);
148 glColor4f(1.0f, 1.0f, 1.0f, 0.0f);
149 glVertex3f(x, JUMP_HEIGHT, y);
160 glDeleteLists(jump_list, 2);
164 void jump_draw(int highlight)
166 glCallList(jump_list + highlight);
169 /*---------------------------------------------------------------------------*/
171 static GLuint swch_list;
173 static GLfloat swch_colors[8][4] = {
174 { 1.0f, 0.0f, 0.0f, 0.5f }, /* red out */
175 { 1.0f, 0.0f, 0.0f, 0.0f },
176 { 1.0f, 0.0f, 0.0f, 0.8f }, /* red in */
177 { 1.0f, 0.0f, 0.0f, 0.0f },
178 { 0.0f, 1.0f, 0.0f, 0.5f }, /* green out */
179 { 0.0f, 1.0f, 0.0f, 0.0f },
180 { 0.0f, 1.0f, 0.0f, 0.8f }, /* green in */
181 { 0.0f, 1.0f, 0.0f, 0.0f }};
187 swch_list = glGenLists(4);
189 /* Create the display lists. */
191 for (k = 0; k < 4; k++)
193 glNewList(swch_list + k, GL_COMPILE);
195 glBegin(GL_QUAD_STRIP);
197 for (i = 0; i <= n; i++)
199 float x = fcosf(2.f * PI * i / n);
200 float y = fsinf(2.f * PI * i / n);
202 glColor4fv(swch_colors[2 * k + 0]);
203 glVertex3f(x, 0.0f, y);
205 glColor4fv(swch_colors[2 * k + 1]);
206 glVertex3f(x, SWCH_HEIGHT, y);
217 if (glIsList(swch_list))
218 glDeleteLists(swch_list, 4);
223 void swch_draw(int b, int e)
225 glCallList(swch_list + b * 2 + e);
228 /*---------------------------------------------------------------------------*/
230 static GLuint flag_list;
236 flag_list = glGenLists(1);
238 glNewList(flag_list, GL_COMPILE);
240 glEnable(GL_COLOR_MATERIAL);
241 glDisable(GL_LIGHTING);
242 glDisable(GL_TEXTURE_2D);
244 glBegin(GL_TRIANGLES);
246 glColor3f(1.0f, 0.0f, 0.0f);
248 glVertex3f( 0.0f, GOAL_HEIGHT, 0.0f);
249 glVertex3f(GOAL_HEIGHT * 0.2f, GOAL_HEIGHT * 0.9f, 0.0f);
250 glVertex3f( 0.0f, GOAL_HEIGHT * 0.8f, 0.0f);
252 glVertex3f( 0.0f, GOAL_HEIGHT, 0.0f);
253 glVertex3f( 0.0f, GOAL_HEIGHT * 0.8f, 0.0f);
254 glVertex3f(GOAL_HEIGHT * 0.2f, GOAL_HEIGHT * 0.9f, 0.0f);
258 glBegin(GL_QUAD_STRIP);
260 for (i = 0; i <= n; i++)
262 float x = fcosf(2.f * PI * i / n) * 0.01f;
263 float y = fsinf(2.f * PI * i / n) * 0.01f;
265 glColor3f(1.0f, 1.0f, 1.0f);
266 glVertex3f(x, 0.0f, y);
267 glVertex3f(x, GOAL_HEIGHT, y);
272 glEnable(GL_TEXTURE_2D);
273 glEnable(GL_LIGHTING);
274 glDisable(GL_COLOR_MATERIAL);
281 if (glIsList(flag_list))
282 glDeleteLists(flag_list, 1);
289 glCallList(flag_list);
292 /*---------------------------------------------------------------------------*/
294 static GLuint clip_text;
296 static GLubyte clip_data[] = { 0xff, 0xff, 0x0, 0x0 };
300 if (!glActiveTextureARB_)
303 glActiveTextureARB_(GL_TEXTURE1_ARB);
305 glGenTextures(1, &clip_text);
306 glBindTexture(GL_TEXTURE_1D, clip_text);
308 glTexImage1D(GL_TEXTURE_1D, 0,
309 GL_LUMINANCE_ALPHA, 2, 0,
310 GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, clip_data);
312 glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
313 glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
315 glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_WRAP_S, GL_CLAMP);
317 glActiveTextureARB_(GL_TEXTURE0_ARB);
322 if (glIsTexture(clip_text))
323 glDeleteTextures(1, &clip_text);
326 void clip_draw_set(void)
328 if (!glActiveTextureARB_)
331 glActiveTextureARB_(GL_TEXTURE1_ARB);
333 glBindTexture(GL_TEXTURE_1D, clip_text);
335 glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
337 glEnable(GL_TEXTURE_GEN_S);
338 glEnable(GL_TEXTURE_1D);
340 glActiveTextureARB_(GL_TEXTURE0_ARB);
343 void clip_draw_clr(void)
345 if (!glActiveTextureARB_)
348 glActiveTextureARB_(GL_TEXTURE1_ARB);
350 glDisable(GL_TEXTURE_GEN_S);
351 glDisable(GL_TEXTURE_1D);
353 glActiveTextureARB_(GL_TEXTURE0_ARB);
356 /*---------------------------------------------------------------------------*/
359 * A note about lighting and shadow: technically speaking, it's wrong.
360 * The light position and shadow projection behave as if the
361 * light-source rotates with the floor. However, the skybox does not
362 * rotate, thus the light should also remain stationary.
364 * The correct behavior would eliminate a significant 3D cue: the
365 * shadow of the ball indicates the ball's position relative to the
366 * floor even when the ball is in the air. This was the motivating
367 * idea behind the shadow in the first place, so correct shadow
368 * projection would only magnify the problem.
371 static GLuint shad_text;
375 shad_text = make_image_from_file(IMG_SHAD);
377 if (config_get_d(CONFIG_SHADOW) == 2)
379 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
380 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
388 if (glIsTexture(shad_text))
389 glDeleteTextures(1, &shad_text);
394 void shad_draw_set(void)
396 glBindTexture(GL_TEXTURE_2D, shad_text);
398 glMatrixMode(GL_TEXTURE);
402 glMatrixMode(GL_MODELVIEW);
404 glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
405 glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
407 glEnable(GL_TEXTURE_GEN_S);
408 glEnable(GL_TEXTURE_GEN_T);
413 void shad_draw_clr(void)
415 glDisable(GL_TEXTURE_GEN_S);
416 glDisable(GL_TEXTURE_GEN_T);
421 /*---------------------------------------------------------------------------*/
423 void fade_draw(float k)
427 int w = config_get_d(CONFIG_WIDTH);
428 int h = config_get_d(CONFIG_HEIGHT);
432 glEnable(GL_COLOR_MATERIAL);
433 glDisable(GL_LIGHTING);
434 glDisable(GL_DEPTH_TEST);
435 glDisable(GL_TEXTURE_2D);
437 glColor4f(0.0f, 0.0f, 0.0f, k);
448 glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
450 glEnable(GL_TEXTURE_2D);
451 glEnable(GL_DEPTH_TEST);
452 glEnable(GL_LIGHTING);
453 glDisable(GL_COLOR_MATERIAL);
459 /*---------------------------------------------------------------------------*/