2
* Copyright (C) 2002 <hk@dgmr.nl>
3
* Ported to Linux by Tugrul Galatali <tugrul@galatali.com>
5
* BusySpheres is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License version 2 as
7
* published by the Free Software Foundation.
9
* BusySpheres is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19
// BusySpheres screen saver
28
#include "rsDefines.h"
31
char *hack_name = (char *)"BusySpheres";
35
#define EFFECT_RANDOM 0
36
#define EFFECT_CRESCENT 1
39
#define EFFECT_LONGITUDE 4
41
int OldMode = 0, NewMode;
42
float ConvertTime = 0;
43
float Points[NRPOINTS][4];
45
void hack_reshape (xstuff_t * XStuff)
47
glViewport (0, 0, (GLsizei) XStuff->windowWidth, (GLsizei) XStuff->windowHeight);
49
glMatrixMode(GL_PROJECTION);
52
gluPerspective (30, (float)XStuff->windowWidth / (float)XStuff->windowHeight, 7, 13);
54
glMatrixMode (GL_MODELVIEW);
57
glClearColor (0, 0, 0, 0);
60
void hack_init (xstuff_t * XStuff) // Called right after the window is created, and OpenGL is initialized.
64
unsigned char texbuf[64][64];
66
for (i = 0; i < NRPOINTS; i++) {
67
Points[i][0] = rsRandf (PIx2);
68
Points[i][1] = rsRandf (PI) - 0.5 * PI;
69
Points[i][2] = Points[i][0];
70
Points[i][3] = Points[i][1];
73
glColorMaterial (GL_FRONT, GL_DIFFUSE);
75
glDisable (GL_DEPTH_TEST);
76
glDisable (GL_LIGHTING);
78
memset ((void *)&texbuf, 0, 4096);
81
for (i = 0; i < 64; i++) {
82
for (j = 0; j < 64; j++) {
85
d = sqrt (x * x + y * y);
89
texbuf[i][j] = (char)(255.0f * d * d);
94
gluBuild2DMipmaps (GL_TEXTURE_2D, 1, 64, 64, GL_LUMINANCE, GL_UNSIGNED_BYTE, texbuf);
96
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
97
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
102
void hack_cleanup (xstuff_t * XStuff)
106
void CalcPoints (float currentTime)
108
float x1, x2, y1, y2;
112
dt = currentTime - ConvertTime;
115
for (i = 0; i < NRPOINTS; i++) {
128
case EFFECT_CRESCENT:
129
x1 = (i * 0.2 * (1 + sin (0.3 * currentTime))) / (PIx2);
130
x1 = PIx2 * (x1 - (int)x1);
131
y1 = PI * ((float)i / NRPOINTS - 0.5);
137
y1 = ((Points[i][3] > 0) ? 0.5 : -0.5) * PI - Points[i][3] * 0.5 * (1 + sin (0.3 * currentTime));
143
y1 = Points[i][3] * 0.5 * (1 + sin (0.3 * currentTime));
147
case EFFECT_LONGITUDE:
149
x1 = PIx2 * (x1 - (int)x1);
150
y1 = 0.9 * PI * ((float)i / NRPOINTS - 0.5);
160
case EFFECT_CRESCENT:
161
x2 = (i * 0.2 * (1 + sin (0.3 * currentTime))) / (PIx2);
162
x2 = PIx2 * (x2 - (int)x2);
163
y2 = PI * ((float)i / NRPOINTS - 0.5);
169
if (Points[i][3] > 0) {
170
y2 = 0.5 * PI - Points[i][3] * 0.5 * (1 + sin (0.3 * currentTime));
172
y2 = -0.5 * PI - Points[i][3] * 0.5 * (1 + sin (0.3 * currentTime));
179
y2 = Points[i][3] * 0.5 * (1 + sin (0.3 * currentTime));
183
case EFFECT_LONGITUDE:
185
x2 = PIx2 * (x1 - (int)x2);
186
y2 = 0.9 * PI * ((float)i / NRPOINTS - 0.5);
189
Points[i][0] = 0.2 * (x1 * dt + x2 * (5 - dt));
190
Points[i][1] = 0.2 * (y1 * dt + y2 * (5 - dt));
195
for (i = 0; i < NRPOINTS; i++) {
196
Points[i][0] = Points[i][2];
197
Points[i][1] = Points[i][3];
202
case EFFECT_CRESCENT:
203
for (i = 0; i < NRPOINTS; i++) {
204
Points[i][0] = (i * 0.2 * (1 + sin (0.3 * currentTime))) / (PIx2);
205
Points[i][0] = PIx2 * (Points[i][0] - (int)Points[i][0]);
206
Points[i][1] = PI * ((float)i / NRPOINTS - 0.5);
212
for (i = 0; i < NRPOINTS; i++) {
213
Points[i][0] = Points[i][2];
214
Points[i][1] = ((Points[i][3] > 0) ? 0.5 : -0.5) * PI - Points[i][3] * 0.5 * (1 + sin (0.3 * currentTime));
220
for (i = 0; i < NRPOINTS; i++) {
221
Points[i][0] = Points[i][2];
222
Points[i][1] = Points[i][3] * 0.5 * (1 + sin (0.3 * currentTime));
227
case EFFECT_LONGITUDE:
228
for (i = 0; i < NRPOINTS; i++) {
229
Points[i][0] = i / 10.0f;
230
Points[i][0] = PIx2 * (Points[i][0] - (int)Points[i][0]);
231
Points[i][1] = 0.9 * PI * ((float)i / NRPOINTS - 0.5);
237
void hack_draw (xstuff_t * XStuff, double currentTime, float frameTime)
239
float x, y, z, w, ws;
241
float st2, ct2, t, t2;
242
float fb_buffer[NRPOINTS * 37 * 4];
244
currentTime = currentTime - (int)currentTime + (int)currentTime % 86400;
246
t = 5 * currentTime + 0.35 * (cos (currentTime * 0.41 + 0.123) + cos (currentTime * 0.51 + 0.234) + cos (currentTime * 0.61 + 0.623) + cos (currentTime * 0.21 + 0.723));
247
t2 = 0.3 * currentTime;
249
if ((currentTime - ConvertTime) > 10) {
251
NewMode = rsRandi (5);
252
ConvertTime = currentTime;
255
CalcPoints(currentTime);
257
glClear (GL_COLOR_BUFFER_BIT);
259
// Setup Feedback buffer for retrieval
260
glFeedbackBuffer (NRPOINTS * 37 * 4, GL_3D, fb_buffer);
261
glRenderMode (GL_FEEDBACK);
263
// set camera position
264
glMatrixMode (GL_MODELVIEW);
268
gluLookAt (10, 0, 0, 0, 0, 0, 0, 0, 1);
270
glRotatef (2.4 * t, 1, 0, 0);
271
glRotatef (2.5 * t, 0, 1, 0);
272
glRotatef (2.6 * t, 0, 0, 1);
277
// Generate the points
279
for (i = 0; i < NRPOINTS; i++) {
280
x = sin (Points[i][0]) * cos (Points[i][1]);
281
y = cos (Points[i][0]) * cos (Points[i][1]);
282
z = sin (Points[i][1]);
284
glVertex3f (x, y, z);
290
glVertex3f (x + 1.5, y, z);
291
glVertex3f (x - 1.5, y, z);
292
glVertex3f (x, y + 1.5, z);
293
glVertex3f (x, y - 1.5, z);
294
glVertex3f (x, y, z + 1.5);
295
glVertex3f (x, y, z - 1.5);
301
glVertex3f (x + 2.25, y, z);
302
glVertex3f (x + 1.5, y + 0.75 * st2, z - 0.75 * ct2);
303
glVertex3f (x + 1.5, y - 0.75 * ct2, z - 0.75 * st2);
304
glVertex3f (x + 1.5, y - 0.75 * st2, z + 0.75 * ct2);
305
glVertex3f (x + 1.5, y + 0.75 * ct2, z + 0.75 * st2);
307
glVertex3f (x - 2.25, y, z);
308
glVertex3f (x - 1.5, y - 0.75 * st2, z - 0.75 * ct2);
309
glVertex3f (x - 1.5, y + 0.75 * ct2, z - 0.75 * st2);
310
glVertex3f (x - 1.5, y + 0.75 * st2, z + 0.75 * ct2);
311
glVertex3f (x - 1.5, y - 0.75 * ct2, z + 0.75 * st2);
313
glVertex3f (x, y + 2.25, z);
314
glVertex3f (x + 0.75 * st2, y + 1.5, z - 0.75 * ct2);
315
glVertex3f (x - 0.75 * ct2, y + 1.5, z - 0.75 * st2);
316
glVertex3f (x - 0.75 * st2, y + 1.5, z + 0.75 * ct2);
317
glVertex3f (x + 0.75 * ct2, y + 1.5, z + 0.75 * st2);
319
glVertex3f (x, y - 2.25, z);
320
glVertex3f (x - 0.75 * st2, y - 1.5, z - 0.75 * ct2);
321
glVertex3f (x + 0.75 * ct2, y - 1.5, z - 0.75 * st2);
322
glVertex3f (x + 0.75 * st2, y - 1.5, z + 0.75 * ct2);
323
glVertex3f (x - 0.75 * ct2, y - 1.5, z + 0.75 * st2);
325
glVertex3f (x, y, z + 2.25);
326
glVertex3f (x + 0.75 * st2, y - 0.75 * ct2, z + 1.5);
327
glVertex3f (x - 0.75 * ct2, y - 0.75 * st2, z + 1.5);
328
glVertex3f (x - 0.75 * st2, y + 0.75 * ct2, z + 1.5);
329
glVertex3f (x + 0.75 * ct2, y + 0.75 * st2, z + 1.5);
331
glVertex3f (x, y, z - 2.25);
332
glVertex3f (x - 0.75 * st2, y - 0.75 * ct2, z - 1.5);
333
glVertex3f (x + 0.75 * ct2, y - 0.75 * st2, z - 1.5);
334
glVertex3f (x + 0.75 * st2, y + 0.75 * ct2, z - 1.5);
335
glVertex3f (x - 0.75 * ct2, y + 0.75 * st2, z - 1.5);
349
glRenderMode (GL_RENDER);
351
glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
353
glMatrixMode(GL_PROJECTION);
357
glMatrixMode(GL_MODELVIEW);
361
glScalef (2.0 / XStuff->windowWidth, 2.0 / XStuff->windowHeight, 1.0);
362
glTranslatef (-0.5 * XStuff->windowWidth, -0.5 * XStuff->windowHeight, 0);
364
glEnable (GL_TEXTURE_2D);
365
glBlendFunc (GL_ONE, GL_ONE);
368
// Draw objects from back to front
370
for (i = 0, k = 0; i < NRPOINTS * 37; i++, k++) {
374
x = fb_buffer[4 * i + 1];
375
y = fb_buffer[4 * i + 2];
376
z = fb_buffer[4 * i + 3];
378
w = 1.3 - z; // diminishing fading
379
ws = 0.002 * XStuff->windowHeight * (1 - z); // Keep Bitmaps same size realive to screensize
381
if (k == 0) { // big sphere
382
glColor3f (0.6 * w, 0.5 * w, 0.3 * w);
385
glColor3f (0.3 * w, 0.6 * w, 0.4 * w);
388
glColor3f (0.2 * w, 0.3 * w, 0.4 * w);
392
glTexCoord2f (0.0, 0.0);
393
glVertex2f (x - w, y - w);
395
glTexCoord2f (1.0, 0.0);
396
glVertex2f (x + w, y - w);
398
glTexCoord2f (1.0, 1.0);
399
glVertex2f (x + w, y + w);
401
glTexCoord2f (0.0, 1.0);
402
glVertex2f (x - w, y + w);
406
glMatrixMode(GL_MODELVIEW);
409
glMatrixMode(GL_PROJECTION);
413
void hack_handle_opts (int argc, char **argv)
419
static struct option long_options[] = {
421
DRIVER_OPTIONS_LONG {0, 0, 0, 0}
424
c = getopt_long (argc, argv, DRIVER_OPTIONS_SHORT "hq:s:t:f:b:eE", long_options, NULL);
426
c = getopt (argc, argv, DRIVER_OPTIONS_SHORT "hq:s:t:f:b:eE");
432
DRIVER_OPTIONS_CASES case 'h':printf ("%s:"
433
#ifndef HAVE_GETOPT_H
434
" Not built with GNU getopt.h, long options *NOT* enabled."
436
"\n" DRIVER_OPTIONS_HELP, argv[0]);