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.
24 /*---------------------------------------------------------------------------*/
26 #define PI 3.1415926535897932
28 static GLuint back_list;
29 static GLuint back_text;
31 /*---------------------------------------------------------------------------*/
33 void back_init(const char *s, int b)
35 int i, slices = b ? 32 : 16;
36 int j, stacks = b ? 16 : 8;
39 back_text = make_image_from_file(s);
41 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
43 back_list = glGenLists(1);
45 glNewList(back_list, GL_COMPILE);
47 glBindTexture(GL_TEXTURE_2D, back_text);
49 glColor3f(1.0f, 1.0f, 1.0f);
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);
69 glTexCoord2f(k, 1.0f - k1);
70 glVertex3f(s * c1, c * c1, s1);
72 glTexCoord2f(k, 1.0f - k0);
73 glVertex3f(s * c0, c * c0, s0);
84 if (glIsList(back_list))
85 glDeleteLists(back_list, 1);
87 if (glIsTexture(back_text))
88 glDeleteTextures(1, &back_text);
94 void back_draw(float t)
98 GLfloat dx = 60.f * fsinf(t / 10.f) + 90.f;
99 GLfloat dz = 180.f * fsinf(t / 12.f);
101 glDisable(GL_LIGHTING);
102 glDepthMask(GL_FALSE);
104 glScalef(BACK_DIST, BACK_DIST, BACK_DIST);
105 glRotatef(dz, 0.f, 0.f, 1.f);
106 glRotatef(dx, 1.f, 0.f, 0.f);
108 glCallList(back_list);
110 glDepthMask(GL_TRUE);
111 glEnable(GL_LIGHTING);
116 /*---------------------------------------------------------------------------*/