~ubuntu-branches/ubuntu/lucid/xscreensaver/lucid

« back to all changes in this revision

Viewing changes to hacks/glx/timetunnel.c

  • Committer: Bazaar Package Importer
  • Author(s): Oliver Grawert
  • Date: 2007-12-06 09:53:12 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20071206095312-fkzcwe4vqm50z208
Tags: 5.04-1ubuntu1
* Merge from debian unstable, remaining changes:
  - split xscreensaver into xscreensaver, xscreensaver-data (hacks we ship),
    xscreensaver-data-extra (hacks in universe). split out gl hacks for
    universe to xscreensaver-gl-extra
  - use fridge for rss screensavers
  - create and install .desktop files for gnome-screensaver

Show diffs side-by-side

added added

removed removed

Lines of Context:
10
10
 * implied warranty.
11
11
 */
12
12
 
13
 
#include <X11/Intrinsic.h>
14
13
#include <math.h> /* for log2 */
15
14
 
16
 
extern XtAppContext app;
17
 
 
18
 
#define PROGCLASS       "TimeTunnel"
19
 
#define HACK_INIT       init_tunnel
20
 
#define HACK_DRAW       draw_tunnel
21
 
#define HACK_RESHAPE    reshape_tunnel
22
 
#define HACK_HANDLE_EVENT tunnel_handle_event
23
 
#define EVENT_MASK      PointerMotionMask
24
 
#define sws_opts        xlockmore_opts
25
 
 
26
 
#define DEF_START       "0.00"
27
 
#define DEF_DILATE      "1.00"
28
 
#define DEF_END         "27.79"
29
 
#define DEF_LOCKLOGO    "False"
30
 
#define DEF_TUNONLY     "False"
31
 
#define DEF_REVERSE     "False"
32
 
#define DEF_FOG         "True"
33
 
#define DEF_TEXTURE     "True"
34
 
#define MAX_TEXTURE 10
35
 
#define CYL_LEN         14.0
36
 
#define DIAMOND_LEN     10.0
37
 
 
38
15
#define DEFAULTS        "*delay:        30000       \n" \
39
16
                        "*count:        30          \n" \
40
17
                        "*showFPS:      False       \n" \
44
21
 
45
22
 
46
23
 
 
24
# define refresh_tunnel 0
 
25
# define release_tunnel 0
47
26
#undef countof
48
27
#define countof(x) (sizeof((x))/sizeof((*x)))
49
28
 
51
30
#include "colors.h"
52
31
#include "rotator.h"
53
32
#include "gltrackball.h"
54
 
#include <ctype.h>
55
 
#include <sys/time.h> /* for time based animations */
 
33
 
 
34
 
 
35
#define DEF_START       "0.00"
 
36
#define DEF_DILATE      "1.00"
 
37
#define DEF_END         "27.79"
 
38
#define DEF_LOCKLOGO    "False"
 
39
#define DEF_DRAWLOGO    "True"
 
40
#define DEF_REVERSE     "False"
 
41
#define DEF_FOG         "True"
 
42
#define DEF_TEXTURE     "True"
 
43
#define MAX_TEXTURE 10
 
44
#define CYL_LEN         14.0
 
45
#define DIAMOND_LEN     10.0
56
46
 
57
47
static float start, end, dilate;
58
 
static Bool do_texture, tunonly, wire, reverse, do_fog;
 
48
static Bool do_texture, drawlogo, wire, reverse, do_fog;
59
49
#ifdef GET_SUED_BY_THE_BBC
60
50
static Bool locklogo;
61
51
#endif
68
58
#ifdef GET_SUED_BY_THE_BBC
69
59
  {"-locklogo"  , ".locklogo",  XrmoptionNoArg, "true" },
70
60
#endif
71
 
  {"-tunonly"   , ".tunonly",   XrmoptionNoArg, "true" },
 
61
  {"-logo"      , ".drawlogo",   XrmoptionNoArg, "true" },
 
62
  {"+logo"      , ".drawlogo",   XrmoptionNoArg, "false" },
72
63
  {"-reverse"   , ".reverse",   XrmoptionNoArg, "true" },
73
64
  {"-fog"       , ".fog",       XrmoptionNoArg, "false" },
74
65
};
81
72
#ifdef GET_SUED_BY_THE_BBC
82
73
  {&locklogo,     "locklogo",   "LockLogo", DEF_LOCKLOGO  , t_Bool},
