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 * A note about lighting and shadow: technically speaking, it's wrong.
295 * The light position and shadow projection behave as if the
296 * light-source rotates with the floor. However, the skybox does not
297 * rotate, thus the light should also remain stationary.
299 * The correct behavior would eliminate a significant 3D cue: the
300 * shadow of the ball indicates the ball's position relative to the
301 * floor even when the ball is in the air. This was the motivating
302 * idea behind the shadow in the first place, so correct shadow
303 * projection would only magnify the problem.
306 static GLuint shad_text;
310 shad_text = make_image_from_file(IMG_SHAD);
312 if (config_get_d(CONFIG_SHADOW) == 2)
314 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
315 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
321 if (glIsTexture(shad_text))
322 glDeleteTextures(1, &shad_text);
325 void shad_draw_set(const float *p, float r)
327 glMatrixMode(GL_TEXTURE);
331 glBindTexture(GL_TEXTURE_2D, shad_text);
334 glTranslatef(0.5f - k * p[0],
335 0.5f - k * p[2], 0.f);
336 glScalef(k, k, 1.0f);
338 glMatrixMode(GL_MODELVIEW);
341 void shad_draw_clr(void)
343 glMatrixMode(GL_TEXTURE);
347 glMatrixMode(GL_MODELVIEW);
350 /*---------------------------------------------------------------------------*/
352 void fade_draw(float k)
356 int w = config_get_d(CONFIG_WIDTH);
357 int h = config_get_d(CONFIG_HEIGHT);
361 glEnable(GL_COLOR_MATERIAL);
362 glDisable(GL_LIGHTING);
363 glDisable(GL_DEPTH_TEST);
364 glDisable(GL_TEXTURE_2D);
366 glColor4f(0.0f, 0.0f, 0.0f, k);
377 glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
379 glEnable(GL_TEXTURE_2D);
380 glEnable(GL_DEPTH_TEST);
381 glEnable(GL_LIGHTING);
382 glDisable(GL_COLOR_MATERIAL);
388 /*---------------------------------------------------------------------------*/