1 /* carousel, Copyright (c) 2005-2018 Jamie Zawinski <jwz@jwz.org>
2 * Loads a sequence of images and rotates them around.
4 * Permission to use, copy, modify, distribute, and sell this software and its
5 * documentation for any purpose is hereby granted without fee, provided that
6 * the above copyright notice appear in all copies and that both that
7 * copyright notice and this permission notice appear in supporting
8 * documentation. No representations are made about the suitability of this
9 * software for any purpose. It is provided "as is" without express or
12 * Created: 21-Feb-2005
15 #if defined(HAVE_COCOA) || defined(HAVE_ANDROID)
16 # define DEF_FONT "OCR A Std 48, Lucida Console 48, Monaco 48"
17 #elif 0 /* real X11, XQueryFont() */
18 # define DEF_FONT "-*-helvetica-bold-r-normal-*-*-480-*-*-*-*-*-*"
19 #else /* real X11, load_font_retry() */
20 # define DEF_FONT "-*-ocr a std-medium-r-*-*-*-480-*-*-m-*-*-*"
23 #define DEF_TITLE_FONT "-*-helvetica-bold-r-normal-*-*-480-*-*-*-*-*-*"
25 #define DEFAULTS "*count: 7 \n" \
27 "*wireframe: False \n" \
28 "*showFPS: False \n" \
29 "*fpsSolid: True \n" \
31 "*font: " DEF_FONT "\n" \
32 "*titleFont: " DEF_TITLE_FONT "\n" \
33 "*desktopGrabber: xscreensaver-getimage -no-desktop %s\n" \
34 "*grabDesktopImages: False \n" \
35 "*chooseRandomImages: True \n"
37 # define free_carousel 0
38 # define release_carousel 0
39 # include "xlockmore.h"
42 #define countof(x) (sizeof((x))/sizeof((*x)))
46 # define DEF_SPEED "1.0"
47 # define DEF_DURATION "20"
48 # define DEF_TITLES "True"
49 # define DEF_ZOOM "True"
50 # define DEF_TILT "XY"
51 # define DEF_MIPMAP "True"
52 # define DEF_DEBUG "False"
55 #include "gltrackball.h"
56 #include "grab-ximage.h"
60 # include <X11/Intrinsic.h> /* for XrmDatabase in -debug mode */
63 /* Should be in <GL/glext.h> */
64 # ifndef GL_TEXTURE_MAX_ANISOTROPY_EXT
65 # define GL_TEXTURE_MAX_ANISOTROPY_EXT 0x84FE
67 # ifndef GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT
68 # define GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT 0x84FF
75 typedef enum { EARLY, NORMAL, LOADING, OUT, IN, DEAD } fade_mode;
76 static int fade_ticks = 60;
79 char *title; /* the filename of this image */
80 int w, h; /* size in pixels of the image */
81 int tw, th; /* size in pixels of the texture */
82 XRectangle geom; /* where in the image the bits are */
88 image current, loading;
89 GLfloat r, theta; /* radius and rotation on the tube */
90 rotator *rot; /* for zoomery */
91 Bool from_top_p; /* whether this image drops in or rises up */
92 time_t expires; /* when this image should be replaced */
93 fade_mode mode; /* in/out animation state */
95 Bool loaded_p; /* whether background load is done */
100 GLXContext *glx_context;
103 trackball_state *trackball;
105 time_t button_down_time;
107 int nframes; /* how many frames are loaded */
109 image_frame **frames; /* pointers to the frames */
111 Bool awaiting_first_images_p;
112 int loads_in_progress;
114 texture_font_data *texfont, *titlefont;
119 int loading_sw, loading_sh;
121 time_t last_time, now;
126 static carousel_state *sss = NULL;
129 /* Command-line arguments
131 static GLfloat speed; /* animation speed scale factor */
132 static int duration; /* reload images after this long */
133 static Bool mipmap_p; /* Use mipmaps instead of single textures. */
134 static Bool titles_p; /* Display image titles. */
135 static Bool zoom_p; /* Throb the images in and out as they spin. */
136 static char *tilt_str;
137 static Bool tilt_x_p; /* Tilt axis towards the viewer */
138 static Bool tilt_y_p; /* Tilt axis side to side */
139 static Bool debug_p; /* Be loud and do weird things. */
142 static XrmOptionDescRec opts[] = {
143 {"-zoom", ".zoom", XrmoptionNoArg, "True" },
144 {"-no-zoom", ".zoom", XrmoptionNoArg, "False" },
145 {"-tilt", ".tilt", XrmoptionSepArg, 0 },
146 {"-no-tilt", ".tilt", XrmoptionNoArg, "" },
147 {"-titles", ".titles", XrmoptionNoArg, "True" },
148 {"-no-titles", ".titles", XrmoptionNoArg, "False" },
149 {"-mipmaps", ".mipmap", XrmoptionNoArg, "True" },
150 {"-no-mipmaps", ".mipmap", XrmoptionNoArg, "False" },
151 {"-duration", ".duration", XrmoptionSepArg, 0 },
152 {"-debug", ".debug", XrmoptionNoArg, "True" },
153 {"-font", ".font", XrmoptionSepArg, 0 },
154 {"-speed", ".speed", XrmoptionSepArg, 0 },
157 static argtype vars[] = {
158 { &mipmap_p, "mipmap", "Mipmap", DEF_MIPMAP, t_Bool},
159 { &debug_p, "debug", "Debug", DEF_DEBUG, t_Bool},
160 { &titles_p, "titles", "Titles", DEF_TITLES, t_Bool},
161 { &zoom_p, "zoom", "Zoom", DEF_ZOOM, t_Bool},
162 { &tilt_str, "tilt", "Tilt", DEF_TILT, t_String},
163 { &speed, "speed", "Speed", DEF_SPEED, t_Float},
164 { &duration, "duration", "Duration", DEF_DURATION, t_Int},
167 ENTRYPOINT ModeSpecOpt carousel_opts = {countof(opts), opts, countof(vars), vars, NULL};
170 /* Allocates a frame structure and stores it in the list.
173 alloc_frame (ModeInfo *mi)
175 carousel_state *ss = &sss[MI_SCREEN(mi)];
176 image_frame *frame = (image_frame *) calloc (1, sizeof (*frame));
180 frame->rot = make_rotator (0, 0, 0, 0, 0.04 * frand(1.0) * speed, False);
182 glGenTextures (1, &frame->current.texid);
183 glGenTextures (1, &frame->loading.texid);
184 if (frame->current.texid <= 0) abort();
185 if (frame->loading.texid <= 0) abort();
187 if (ss->frames_size <= ss->nframes)
189 ss->frames_size = (ss->frames_size * 1.2) + ss->nframes;
190 ss->frames = (image_frame **)
191 realloc (ss->frames, ss->frames_size * sizeof(*ss->frames));
194 fprintf (stderr, "%s: out of memory (%d images)\n",
195 progname, ss->frames_size);
200 ss->frames[ss->nframes++] = frame;
206 static void image_loaded_cb (const char *filename, XRectangle *geom,
207 int image_width, int image_height,
208 int texture_width, int texture_height,
212 /* Load a new file into the given image struct.
215 load_image (ModeInfo *mi, image_frame *frame)
217 carousel_state *ss = &sss[MI_SCREEN(mi)];
218 int wire = MI_IS_WIREFRAME(mi);
220 if (debug_p && !wire && frame->current.w != 0)
221 fprintf (stderr, "%s: dropped %4d x %-4d %4d x %-4d \"%s\"\n",
223 frame->current.geom.width,
224 frame->current.geom.height,
225 frame->current.tw, frame->current.th,
226 (frame->current.title ? frame->current.title : "(null)"));
231 case NORMAL: frame->mode = LOADING; break;
235 ss->loads_in_progress++;
238 image_loaded_cb (0, 0, 0, 0, 0, 0, frame);
241 int w = (MI_WIDTH(mi) / 2) - 1;
242 int h = (MI_HEIGHT(mi) / 2) - 1;
246 if (w > h * 5) { /* tiny window: use 16:9 boxes */
250 load_texture_async (mi->xgwa.screen, mi->window, *ss->glx_context, w, h,
251 mipmap_p, frame->loading.texid,
252 image_loaded_cb, frame);
257 /* Callback that tells us that the texture has been loaded.
260 image_loaded_cb (const char *filename, XRectangle *geom,
261 int image_width, int image_height,
262 int texture_width, int texture_height,
265 image_frame *frame = (image_frame *) closure;
266 ModeInfo *mi = frame->mi;
267 carousel_state *ss = &sss[MI_SCREEN(mi)];
268 int wire = MI_IS_WIREFRAME(mi);
272 frame->loading.w = MI_WIDTH (mi) * (0.5 + frand (1.0));
273 frame->loading.h = MI_HEIGHT (mi);
274 frame->loading.geom.width = frame->loading.w;
275 frame->loading.geom.height = frame->loading.h;
279 if (image_width == 0 || image_height == 0)
282 glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
283 glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
284 mipmap_p ? GL_LINEAR_MIPMAP_LINEAR : GL_LINEAR);
286 if (ss->anisotropic >= 1.0)
287 glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT,
290 glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
291 glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
293 frame->loading.w = image_width;
294 frame->loading.h = image_height;
295 frame->loading.tw = texture_width;
296 frame->loading.th = texture_height;
297 frame->loading.geom = *geom;
299 if (frame->loading.title)
300 free (frame->loading.title);
301 frame->loading.title = (filename ? strdup (filename) : 0);
303 /* xscreensaver-getimage returns paths relative to the image directory
304 now, so leave the sub-directory part in. Unless it's an absolute path.
306 if (frame->loading.title && frame->loading.title[0] == '/')
307 { /* strip filename to part after last /. */
308 char *s = strrchr (frame->loading.title, '/');
309 if (s) strcpy (frame->loading.title, s+1);
313 fprintf (stderr, "%s: loaded %4d x %-4d %4d x %-4d \"%s\"\n",
315 frame->loading.geom.width,
316 frame->loading.geom.height,
317 frame->loading.tw, frame->loading.th,
318 (frame->loading.title ? frame->loading.title : "(null)"));
322 frame->loaded_p = True;
324 if (ss->loads_in_progress <= 0) abort();
325 ss->loads_in_progress--;
327 /* This image expires N seconds after it finished loading. */
328 frame->expires = time((time_t *) 0) + (duration * MI_COUNT(mi));
332 case EARLY: /* part of the initial batch of images */
334 image swap = frame->current;
335 frame->current = frame->loading;
336 frame->loading = swap;
339 case LOADING: /* start dropping the old image out */
342 frame->mode_tick = fade_ticks / speed;
343 frame->from_top_p = random() & 1;
352 static void loading_msg (ModeInfo *mi, int n);
355 load_initial_images (ModeInfo *mi)
357 carousel_state *ss = &sss[MI_SCREEN(mi)];
359 Bool all_loaded_p = True;
360 for (i = 0; i < ss->nframes; i++)
361 if (! ss->frames[i]->loaded_p)
362 all_loaded_p = False;
366 if (ss->nframes < MI_COUNT (mi))
368 /* The frames currently on the list are fully loaded.
369 Start the next one loading. (We run the image loader
370 asynchronously, but we load them one at a time.)
372 load_image (mi, alloc_frame (mi));
376 /* The first batch of images are now all loaded!
377 Stagger the expire times so that they don't all drop out at once.
379 time_t now = time((time_t *) 0);
382 for (i = 0; i < ss->nframes; i++)
384 image_frame *frame = ss->frames[i];
386 frame->theta = i * 360.0 / ss->nframes;
387 frame->expires = now + (duration * (i + 1));
388 frame->mode = NORMAL;
391 /* Instead of always going clockwise, shuffle the expire times
392 of the frames so that they drop out in a random order.
394 for (i = 0; i < ss->nframes; i++)
396 image_frame *frame1 = ss->frames[i];
397 image_frame *frame2 = ss->frames[random() % ss->nframes];
398 time_t swap = frame1->expires;
399 frame1->expires = frame2->expires;
400 frame2->expires = swap;
403 ss->awaiting_first_images_p = False;
407 loading_msg (mi, ss->nframes-1);
409 return !ss->awaiting_first_images_p;
414 reshape_carousel (ModeInfo *mi, int width, int height)
416 GLfloat h = (GLfloat) height / (GLfloat) width;
419 if (width > height * 5) { /* tiny window: show middle */
420 height = width * 9/16;
422 h = height / (GLfloat) width;
425 glViewport (0, y, (GLint) width, (GLint) height);
427 glMatrixMode(GL_PROJECTION);
429 gluPerspective (60.0, 1/h, 1.0, 8.0);
431 glMatrixMode(GL_MODELVIEW);
433 gluLookAt( 0.0, 0.0, 2.6,
437 glClear(GL_COLOR_BUFFER_BIT);
442 carousel_handle_event (ModeInfo *mi, XEvent *event)
444 carousel_state *ss = &sss[MI_SCREEN(mi)];
446 if (event->xany.type == ButtonPress &&
447 event->xbutton.button == Button1)
449 if (! ss->button_down_p)
450 ss->button_down_time = time((time_t *) 0);
452 else if (event->xany.type == ButtonRelease &&
453 event->xbutton.button == Button1)
455 if (ss->button_down_p)
457 /* Add the time the mouse was held to the expire times of all
458 frames, so that mouse-dragging doesn't count against
461 int secs = time((time_t *) 0) - ss->button_down_time;
463 for (i = 0; i < ss->nframes; i++)
464 ss->frames[i]->expires += secs;
468 if (gltrackball_event_handler (event, ss->trackball,
469 MI_WIDTH (mi), MI_HEIGHT (mi),
472 else if (screenhack_event_helper (MI_DISPLAY(mi), MI_WINDOW(mi), event))
474 int i = random() % ss->nframes;
475 ss->frames[i]->expires = 0;
483 /* Kludge to add "-v" to invocation of "xscreensaver-getimage" in -debug mode
486 hack_resources (Display *dpy)
489 char *res = "desktopGrabber";
490 char *val = get_string_resource (dpy, res, "DesktopGrabber");
494 XrmDatabase db = XtDatabase (dpy);
495 sprintf (buf1, "%.100s.%.100s", progname, res);
496 sprintf (buf2, "%.200s -v", val);
498 value.size = strlen(buf2);
499 XrmPutResource (&db, buf1, "String", &value);
500 # endif /* !HAVE_JWXYZ */
505 loading_msg (ModeInfo *mi, int n)
507 carousel_state *ss = &sss[MI_SCREEN(mi)];
508 int wire = MI_IS_WIREFRAME(mi);
514 sprintf (text, "Loading images...");
516 sprintf (text, "Loading images... (%d%%)",
517 (int) (n * 100 / MI_COUNT(mi)));
519 if (ss->loading_sw == 0)
521 /* only do this once, so that the string doesn't move. */
523 texture_string_metrics (ss->titlefont, text, &e, 0, 0);
524 ss->loading_sw = e.width;
525 ss->loading_sh = e.ascent + e.descent;
528 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
530 glMatrixMode(GL_PROJECTION);
534 glMatrixMode(GL_MODELVIEW);
540 double rot = current_device_rotation();
541 glRotatef(rot, 0, 0, 1);
542 if ((rot > 45 && rot < 135) ||
543 (rot < -45 && rot > -135))
545 GLfloat s = MI_WIDTH(mi) / (GLfloat) MI_HEIGHT(mi);
546 glScalef (s, 1/s, 1);
552 if (MI_WIDTH(mi) < MI_HEIGHT(mi)) /* portrait orientation */
554 GLfloat s = (MI_WIDTH(mi) / (GLfloat) MI_HEIGHT(mi));
556 glTranslatef(-s/2, 0, 0);
560 glOrtho(0, MI_WIDTH(mi), 0, MI_HEIGHT(mi), -1, 1);
561 glTranslatef ((MI_WIDTH(mi) - ss->loading_sw) / 2,
562 (MI_HEIGHT(mi) - ss->loading_sh) / 2,
565 glEnable (GL_TEXTURE_2D);
566 glDisable (GL_DEPTH_TEST);
567 print_texture_string (ss->titlefont, text);
568 glEnable (GL_DEPTH_TEST);
571 glMatrixMode(GL_PROJECTION);
574 glMatrixMode(GL_MODELVIEW);
577 glXSwapBuffers (MI_DISPLAY (mi), MI_WINDOW(mi));
582 init_carousel (ModeInfo *mi)
584 int screen = MI_SCREEN(mi);
586 int wire = MI_IS_WIREFRAME(mi);
591 if ((ss->glx_context = init_GL(mi)) != NULL) {
592 reshape_carousel (mi, MI_WIDTH(mi), MI_HEIGHT(mi));
593 clear_gl_error(); /* WTF? sometimes "invalid op" from glViewport! */
598 if (!tilt_str || !*tilt_str)
600 else if (!strcasecmp (tilt_str, "0"))
602 else if (!strcasecmp (tilt_str, "X"))
604 else if (!strcasecmp (tilt_str, "Y"))
606 else if (!strcasecmp (tilt_str, "XY"))
607 tilt_x_p = tilt_y_p = 1;
610 fprintf (stderr, "%s: tilt must be 'X', 'Y', 'XY' or '', not '%s'\n",
616 double spin_speed = speed * 0.2; /* rotation of tube around axis */
617 double spin_accel = speed * 0.1;
618 double wander_speed = speed * 0.001; /* tilting of axis */
620 spin_speed *= 0.9 + frand(0.2);
621 wander_speed *= 0.9 + frand(0.2);
623 ss->rot = make_rotator (spin_speed, spin_speed, spin_speed,
624 spin_accel, wander_speed, True);
626 ss->trackball = gltrackball_init (False);
629 if (strstr ((char *) glGetString(GL_EXTENSIONS),
630 "GL_EXT_texture_filter_anisotropic"))
631 glGetFloatv (GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &ss->anisotropic);
633 ss->anisotropic = 0.0;
635 glDisable (GL_LIGHTING);
636 glEnable (GL_DEPTH_TEST);
637 glDisable (GL_CULL_FACE);
641 glShadeModel (GL_SMOOTH);
642 glEnable (GL_LINE_SMOOTH);
643 /* This gives us a transparent diagonal slice through each image! */
644 /* glEnable (GL_POLYGON_SMOOTH); */
645 glHint (GL_LINE_SMOOTH_HINT, GL_NICEST);
647 glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
648 glEnable (GL_ALPHA_TEST);
650 glEnable (GL_POLYGON_OFFSET_FILL);
651 glPolygonOffset (1.0, 1.0);
655 ss->texfont = load_texture_font (MI_DISPLAY(mi), "font");
656 ss->titlefont = load_texture_font (MI_DISPLAY(mi), "titleFont");
659 hack_resources (MI_DISPLAY (mi));
662 ss->frames_size = 10;
663 ss->frames = (image_frame **)
664 calloc (1, ss->frames_size * sizeof(*ss->frames));
667 ss->mode_tick = fade_ticks / speed;
669 ss->awaiting_first_images_p = True;
674 draw_frame (ModeInfo *mi, image_frame *frame, time_t now, Bool body_p)
676 carousel_state *ss = &sss[MI_SCREEN(mi)];
677 int wire = MI_IS_WIREFRAME(mi);
679 GLfloat texw = frame->current.geom.width / (GLfloat) frame->current.tw;
680 GLfloat texh = frame->current.geom.height / (GLfloat) frame->current.th;
681 GLfloat texx1 = frame->current.geom.x / (GLfloat) frame->current.tw;
682 GLfloat texy1 = frame->current.geom.y / (GLfloat) frame->current.th;
683 GLfloat texx2 = texx1 + texw;
684 GLfloat texy2 = texy1 + texh;
685 GLfloat aspect = ((GLfloat) frame->current.geom.height /
686 (GLfloat) frame->current.geom.width);
688 glBindTexture (GL_TEXTURE_2D, frame->current.texid);
692 /* Position this image on the wheel.
694 glRotatef (frame->theta, 0, 1, 0);
695 glTranslatef (0, 0, frame->r);
697 /* Scale down the image so that all N frames fit on the wheel
698 without bumping in to each other.
704 case 1: t = -1.0; s = 1.7; break;
705 case 2: t = -0.8; s = 1.6; break;
706 case 3: t = -0.4; s = 1.5; break;
707 case 4: t = -0.2; s = 1.3; break;
708 default: t = 0.0; s = 6.0 / ss->nframes; break;
710 glTranslatef (0, 0, t);
714 /* Center this image on the wheel plane.
716 glTranslatef (-0.5, -(aspect/2), 0);
718 /* Move as per the "zoom in and out" setting.
723 /* Only use the Z component of the rotator for in/out position. */
724 get_position (frame->rot, &x, &y, &z, !ss->button_down_p);
725 glTranslatef (0, 0, z/2);
728 /* Compute the "drop in and out" state.
736 if (!ss->button_down_p &&
737 now >= frame->expires &&
738 ss->loads_in_progress == 0) /* only load one at a time */
739 load_image (mi, frame);
744 if (--frame->mode_tick <= 0) {
745 image swap = frame->current;
746 frame->current = frame->loading;
747 frame->loading = swap;
750 frame->mode_tick = fade_ticks / speed;
754 if (--frame->mode_tick <= 0)
755 frame->mode = NORMAL;
761 /* Now translate for current in/out state.
763 if (frame->mode == OUT || frame->mode == IN)
765 GLfloat t = (frame->mode == OUT
766 ? frame->mode_tick / (fade_ticks / speed)
767 : (((fade_ticks / speed) - frame->mode_tick + 1) /
768 (fade_ticks / speed)));
770 if (frame->from_top_p) t = -t;
771 glTranslatef (0, t, 0);
774 if (body_p) /* Draw the image quad. */
779 glNormal3f (0, 0, 1);
780 glEnable (GL_TEXTURE_2D);
782 glNormal3f (0, 0, 1);
783 glTexCoord2f (texx1, texy2); glVertex3f (0, 0, 0);
784 glTexCoord2f (texx2, texy2); glVertex3f (1, 0, 0);
785 glTexCoord2f (texx2, texy1); glVertex3f (1, aspect, 0);
786 glTexCoord2f (texx1, texy1); glVertex3f (0, aspect, 0);
790 /* Draw a box around it.
793 glColor3f (0.5, 0.5, 0.5);
794 glDisable (GL_TEXTURE_2D);
795 glBegin (GL_LINE_LOOP);
796 glVertex3f (0, 0, 0);
797 glVertex3f (1, 0, 0);
798 glVertex3f (1, aspect, 0);
799 glVertex3f (0, aspect, 0);
803 else /* Draw a title under the image. */
807 GLfloat scale = 0.05;
808 char *title = frame->current.title ? frame->current.title : "(untitled)";
809 texture_string_metrics (ss->texfont, title, &e, 0, 0);
811 sh = e.ascent + e.descent;
813 glTranslatef (0, -scale, 0);
816 glScalef (scale, scale, scale);
818 glTranslatef (((1/scale) - sw) / 2, 0, 0);
823 glEnable (GL_TEXTURE_2D);
824 print_texture_string (ss->texfont, title);
828 glBegin (GL_LINE_LOOP);
829 glVertex3f (0, 0, 0);
830 glVertex3f (sw, 0, 0);
831 glVertex3f (sw, sh, 0);
832 glVertex3f (0, sh, 0);
842 draw_carousel (ModeInfo *mi)
844 carousel_state *ss = &sss[MI_SCREEN(mi)];
847 if (!ss->glx_context)
850 glXMakeCurrent(MI_DISPLAY(mi), MI_WINDOW(mi), *(ss->glx_context));
852 if (ss->awaiting_first_images_p)
853 if (!load_initial_images (mi))
856 /* Only check the wall clock every 10 frames */
858 if (ss->now == 0 || ss->draw_tick++ > 10)
860 ss->now = time((time_t *) 0);
861 if (ss->last_time == 0) ss->last_time = ss->now;
867 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
871 glRotatef(current_device_rotation(), 0, 0, 1);
874 /* Run the startup "un-shrink" animation.
879 if (--ss->mode_tick <= 0)
882 ss->last_time = time((time_t *) 0);
892 /* Scale as per the startup "un-shrink" animation.
894 if (ss->mode != NORMAL)
896 GLfloat s = (ss->mode == OUT
897 ? ss->mode_tick / (fade_ticks / speed)
898 : (((fade_ticks / speed) - ss->mode_tick + 1) /
899 (fade_ticks / speed)));
903 /* Rotate and tilt as per the user, and the motion modeller.
907 gltrackball_rotate (ss->trackball);
909 /* Tilt the tube up or down by up to 30 degrees */
910 get_position (ss->rot, &x, &y, &z, !ss->button_down_p);
912 glRotatef (15 - (x * 30), 1, 0, 0);
914 glRotatef (7 - (y * 14), 0, 0, 1);
916 /* Only use the Y component of the rotator. */
917 get_rotation (ss->rot, &x, &y, &z, !ss->button_down_p);
918 glRotatef (y * 360, 0, 1, 0);
921 /* First draw each image, then draw the titles. GL insists that you
922 draw back-to-front in order to make alpha blending work properly,
923 so we need to draw all of the 100% opaque images before drawing
924 any of the not-100%-opaque titles.
926 for (i = 0; i < ss->nframes; i++)
927 draw_frame (mi, ss->frames[i], ss->now, True);
929 for (i = 0; i < ss->nframes; i++)
930 draw_frame (mi, ss->frames[i], ss->now, False);
934 if (mi->fps_p) do_fps (mi);
936 glXSwapBuffers (MI_DISPLAY (mi), MI_WINDOW(mi));
939 XSCREENSAVER_MODULE ("Carousel", carousel)