83
74
#endif
84
 
  {&tunonly,     "tunonly",   "TunnelOnly", DEF_TUNONLY  , t_Bool},
 
75
  {&drawlogo,     "drawlogo",   "DrawLogo", DEF_DRAWLOGO  , t_Bool},
85
76
  {&reverse,     "reverse",   "Reverse", DEF_REVERSE  , t_Bool},
86
77
  {&do_fog,     "fog",   "Fog", DEF_FOG  , t_Bool},
87
78
};
88
79
 
89
 
ModeSpecOpt sws_opts = {countof(opts), opts, countof(vars), vars, NULL};
 
80
ENTRYPOINT ModeSpecOpt tunnel_opts = {countof(opts), opts, countof(vars), vars, NULL};
90
81
#include "xpm-ximage.h"
91
 
#include "../../utils/images/logo-180.xpm"
92
 
#include "../images/tunnelstar.xpm"
93
 
#include "../images/timetunnel0.xpm"
94
 
#include "../images/timetunnel1.xpm"
95
 
#include "../images/timetunnel2.xpm"
 
82
#include "images/logo-180.xpm"
 
83
#include "images/tunnelstar.xpm"
 
84
#include "images/timetunnel0.xpm"
 
85
#include "images/timetunnel1.xpm"
 
86
#include "images/timetunnel2.xpm"
96
87
#ifdef GET_SUED_BY_THE_BBC
97
 
# include "../images/tardis.xpm"
98
 
# include "../images/whologo.xpm"
99
 
# include "../images/whohead1.xpm"
100
 
/* #include "../images/whohead_psy.xpm" */
 
88
# include "images/tardis.xpm"
 
89
# include "images/whologo.xpm"
 
90
# include "images/whohead1.xpm"
 
91
/* #include "images/whohead_psy.xpm" */
101
92
# endif /* GET_SUED_BY_THE_BBC */
102
93
 
103
94
 
104
95
#ifdef USE_GL /* whole file */
105
96
 
106
 
#include <GL/glu.h>
107
 
 
108
97
/* ANIMATION CONTROLS */
109
98
/* an effect is a collection of floating point variables that vary with time.
110
99
A knot is a timestamp with an array of floats.  State is the current values of the floats.
139
128
static tunnel_configuration *tconf = NULL;
140
129
 
141
130
/* allocate memory and populate effect with knot data */
142
 
