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.
25 /*---------------------------------------------------------------------------*/
27 #define PI 3.1415926535897932
29 static GLuint back_list;
30 static GLuint back_text;
32 /*---------------------------------------------------------------------------*/
34 void back_init(const char *s, int b)
36 int i, slices = b ? 32 : 16;
37 int j, stacks = b ? 16 : 8;
40 back_text = make_image_from_file(NULL, NULL, NULL, NULL, s);
42 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
44 back_list = glGenLists(1);
46 glNewList(back_list, GL_COMPILE);
48 glColor3f(1.f, 1.f, 1.f);
49 glBindTexture(GL_TEXTURE_2D, back_text);
51 for (i = 0; i < stacks; i++)
53 float k0 = (float) i / stacks;
54 float k1 = (float) (i + 1) / stacks;
56 float s0 = fsinf(V_PI * (k0 - 0.5));
57 float c0 = fcosf(V_PI * (k0 - 0.5));
58 float s1 = fsinf(V_PI * (k1 - 0.5));
59 float c1 = fcosf(V_PI * (k1 - 0.5));
61 glBegin(GL_QUAD_STRIP);
63 for (j = 0; j <= slices; j++)
65 float k = (float) j / slices;
66 float s = fsinf(V_PI * k * 2.0);
67 float c = fcosf(V_PI * k * 2.0);
70 glNormal3f(s * c1, c * c1, s1);
71 glVertex3f(s * c1, c * c1, s1);
74 glNormal3f(s * c0, c * c0, s0);
75 glVertex3f(s * c0, c * c0, s0);
86 if (glIsList(back_list))
87 glDeleteLists(back_list, 1);
89 if (glIsTexture(back_text))
90 glDeleteTextures(1, &back_text);
96 void back_draw(float t)
99 glPushAttrib(GL_LIGHTING_BIT | GL_DEPTH_BUFFER_BIT);
101 GLfloat dx = 60.f * fsinf(t / 10.f) + 90.f;
102 GLfloat dz = 180.f * fsinf(t / 12.f);
104 glDisable(GL_LIGHTING);
105 glDepthMask(GL_FALSE);
107 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
108 glScalef(BACK_DIST, BACK_DIST, BACK_DIST);
109 glRotatef(dz, 0.f, 0.f, 1.f);
110 glRotatef(dx, 1.f, 0.f, 0.f);
112 glCallList(back_list);
118 /*---------------------------------------------------------------------------*/