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 #include "solid_draw.h"
30 /*---------------------------------------------------------------------------*/
32 static struct s_full beam;
33 static struct s_full jump;
34 static struct s_full goal;
35 static struct s_full flag;
36 static struct s_full mark;
37 static struct s_full back;
39 static GLuint back_text;
41 /*---------------------------------------------------------------------------*/
45 sol_load_full(&beam, "geom/beam/beam.sol", 0);
46 sol_load_full(&jump, "geom/jump/jump.sol", 0);
47 sol_load_full(&goal, "geom/goal/goal.sol", 0);
48 sol_load_full(&flag, "geom/flag/flag.sol", 0);
49 sol_load_full(&mark, "geom/mark/mark.sol", 0);
50 sol_load_full(&back, "geom/back/back.sol", 0);
63 /*---------------------------------------------------------------------------*/
65 void back_init(const char *name)
68 back_text = make_image_from_file(name);
70 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
75 if (glIsTexture(back_text))
76 glDeleteTextures(1, &back_text);
81 /*---------------------------------------------------------------------------*/
83 static void jump_part_draw(GLfloat s, GLfloat a)
85 glMatrixMode(GL_TEXTURE);
86 glTranslatef(s, 0.0f, 0.0f);
87 glMatrixMode(GL_MODELVIEW);
89 glRotatef(a, 0.0f, 1.0f, 0.0f);
90 sol_draw(&jump.draw, 1, 1);
91 glScalef(0.9f, 0.9f, 0.9f);
94 static void goal_part_draw(GLfloat s, GLfloat a)
96 glMatrixMode(GL_TEXTURE);
97 glTranslatef(0.0f, -s, 0.0f);
98 glMatrixMode(GL_MODELVIEW);
100 glRotatef(a, 0.0f, 1.0f, 0.0f);
101 sol_draw(&goal.draw, 1, 1);
102 glScalef(0.75f, 1.1f, 0.9f);
105 /*---------------------------------------------------------------------------*/
109 const GLfloat t = SDL_GetTicks() * 0.001f;
113 glScalef(1.0f, 3.0f, 1.0f);
115 glColor4f(1.0f, 1.0f, 0.0f, 0.5f);
116 sol_draw(&beam.draw, 1, 1);
118 goal_part_draw(t * 0.1f, 20.0f);
119 goal_part_draw(t * 0.2f, 30.0f);
120 goal_part_draw(t * 0.3f, 70.0f);
122 glMatrixMode(GL_TEXTURE);
124 glMatrixMode(GL_MODELVIEW);
126 glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
131 void jump_draw(int highlight)
133 const GLfloat t = SDL_GetTicks() * 0.001f;
135 static GLfloat jump_colors[4][4] = {
136 { 0.75f, 0.5f, 1.0f, 0.5f },
137 { 0.75f, 0.5f, 1.0f, 0.8f },
142 glColor4fv(jump_colors[highlight]);
144 glScalef(1.0f, 2.0f, 1.0f);
145 sol_draw(&beam.draw, 1, 1);
147 jump_part_draw(t * 0.1f, t * 360.0f);
148 jump_part_draw(t * 0.2f, t * 360.0f);
149 jump_part_draw(t * 0.3f, t * 360.0f);
151 glMatrixMode(GL_TEXTURE);
153 glMatrixMode(GL_MODELVIEW);
155 glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
160 void swch_draw(int b, int e)
162 static GLfloat swch_colors[4][4] = {
163 { 1.0f, 0.0f, 0.0f, 0.5f }, /* red out */
164 { 1.0f, 0.0f, 0.0f, 0.8f }, /* red in */
165 { 0.0f, 1.0f, 0.0f, 0.5f }, /* green out */
166 { 0.0f, 1.0f, 0.0f, 0.8f }, /* green in */
171 glScalef(1.0f, 2.0f, 1.0f);
173 glColor4fv(swch_colors[b * 2 + e]);
174 sol_draw(&beam.draw, 1, 1);
175 glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
182 glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
183 sol_draw(&flag.draw, 1, 1);
188 sol_draw(&mark.draw, 1, 1);
191 void back_draw(float t)
195 GLfloat dx = 60.0f * fsinf(t / 10.0f);
196 GLfloat dz = 180.0f * fsinf(t / 12.0f);
198 glDisable(GL_LIGHTING);
199 glDepthMask(GL_FALSE);
201 glScalef(-BACK_DIST, BACK_DIST, -BACK_DIST);
202 glRotatef(dz, 0.0f, 0.0f, 1.0f);
203 glRotatef(dx, 1.0f, 0.0f, 0.0f);
205 glBindTexture(GL_TEXTURE_2D, back_text);
206 sol_draw(&back.draw, 1, 1);
207 glBindTexture(GL_TEXTURE_2D, 0);
209 glDepthMask(GL_TRUE);
210 glEnable(GL_LIGHTING);
215 /*---------------------------------------------------------------------------*/
217 static GLuint clip_text;
219 static GLubyte clip_data[] = { 0xff, 0xff, 0x0, 0x0 };
223 if (!glActiveTexture_)
226 glActiveTexture_(GL_TEXTURE1);
228 glGenTextures(1, &clip_text);
229 glBindTexture(GL_TEXTURE_1D, clip_text);
231 glTexImage1D(GL_TEXTURE_1D, 0,
232 GL_LUMINANCE_ALPHA, 2, 0,
233 GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, clip_data);
235 glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
236 glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
238 glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_WRAP_S, GL_CLAMP);
240 glActiveTexture_(GL_TEXTURE0);
245 if (glIsTexture(clip_text))
246 glDeleteTextures(1, &clip_text);
249 void clip_draw_set(void)
251 if (!glActiveTexture_)
254 glActiveTexture_(GL_TEXTURE1);
256 glBindTexture(GL_TEXTURE_1D, clip_text);
258 glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
260 glEnable(GL_TEXTURE_GEN_S);
261 glEnable(GL_TEXTURE_1D);
263 glActiveTexture_(GL_TEXTURE0);
266 void clip_draw_clr(void)
268 if (!glActiveTexture_)
271 glActiveTexture_(GL_TEXTURE1);
273 glDisable(GL_TEXTURE_GEN_S);
274 glDisable(GL_TEXTURE_1D);
276 glActiveTexture_(GL_TEXTURE0);
279 /*---------------------------------------------------------------------------*/
282 * A note about lighting and shadow: technically speaking, it's wrong.
283 * The light position and shadow projection behave as if the
284 * light-source rotates with the floor. However, the skybox does not
285 * rotate, thus the light should also remain stationary.
287 * The correct behavior would eliminate a significant 3D cue: the
288 * shadow of the ball indicates the ball's position relative to the
289 * floor even when the ball is in the air. This was the motivating
290 * idea behind the shadow in the first place, so correct shadow
291 * projection would only magnify the problem.
294 static GLuint shad_text;
298 shad_text = make_image_from_file(IMG_SHAD);
300 if (config_get_d(CONFIG_SHADOW) == 2)
302 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
303 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
313 if (glIsTexture(shad_text))
314 glDeleteTextures(1, &shad_text);
320 void shad_draw_set(void)
322 glActiveTexture_(GL_TEXTURE1);
324 glEnable(GL_TEXTURE_2D);
325 glBindTexture(GL_TEXTURE_2D, shad_text);
326 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
328 glActiveTexture_(GL_TEXTURE0);
332 glMatrixMode(GL_TEXTURE);
336 glMatrixMode(GL_MODELVIEW);
338 glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
339 glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
341 glEnable(GL_TEXTURE_GEN_S);
342 glEnable(GL_TEXTURE_GEN_T);
348 void shad_draw_clr(void)
350 glActiveTexture_(GL_TEXTURE1);
352 glBindTexture(GL_TEXTURE_2D, 0);
353 glDisable(GL_TEXTURE_2D);
355 glActiveTexture_(GL_TEXTURE0);
358 glDisable(GL_TEXTURE_GEN_S);
359 glDisable(GL_TEXTURE_GEN_T);
365 /*---------------------------------------------------------------------------*/