void init_effect(effect_t *e, int numk, int kwidth, 
143
 
        float dir, float *data ) {
 
131
static void init_effect(effect_t *e, int numk, int kwidth, 
 
132
        float dir, float *data ) 
 
133
{
144
134
        int i, j;
145
135
 
146
136
        e->numknots = numk;     
157
147
   Knots are linerally interpolated to yield float values, depending on
158
148
   knot width.  knot format is [time, data, data, data...].
159
149
   Data can be alpha, zvalue, etc. */
160
 
void init_effects(effect_t *e, int effectnum)
 
150
static void init_effects(effect_t *e, int effectnum)
161
151
{
162
152
        /* effect 1: wall tunnel. percent closed */
163
153
        float e1d[6][2] = 
307
297
 
308
298
 
309
299
/* set fog parameters, controlled by effect */
310
 
void update_fog(float color, float density, float start, float end) {
 
300
static void update_fog(float color, float density, float start, float end) 
 
301
{
311
302
                GLfloat col[4];
312
303
        
313
304
                col[0] = col[1] = col[2] = color;
323
314
/* set effect's floating point data values by linearally interpolating
324
315
between two knots whose times bound the current time: eff_time */
325
316
 
326
 
void update_knots(effect_t *e, float eff_time) {
 
317
static void update_knots(effect_t *e, float eff_time) 
 
318
{
327
319
        int i, j;
328
320
        float timedelta, lowknot, highknot, *curknot, *nextknot;
329
321
 
351
343
 
352
344
/* Window management, etc
353
345
 */
354
 
void
 
346
ENTRYPOINT void
355
347
reshape_tunnel (ModeInfo *mi, int width, int height)
356
348
{
357
349
  GLfloat h = (GLfloat) height / (GLfloat) width;
374
366
 
375
367
 
376
368
 
377
 
Bool
 
369
ENTRYPOINT Bool
378
370
tunnel_handle_event (ModeInfo *mi, XEvent *event)
379
371
{
380
372
  tunnel_configuration *tc = &tconf[MI_SCREEN(mi)];
414
406
  return False;
415
407
}
416
408
 
417
 
void setTexParams(void)
 
409
static void setTexParams(void)
418
410
{
419
411
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
420
412
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
423
415
        glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
424
416
}
425
417
 
426
 
void update_animation(tunnel_configuration *tc) {
 
418
static void update_animation(tunnel_configuration *tc) {
427
419
 
428
420
        /* time based, of course*/
429
421
        /* shift texture based on elapsed time since previous call*/
430
 
        static struct timeval tv;
431
 
        static struct timezone tz;
432
 
        static int elapsed_usecs, elapsed_secs, i;
 
422
        struct timeval tv;
 
423
        struct timezone tz;
 
424
        int elapsed_usecs, elapsed_secs, i;
433
425
        float computed_timeshift;
434
426
 
435
427
        /* get new animation time */
484
476
/* draw a textured(tex) quad at a certain depth (z), and certain alpha (alpha), 
485
477
with aspect ratio (aspect), and blending mode (blend_mode) of either adding
486
478
or subtracting.  if alpha is zero or less, nothing happens */
487
 
void draw_sign(ModeInfo *mi, tunnel_configuration *tc, float z,  float alpha, float aspect,
 
479
static void draw_sign(ModeInfo *mi, tunnel_configuration *tc, float z,  float alpha, float aspect,
488
480
                GLuint tex, int blend_mode)
489
481
{
490
482
 
535
527
/* draw a time tunnel.  used for both cylender and diamond tunnels.
536
528
   uses texture shifter (indexed by shiftnum) to simulate motion.
537
529
   tunnel does not move, and is acutally a display list.  if alpha = 0, skip */
538
 
void draw_cyl(ModeInfo *mi, tunnel_configuration *tc, float alpha, int texnum, int listnum, int shiftnum)
 
530
static void draw_cyl(ModeInfo *mi, tunnel_configuration *tc, float alpha, int texnum, int listnum, int shiftnum)
539
531
{
540
532
        if (alpha > 0.0) {
541
533
                if (listnum  ==  tc->diamondlist)
568
560
grows to outline of tardis.  percent is how complete
569
561
tardis outline is.  cap is to draw cap for nice fog effects */
570
562
 
571
 
void make_wall_tunnel(ModeInfo *mi, tunnel_configuration *tc, float percent, float cap)
 
563
static void make_wall_tunnel(ModeInfo *mi, tunnel_configuration *tc, float percent, float cap)
572
564
{
573
565
        /* tardis is about 2x1, so wrap tex around, starting at the base*/
574
566
        /* tex coords are:
616
608
                glBindTexture(GL_TEXTURE_2D, tc->texture_binds[0]);
617
609
#endif
618
610
        glColor3f(1.0, 1.0, 0.0);
619
 
        if (cap > 0.0 && percent > 0.0 && ! tunonly && do_fog) {
 
611
        if (cap > 0.0 && percent > 0.0 && drawlogo && do_fog) {
620
612
                mi->polygon_count += 6;
621
613
                glBegin(GL_TRIANGLE_FAN);
622
614
                glVertex3f(0.0, 0.0, zdepth);
827
819
/* wraps an int to between min and max.
828
820
   Kind of like the remainder when devided by (max - min).
829
821
   Used to create torus mapping on square array */
830
 
int wrapVal(int val, int min, int max)
 
822
static int wrapVal(int val, int min, int max)
831
823
{
832
824
        int ret;
833
825
 
851
843
 
852
844
*/
853
845
 
854
 
float mylog2(float x) { return ( log(x) / log(2));}
 
846
static float mylog2(float x) { return ( log(x) / log(2));}
855
847
 
856
 
static void LoadTexture(ModeInfo * mi, char **fn, unsigned int texbind, int blur, float bw_color, Bool anegative, Bool onealpha)
 
848
static void LoadTexture(ModeInfo * mi, char **fn, GLuint texbind, int blur, float bw_color, Bool anegative, Bool onealpha)
857
849
{
858
850
        /* looping and temporary array index variables */
859
851
        int ix, iy, bx, by, indx, indy, boxsize, cchan, tmpidx, dtaidx;
865
857
 
866
858
        XImage *teximage;    /* Texture data */
867
859
 
868
 
        rescale = FALSE;
 
860
        rescale = False;
869
861
 
870
862
        boxsize = 2;
871
863
        boxdiv = 1.0 / ( boxsize * 2.0 + 1.0) / ( boxsize * 2.0 + 1.0);
883
875
        tmpfa = mylog2((float) teximage->width);
884
876
        bx = 2 << (int) (tmpfa -1);
885
877
        if (bx != teximage->width) {
886
 
                rescale = TRUE;
 
878
                rescale = True;
887
879
                if ((tmpfa - (int) tmpfa) >  0.5849)
888
880
                        bx = bx * 2;
889
881
        }
890
882
        tmpfa = mylog2((float) teximage->height);
891
883
        by = 2 << (int) (tmpfa - 1);
892
884
        if (by != teximage->height) {
893
 
                rescale = TRUE;
 
885
                rescale = True;
894
886
                if ((tmpfa - (int) tmpfa) >  0.5849)
895
887
                        by = by * 2;
896
888
        }
996
988
/* creates cylender for time tunnel. sides, zmin, zmax, rad(ius) obvious.
997
989
   stretch scales texture coords; makes tunnel go slower the larger it is.
998
990
   not drawn, but put into display list. */
999
 
void makecyl(int sides, float zmin, float zmax, float rad, float stretch) {
 
991
static void makecyl(int sides, float zmin, float zmax, float rad, float stretch) 
 
992
{
1000
993
        int i;
1001
994
        float theta;
1002
995
 
1033
1026
        glEnd();
1034
1027
}
1035
1028
 
1036
 
void 
 
1029
ENTRYPOINT void 
1037
1030
init_tunnel (ModeInfo *mi)
1038
1031
{
1039
1032
  int i;
1080
1073
 
1081
1074
  if (wire) {
1082
1075
        glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
1083
 
        do_texture = FALSE;
 
1076
        do_texture = False;
1084
1077
  }
1085
1078
 
1086
1079
  if (do_texture)
1088
1081
          glGenTextures(MAX_TEXTURE, tc->texture_binds);
1089
1082
          
1090
1083
          /*LoadTexture(*mi, **fn, texbind, bluralpha, bw_color,  anegative, onealpha)*/
1091
 
          LoadTexture(mi, timetunnel0_xpm, tc->texture_binds[0], 0, 0.0, FALSE, FALSE);
1092
 
          LoadTexture(mi, timetunnel1_xpm, tc->texture_binds[2], 0, 0.0, FALSE, FALSE);
1093
 
          LoadTexture(mi, timetunnel2_xpm, tc->texture_binds[5], 0, 0.0, FALSE, FALSE);
1094
 
          LoadTexture(mi, tunnelstar_xpm, tc->texture_binds[4], 0, 0.0, FALSE, FALSE);
 
1084
          LoadTexture(mi, timetunnel0_xpm, tc->texture_binds[0], 0, 0.0, False, False);
 
1085
          LoadTexture(mi, timetunnel1_xpm, tc->texture_binds[2], 0, 0.0, False, False);
 
1086
          LoadTexture(mi, timetunnel2_xpm, tc->texture_binds[5], 0, 0.0, False, False);
 
1087
          LoadTexture(mi, tunnelstar_xpm, tc->texture_binds[4], 0, 0.0, False, False);
1095
1088
# ifdef GET_SUED_BY_THE_BBC
1096
1089
          if (locklogo) {
1097
1090
# endif /* GET_SUED_BY_THE_BBC */
1098
 
                LoadTexture(mi, (char **) logo_180_xpm, tc->texture_binds[3],  0,0.0, FALSE, FALSE);
 
1091
                LoadTexture(mi, (char **) logo_180_xpm, tc->texture_binds[3],  0,0.0, False, False);
1099
1092
                tc->texture_binds[1] = tc->texture_binds[3];
1100
1093
                tc->texture_binds[6] = tc->texture_binds[3];
1101
1094
                tc->texture_binds[8] = tc->texture_binds[3];
1102
1095
                /* negative */
1103
 
                LoadTexture(mi, (char **) logo_180_xpm, tc->texture_binds[9],  2,1.0, TRUE, TRUE);
 
1096
                LoadTexture(mi, (char **) logo_180_xpm, tc->texture_binds[9],  2,1.0, True, True);
1104
1097
# ifdef GET_SUED_BY_THE_BBC
1105
1098
         } else {
1106
 
                LoadTexture(mi, whologo_xpm, tc->texture_binds[3],  0,0.0, FALSE, FALSE);
1107
 
                LoadTexture(mi, tardis_xpm, tc->texture_binds[1], 0, 0.0 ,FALSE, FALSE);
1108
 
                LoadTexture(mi, whohead1_xpm, tc->texture_binds[6], 0, 1.0, FALSE, FALSE);
1109
 
                /* LoadTexture(mi, whohead_psy_xpm, tc->texture_binds[8], 1, 0.7, FALSE, FALSE); */
 
1099
                LoadTexture(mi, whologo_xpm, tc->texture_binds[3],  0,0.0, False, False);
 
1100
                LoadTexture(mi, tardis_xpm, tc->texture_binds[1], 0, 0.0 ,False, False);
 
1101
                LoadTexture(mi, whohead1_xpm, tc->texture_binds[6], 0, 1.0, False, False);
 
1102
                /* LoadTexture(mi, whohead_psy_xpm, tc->texture_binds[8], 1, 0.7, False, False); */
1110
1103
                /* negative */
1111
 
                LoadTexture(mi, whohead1_xpm, tc->texture_binds[9], 2, 1.0, TRUE, TRUE);
 
1104
                LoadTexture(mi, whohead1_xpm, tc->texture_binds[9], 2, 1.0, True, True);
1112
1105
          }
1113
1106
# endif /* GET_SUED_BY_THE_BBC */
1114
1107
          glEnable(GL_TEXTURE_2D);
1146
1139
}
1147
1140
 
1148
1141
 
1149
 
void
 
1142
ENTRYPOINT void
1150
1143
draw_tunnel (ModeInfo *mi)
1151
1144
{
1152
1145
  tunnel_configuration *tc = &tconf[MI_SCREEN(mi)];
1157
1150
  if (!tc->glx_context)
1158
1151
    return;
1159
1152
 
 
1153
  glXMakeCurrent(MI_DISPLAY(mi), MI_WINDOW(mi), *(tc->glx_context));
 
1154
 
1160
1155
  glShadeModel(GL_SMOOTH);
1161
1156
 
1162
1157
  glEnable(GL_NORMALIZE);
1188
1183
 
1189
1184
  glEnable(GL_BLEND);
1190
1185
  draw_cyl(mi, tc, tc->effects[6].state[0], 5, tc->diamondlist, 2); 
1191
 
  if (! tunonly)
 
1186
  if (drawlogo)
1192
1187
        draw_sign(mi, tc,tc->effects[12].state[0], tc->effects[12].state[1],  1.0 / 1.33, 9, 1); 
1193
1188
  glDisable(GL_BLEND);
1194
1189
  /* then tardis tunnel */
1200
1195
 
1201
1196
       /*void draw_sign(mi, tc,z,alpha,aspect,tex,blendmode)*/
1202
1197
  /* tardis */
1203
 
  if (! tunonly)
 
1198
  if (drawlogo)
1204
1199
        draw_sign(mi, tc, tc->effects[2].state[0], tc->effects[2].state[1], 2.0, 1, 0);
1205
1200
  /* logo */
1206
 
  if (! tunonly)
 
1201
  if (drawlogo)
1207
1202
        draw_sign(mi, tc, tc->effects[5].state[0], tc->effects[5].state[1], 1.0, 3, 0);
1208
1203
  /*who head brite*/
1209
 
  if (! tunonly)
 
1204
  if (drawlogo)
1210
1205
        draw_sign(mi, tc,1.0, tc->effects[10].state[0],  1.0 / 1.33, 6, 2);
1211
1206
  /*who head psychadelic REMOVED*/
1212
1207
  /* draw_sign(mi, tc,1.0, tc->effects[11].state[0],  1.0 / 1.33, 8, 0); */
1216
1211
  draw_sign(mi, tc,  tc->effects[8].state[0],  tc->effects[8].state[0],  1.0, 4, 1);
1217
1212
 
1218
1213
  /* normal head */
1219
 
  if (! tunonly)
 
1214
  if (drawlogo)
1220
1215
        draw_sign(mi, tc,1.0, tc->effects[9].state[0], 1.0 /  1.33, 6, 0);
1221
1216
 
1222
1217
  /* --- end composite image assembly --- */
1231
1226
  glXSwapBuffers(dpy, window);
1232
1227
}
1233
1228
 
 
1229
XSCREENSAVER_MODULE_2 ("TimeTunnel", timetunnel, tunnel)
 
1230
 
1234
1231
#endif /* USE_GL */