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.
29 #define PI 3.1415926535897932
31 /*---------------------------------------------------------------------------*/
33 static GLuint mark_list;
37 int i, slices = b ? 32 : 16;
39 mark_list = glGenLists(1);
41 glNewList(mark_list, GL_COMPILE);
43 glBegin(GL_TRIANGLE_FAN);
45 glNormal3f(0.f, 1.f, 0.f);
47 for (i = 0; i < slices; i++)
49 float x = fcosf(-2.f * PI * i / slices);
50 float y = fsinf(-2.f * PI * i / slices);
62 glEnable(GL_COLOR_MATERIAL);
63 glDisable(GL_TEXTURE_2D);
64 glDepthMask(GL_FALSE);
66 glCallList(mark_list);
69 glEnable(GL_TEXTURE_2D);
70 glDisable(GL_COLOR_MATERIAL);
75 if (glIsList(mark_list))
76 glDeleteLists(mark_list, 1);
81 /*---------------------------------------------------------------------------*/
83 static GLuint goal_list;
87 int i, n = b ? 32 : 8;
89 goal_list = glGenLists(1);
91 glNewList(goal_list, GL_COMPILE);
93 glBegin(GL_QUAD_STRIP);
95 for (i = 0; i <= n; i++)
97 float x = fcosf(2.f * PI * i / n);
98 float y = fsinf(2.f * PI * i / n);
100 glColor4f(1.0f, 1.0f, 0.0f, 0.5f);
101 glVertex3f(x, 0.0f, y);
103 glColor4f(1.0f, 1.0f, 0.0f, 0.0f);
104 glVertex3f(x, GOAL_HEIGHT, y);
114 if (glIsList(goal_list))
115 glDeleteLists(goal_list, 1);
122 glCallList(goal_list);
125 /*---------------------------------------------------------------------------*/
127 static GLuint jump_list;
129 void jump_init(int b)
131 int k, i, n = b ? 32 : 8;
133 jump_list = glGenLists(2);
135 for (k = 0; k < 2; k++)
137 glNewList(jump_list + k, GL_COMPILE);
139 glBegin(GL_QUAD_STRIP);
141 for (i = 0; i <= n; i++)
143 float x = fcosf(2.f * PI * i / n);
144 float y = fsinf(2.f * PI * i / n);
146 glColor4f(0.75f, 0.5f, 1.0f, (k == 0 ? 0.5f : 0.8f));
147 glVertex3f(x, 0.0f, y);
149 glColor4f(1.0f, 1.0f, 1.0f, 0.0f);
150 glVertex3f(x, JUMP_HEIGHT, y);
161 glDeleteLists(jump_list, 2);
165 void jump_draw(int highlight)
167 glCallList(jump_list + highlight);
170 /*---------------------------------------------------------------------------*/
172 static GLuint swch_list;
174 static GLfloat swch_colors[8][4] = {
175 { 1.0f, 0.0f, 0.0f, 0.5f }, /* red out */
176 { 1.0f, 0.0f, 0.0f, 0.0f },
177 { 1.0f, 0.0f, 0.0f, 0.8f }, /* red in */
178 { 1.0f, 0.0f, 0.0f, 0.0f },
179 { 0.0f, 1.0f, 0.0f, 0.5f }, /* green out */
180 { 0.0f, 1.0f, 0.0f, 0.0f },
181 { 0.0f, 1.0f, 0.0f, 0.8f }, /* green in */
182 { 0.0f, 1.0f, 0.0f, 0.0f }};
184 void swch_init(int b)
186 int k, i, n = b ? 32 : 8;
188 swch_list = glGenLists(4);
190 /* Create the display lists. */
192 for (k = 0; k < 4; k++)
194 glNewList(swch_list + k, GL_COMPILE);
196 glBegin(GL_QUAD_STRIP);
198 for (i = 0; i <= n; i++)
200 float x = fcosf(2.f * PI * i / n);
201 float y = fsinf(2.f * PI * i / n);
203 glColor4fv(swch_colors[2 * k + 0]);
204 glVertex3f(x, 0.0f, y);
206 glColor4fv(swch_colors[2 * k + 1]);
207 glVertex3f(x, SWCH_HEIGHT, y);
218 if (glIsList(swch_list))
219 glDeleteLists(swch_list, 2);
224 void swch_draw(int b, int e)
226 glCallList(swch_list + b * 2 + e);
229 /*---------------------------------------------------------------------------*/
231 static GLuint flag_list;
233 void flag_init(int b)
235 int i, n = b ? 8 : 4;
237 flag_list = glGenLists(1);
239 glNewList(flag_list, GL_COMPILE);
241 glEnable(GL_COLOR_MATERIAL);
242 glDisable(GL_LIGHTING);
243 glDisable(GL_TEXTURE_2D);
245 glBegin(GL_TRIANGLES);
247 glColor3f(1.0f, 0.0f, 0.0f);
249 glVertex3f( 0.0f, GOAL_HEIGHT, 0.0f);
250 glVertex3f(GOAL_HEIGHT * 0.2f, GOAL_HEIGHT * 0.9f, 0.0f);
251 glVertex3f( 0.0f, GOAL_HEIGHT * 0.8f, 0.0f);
253 glVertex3f( 0.0f, GOAL_HEIGHT, 0.0f);
254 glVertex3f( 0.0f, GOAL_HEIGHT * 0.8f, 0.0f);
255 glVertex3f(GOAL_HEIGHT * 0.2f, GOAL_HEIGHT * 0.9f, 0.0f);
259 glBegin(GL_QUAD_STRIP);
261 for (i = 0; i <= n; i++)
263 float x = fcosf(2.f * PI * i / n) * 0.01f;
264 float y = fsinf(2.f * PI * i / n) * 0.01f;
266 glColor3f(1.0f, 1.0f, 1.0f);
267 glVertex3f(x, 0.0f, y);
268 glVertex3f(x, GOAL_HEIGHT, y);
273 glEnable(GL_TEXTURE_2D);
274 glEnable(GL_LIGHTING);
275 glDisable(GL_COLOR_MATERIAL);
282 if (glIsList(flag_list))
283 glDeleteLists(flag_list, 1);
290 glCallList(flag_list);
293 /*---------------------------------------------------------------------------*/
295 * A note about lighting and shadow: technically speaking, it's wrong.
296 * The light position and shadow projection behave as if the
297 * light-source rotates with the floor. However, the skybox does not
298 * rotate, thus the light should also remain stationary.
300 * The correct behavior would eliminate a significant 3D cue: the
301 * shadow of the ball indicates the ball's position relative to the
302 * floor even when the ball is in the air. This was the motivating
303 * idea behind the shadow in the first place, so correct shadow
304 * projection would only magnify the problem.
307 static GLuint shad_text;
311 shad_text = make_image_from_file(IMG_SHAD);
313 if (config_get_d(CONFIG_SHADOW) == 2)
315 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
316 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
322 if (glIsTexture(shad_text))
323 glDeleteTextures(1, &shad_text);
326 void shad_draw_set(const float *p, float r)
328 glMatrixMode(GL_TEXTURE);
332 glBindTexture(GL_TEXTURE_2D, shad_text);
335 glTranslatef(0.5f - k * p[0],
336 0.5f - k * p[2], 0.f);
337 glScalef(k, k, 1.0f);
339 glMatrixMode(GL_MODELVIEW);
342 void shad_draw_clr(void)
344 glMatrixMode(GL_TEXTURE);
348 glMatrixMode(GL_MODELVIEW);
351 /*---------------------------------------------------------------------------*/
353 void fade_draw(float k)
357 int w = config_get_d(CONFIG_WIDTH);
358 int h = config_get_d(CONFIG_HEIGHT);
362 glEnable(GL_COLOR_MATERIAL);
363 glDisable(GL_LIGHTING);
364 glDisable(GL_DEPTH_TEST);
365 glDisable(GL_TEXTURE_2D);
367 glColor4f(0.0f, 0.0f, 0.0f, k);
378 glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
380 glEnable(GL_TEXTURE_2D);
381 glEnable(GL_DEPTH_TEST);
382 glEnable(GL_LIGHTING);
383 glDisable(GL_COLOR_MATERIAL);
389 /*---------------------------------------------------------------------------*/