1 /* flyingtoasters, Copyright (c) 2003-2006 Jamie Zawinski <jwz@jwz.org>
3 * Permission to use, copy, modify, distribute, and sell this software and its
4 * documentation for any purpose is hereby granted without fee, provided that
5 * the above copyright notice appear in all copies and that both that
6 * copyright notice and this permission notice appear in supporting
7 * documentation. No representations are made about the suitability of this
8 * software for any purpose. It is provided "as is" without express or
11 * Draws 3D flying toasters, and toast. Inspired by the ancient
12 * Berkeley Systems / After Dark hack, but now updated to the wide
13 * wonderful workd of OpenGL and 3D!
15 * Code by jwz; object models by Baconmonkey.
17 * The original After Dark flying toasters, with the fluffy white wings,
18 * were a trademark of Berkeley Systems. Berkeley Systems ceased to exist
19 * some time in 1998, having been gobbled up by Sierra Online, who were
20 * subsequently gobbled up by Flipside and/or Vivendi (it's hard to tell
21 * exactly what happened when.)
23 * I doubt anyone even cares any more, but if they do, hopefully this homage,
24 * with the space-age 3D jet-plane toasters, will be considered different
25 * enough that whoever still owns the trademark to the fluffy-winged 2D
26 * bitmapped toasters won't get all huffy at us.
29 #define DEFAULTS "*delay: 30000 \n" \
30 "*showFPS: False \n" \
31 "*wireframe: False \n" \
35 # define refresh_toasters 0
36 # define release_toasters 0
38 #define countof(x) (sizeof((x))/sizeof((*x)))
40 #define DEF_SPEED "1.0"
41 #define DEF_NTOASTERS "20"
42 #define DEF_NSLICES "25"
43 #define DEF_TEXTURE "True"
46 #define BELLRAND(n) ((frand((n)) + frand((n)) + frand((n))) / 3)
48 #include "xlockmore.h"
49 #include "gltrackball.h"
50 #include "xpm-ximage.h"
53 #include "../images/chromesphere.xpm"
54 #include "../images/toast.xpm"
56 #ifdef USE_GL /* whole file */
60 extern const struct gllist
61 *toaster, *toaster_base, *toaster_handle, *toaster_handle2, *toaster_jet,
62 *toaster_knob, *toaster_slots, *toaster_wing, *toast, *toast2;
64 static const struct gllist * const *all_objs[] = {
65 &toaster, &toaster_base, &toaster_handle, &toaster_handle2, &toaster_jet,
66 &toaster_knob, &toaster_slots, &toaster_wing, &toast, &toast2
69 #define BASE_TOASTER 0
78 #define TOAST_BITTEN 9
81 #define GRID_DEPTH 500
84 static const struct { GLfloat x, y; } nice_views[] = {
87 { 12, 28 }, /* this is a list of viewer rotations that look nice. */
88 { 12, -28 }, /* every now and then we switch to a new one. */
89 {-10, -28 }, /* (but we only use the first two at start-up.) */
103 int toast_type; /* 0, 1 */
104 GLfloat handle_pos; /* 0.0 - 1.0 */
105 GLfloat knob_pos; /* degrees */
106 int loaded; /* 2 bits */
110 GLXContext *glx_context;
111 trackball_state *user_trackball;
114 int last_view, target_view;
115 GLfloat view_x, view_y;
116 int view_steps, view_tick;
117 Bool auto_tracking_p;
121 GLuint chrome_texture;
122 GLuint toast_texture;
127 } toaster_configuration;
129 static toaster_configuration *bps = NULL;
131 static GLfloat speed;
132 static int ntoasters;
134 static int do_texture;
136 static XrmOptionDescRec opts[] = {
137 { "-speed", ".speed", XrmoptionSepArg, 0 },
138 { "-ntoasters", ".ntoasters", XrmoptionSepArg, 0 },
139 { "-nslices", ".nslices", XrmoptionSepArg, 0 },
140 {"-texture", ".texture", XrmoptionNoArg, "True" },
141 {"+texture", ".texture", XrmoptionNoArg, "False" },
144 static argtype vars[] = {
145 {&speed, "speed", "Speed", DEF_SPEED, t_Float},
146 {&ntoasters, "ntoasters", "Count", DEF_NTOASTERS, t_Int},
147 {&nslices, "nslices", "Count", DEF_NSLICES, t_Int},
148 {&do_texture, "texture", "Texture", DEF_TEXTURE, t_Bool},
151 ENTRYPOINT ModeSpecOpt toasters_opts = {countof(opts), opts, countof(vars), vars, NULL};
155 reset_floater (ModeInfo *mi, floater *f)
157 /* toaster_configuration *bp = &bps[MI_SCREEN(mi)]; */
159 GLfloat n = GRID_SIZE/2.0;
160 GLfloat n2 = GRID_DEPTH/2.0;
161 GLfloat delta = GRID_SIZE * speed / 200.0;
167 f->dz += BELLRAND(delta) - delta/3;
169 if (! (random() % 5)) {
170 f->dx += (BELLRAND(delta*2) - delta);
171 f->dy += (BELLRAND(delta*2) - delta);
174 if (! (random() % 40)) f->dz *= 10; /* occasional speedy one */
176 f->x = frand(n) - n/2;
177 f->y = frand(n) - n/2;
178 f->z = -n2 - frand(delta * 4);
183 f->knob_pos = frand(180) - 90;
184 f->handle_pos = ((random() & 1) ? 0.0 : 1.0);
186 if (f->handle_pos > 0.8 && (! (random() % 5)))
187 f->loaded = (random() & 3); /* let's toast! */
191 if (! (random() % 10))
192 f->toast_type = 1; /* toast_bitten */
198 tick_floater (ModeInfo *mi, floater *f)
200 toaster_configuration *bp = &bps[MI_SCREEN(mi)];
202 GLfloat n1 = GRID_DEPTH/2.0;
203 GLfloat n2 = GRID_SIZE*4;
205 if (bp->button_down_p) return;
211 if (! (random() % 50000)) /* sudden gust of gravity */
214 if (f->x < -n2 || f->x > n2 ||
215 f->y < -n2 || f->y > n2 ||
217 reset_floater (mi, f);
222 auto_track_init (ModeInfo *mi)
224 toaster_configuration *bp = &bps[MI_SCREEN(mi)];
225 bp->last_view = (random() % 2);
226 bp->target_view = bp->last_view + 2;
227 bp->view_x = nice_views[bp->last_view].x;
228 bp->view_y = nice_views[bp->last_view].y;
229 bp->view_steps = 100;
231 bp->auto_tracking_p = True;
236 auto_track (ModeInfo *mi)
238 toaster_configuration *bp = &bps[MI_SCREEN(mi)];
240 if (bp->button_down_p)
243 /* if we're not moving, maybe start moving. Otherwise, do nothing. */
244 if (! bp->auto_tracking_p)
246 if (++bp->track_tick < 200/speed) return;
248 if (! (random() % 5))
249 bp->auto_tracking_p = True;
256 GLfloat ox = nice_views[bp->last_view].x;
257 GLfloat oy = nice_views[bp->last_view].y;
258 GLfloat tx = nice_views[bp->target_view].x;
259 GLfloat ty = nice_views[bp->target_view].y;
261 /* move from A to B with sinusoidal deltas, so that it doesn't jerk
263 GLfloat th = sin ((M_PI / 2) * (double) bp->view_tick / bp->view_steps);
265 bp->view_x = (ox + ((tx - ox) * th));
266 bp->view_y = (oy + ((ty - oy) * th));
269 if (bp->view_tick >= bp->view_steps)
272 bp->view_steps = (350.0 / speed);
273 bp->last_view = bp->target_view;
274 bp->target_view = (random() % (countof(nice_views) - 2)) + 2;
275 bp->auto_tracking_p = False;
281 /* Window management, etc
284 reshape_toasters (ModeInfo *mi, int width, int height)
286 GLfloat h = (GLfloat) height / (GLfloat) width;
288 glViewport (0, 0, (GLint) width, (GLint) height);
290 glMatrixMode(GL_PROJECTION);
292 gluPerspective (40.0, 1/h, 1.0, 250);
294 glMatrixMode(GL_MODELVIEW);
296 gluLookAt( 0.0, 2.0, 30.0,
300 glClear(GL_COLOR_BUFFER_BIT);
305 toasters_handle_event (ModeInfo *mi, XEvent *event)
307 toaster_configuration *bp = &bps[MI_SCREEN(mi)];
309 if (event->xany.type == ButtonPress &&
310 event->xbutton.button == Button1)
312 bp->button_down_p = True;
313 gltrackball_start (bp->user_trackball,
314 event->xbutton.x, event->xbutton.y,
315 MI_WIDTH (mi), MI_HEIGHT (mi));
318 else if (event->xany.type == ButtonRelease &&
319 event->xbutton.button == Button1)
321 bp->button_down_p = False;
324 else if (event->xany.type == ButtonPress &&
325 (event->xbutton.button == Button4 ||
326 event->xbutton.button == Button5 ||
327 event->xbutton.button == Button6 ||
328 event->xbutton.button == Button7))
330 gltrackball_mousewheel (bp->user_trackball, event->xbutton.button, 5,
331 !event->xbutton.state);
334 else if (event->xany.type == MotionNotify &&
337 gltrackball_track (bp->user_trackball,
338 event->xmotion.x, event->xmotion.y,
339 MI_WIDTH (mi), MI_HEIGHT (mi));
348 load_textures (ModeInfo *mi)
350 toaster_configuration *bp = &bps[MI_SCREEN(mi)];
353 xi = xpm_to_ximage (mi->dpy, mi->xgwa.visual, mi->xgwa.colormap,
357 glGenTextures (1, &bp->chrome_texture);
358 glBindTexture (GL_TEXTURE_2D, bp->chrome_texture);
359 glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
360 glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
361 glPixelStorei (GL_UNPACK_ALIGNMENT, 1);
362 glTexImage2D (GL_TEXTURE_2D, 0, GL_RGBA,
363 xi->width, xi->height, 0,
365 /* GL_UNSIGNED_BYTE, */
366 GL_UNSIGNED_INT_8_8_8_8_REV,
368 check_gl_error("texture");
370 xi = xpm_to_ximage (mi->dpy, mi->xgwa.visual, mi->xgwa.colormap,
373 glGenTextures (1, &bp->toast_texture);
374 glBindTexture (GL_TEXTURE_2D, bp->toast_texture);
375 glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
376 glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
377 glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
378 glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
379 glPixelStorei (GL_UNPACK_ALIGNMENT, 1);
380 glTexImage2D (GL_TEXTURE_2D, 0, GL_RGBA,
381 xi->width, xi->height, 0,
383 /* GL_UNSIGNED_BYTE, */
384 GL_UNSIGNED_INT_8_8_8_8_REV,
386 check_gl_error("texture");
388 glEnable(GL_TEXTURE_GEN_S);
389 glEnable(GL_TEXTURE_GEN_T);
390 glEnable(GL_TEXTURE_2D);
395 init_toasters (ModeInfo *mi)
397 toaster_configuration *bp;
398 int wire = MI_IS_WIREFRAME(mi);
402 bps = (toaster_configuration *)
403 calloc (MI_NUM_SCREENS(mi), sizeof (toaster_configuration));
405 fprintf(stderr, "%s: out of memory\n", progname);
409 bp = &bps[MI_SCREEN(mi)];
412 bp = &bps[MI_SCREEN(mi)];
414 bp->glx_context = init_GL(mi);
416 reshape_toasters (mi, MI_WIDTH(mi), MI_HEIGHT(mi));
418 glShadeModel(GL_SMOOTH);
420 glEnable(GL_DEPTH_TEST);
421 glEnable(GL_NORMALIZE);
422 glEnable(GL_CULL_FACE);
426 GLfloat pos[4] = {0.4, 0.2, 0.4, 0.0};
427 /* GLfloat amb[4] = {0.0, 0.0, 0.0, 1.0};*/
428 GLfloat amb[4] = {0.2, 0.2, 0.2, 1.0};
429 GLfloat dif[4] = {1.0, 1.0, 1.0, 1.0};
430 GLfloat spc[4] = {1.0, 1.0, 1.0, 1.0};
432 glEnable(GL_LIGHTING);
434 glEnable(GL_DEPTH_TEST);
435 glEnable(GL_CULL_FACE);
437 glLightfv(GL_LIGHT0, GL_POSITION, pos);
438 glLightfv(GL_LIGHT0, GL_AMBIENT, amb);
439 glLightfv(GL_LIGHT0, GL_DIFFUSE, dif);
440 glLightfv(GL_LIGHT0, GL_SPECULAR, spc);
443 if (!wire && do_texture)
446 bp->user_trackball = gltrackball_init ();
447 auto_track_init (mi);
449 bp->dlists = (GLuint *) calloc (countof(all_objs)+1, sizeof(GLuint));
450 for (i = 0; i < countof(all_objs); i++)
451 bp->dlists[i] = glGenLists (1);
453 for (i = 0; i < countof(all_objs); i++)
455 const struct gllist *gll = *all_objs[i];
457 glNewList (bp->dlists[i], GL_COMPILE);
459 glMatrixMode(GL_MODELVIEW);
461 glMatrixMode(GL_TEXTURE);
463 glMatrixMode(GL_MODELVIEW);
465 glRotatef (-90, 1, 0, 0);
466 glRotatef (180, 0, 0, 1);
469 glBindTexture (GL_TEXTURE_2D, 0);
471 if (i == BASE_TOASTER)
473 GLfloat color[4] = {1.00, 1.00, 1.00, 1.00};
474 GLfloat spec[4] = {1.00, 1.00, 1.00, 1.0};
475 GLfloat shiny = 20.0;
476 glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, color);
477 glMaterialfv (GL_FRONT_AND_BACK, GL_SPECULAR, spec);
478 glMaterialf (GL_FRONT_AND_BACK, GL_SHININESS, shiny);
480 glBindTexture (GL_TEXTURE_2D, bp->chrome_texture);
481 glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
482 glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
484 else if (i == TOAST || i == TOAST_BITTEN)
486 GLfloat color[4] = {0.80, 0.80, 0.00, 1.0};
487 GLfloat spec[4] = {0.00, 0.00, 0.00, 1.0};
489 glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, color);
490 glMaterialfv (GL_FRONT_AND_BACK, GL_SPECULAR, spec);
491 glMaterialf (GL_FRONT_AND_BACK, GL_SHININESS, shiny);
493 glBindTexture (GL_TEXTURE_2D, bp->toast_texture);
494 glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
495 glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
497 glMatrixMode(GL_TEXTURE);
498 glTranslatef(0.5, 0.5, 0);
499 glMatrixMode(GL_MODELVIEW);
501 else if (i == SLOTS || i == HANDLE_SLOT)
503 GLfloat color[4] = {0.30, 0.30, 0.40, 1.0};
504 GLfloat spec[4] = {0.40, 0.40, 0.70, 1.0};
505 GLfloat shiny = 128.0;
506 glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, color);
507 glMaterialfv (GL_FRONT_AND_BACK, GL_SPECULAR, spec);
508 glMaterialf (GL_FRONT_AND_BACK, GL_SHININESS, shiny);
510 else if (i == HANDLE)
512 GLfloat color[4] = {0.80, 0.10, 0.10, 1.0};
513 GLfloat spec[4] = {1.00, 1.00, 1.00, 1.0};
514 GLfloat shiny = 20.0;
515 glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, color);
516 glMaterialfv (GL_FRONT_AND_BACK, GL_SPECULAR, spec);
517 glMaterialf (GL_FRONT_AND_BACK, GL_SHININESS, shiny);
521 GLfloat color[4] = {0.80, 0.10, 0.10, 1.0};
522 GLfloat spec[4] = {0.00, 0.00, 0.00, 1.0};
524 glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, color);
525 glMaterialfv (GL_FRONT_AND_BACK, GL_SPECULAR, spec);
526 glMaterialf (GL_FRONT_AND_BACK, GL_SHININESS, shiny);
528 else if (i == JET || i == JET_WING)
530 GLfloat color[4] = {0.70, 0.70, 0.70, 1.0};
531 GLfloat spec[4] = {1.00, 1.00, 1.00, 1.0};
532 GLfloat shiny = 20.0;
533 glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, color);
534 glMaterialfv (GL_FRONT_AND_BACK, GL_SPECULAR, spec);
535 glMaterialf (GL_FRONT_AND_BACK, GL_SHININESS, shiny);
539 GLfloat color[4] = {0.50, 0.50, 0.50, 1.0};
540 GLfloat spec[4] = {1.00, 1.00, 1.00, 1.0};
541 GLfloat shiny = 20.0;
542 glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, color);
543 glMaterialfv (GL_FRONT_AND_BACK, GL_SPECULAR, spec);
544 glMaterialf (GL_FRONT_AND_BACK, GL_SHININESS, shiny);
548 GLfloat color[4] = {1.00, 1.00, 1.00, 1.00};
549 GLfloat spec[4] = {1.00, 1.00, 1.00, 1.0};
550 GLfloat shiny = 128.0;
551 glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, color);
552 glMaterialfv (GL_FRONT_AND_BACK, GL_SPECULAR, spec);
553 glMaterialf (GL_FRONT_AND_BACK, GL_SHININESS, shiny);
556 renderList (gll, wire);
558 glMatrixMode(GL_TEXTURE);
560 glMatrixMode(GL_MODELVIEW);
566 bp->nfloaters = ntoasters + nslices;
567 bp->floaters = (floater *) calloc (bp->nfloaters, sizeof (floater));
569 for (i = 0; i < bp->nfloaters; i++)
571 floater *f = &bp->floaters[i];
572 /* arrange the list so that half the toasters are in front of bread,
573 and half are behind. */
574 f->toaster_p = ((i < ntoasters / 2) ||
575 (i >= (nslices + (ntoasters / 2))));
576 reset_floater (mi, f);
578 /* Position the first generation randomly, but make sure they aren't
579 on screen yet (until we rotate the view into position.)
582 GLfloat min = -GRID_DEPTH/2;
583 GLfloat max = GRID_DEPTH/3.5;
584 f->z = frand (max - min) + min;
591 draw_origin (ModeInfo *mi)
594 /* toaster_configuration *bp = &bps[MI_SCREEN(mi)];*/
596 if (!MI_IS_WIREFRAME(mi)) glDisable(GL_LIGHTING);
597 if (!MI_IS_WIREFRAME(mi) && do_texture) glDisable(GL_TEXTURE_2D);
602 glVertex3f(-1, 0, 0); glVertex3f(1, 0, 0);
603 glVertex3f(0, -1, 0); glVertex3f(0, 1, 0);
604 glVertex3f(0, 0, -1); glVertex3f(0, 0, 1);
608 if (!MI_IS_WIREFRAME(mi)) glEnable(GL_LIGHTING);
609 if (!MI_IS_WIREFRAME(mi) && do_texture) glEnable(GL_TEXTURE_2D);
615 draw_grid (ModeInfo *mi)
618 /* toaster_configuration *bp = &bps[MI_SCREEN(mi)];*/
620 if (!MI_IS_WIREFRAME(mi)) glDisable(GL_LIGHTING);
621 if (!MI_IS_WIREFRAME(mi) && do_texture) glDisable(GL_TEXTURE_2D);
623 glBegin(GL_LINE_LOOP);
624 glVertex3f(-GRID_SIZE/2, -GRID_SIZE/2, 0);
625 glVertex3f(-GRID_SIZE/2, GRID_SIZE/2, 0);
626 glVertex3f( GRID_SIZE/2, GRID_SIZE/2, 0);
627 glVertex3f( GRID_SIZE/2, -GRID_SIZE/2, 0);
629 glBegin(GL_LINE_LOOP);
630 glVertex3f(-GRID_SIZE/2, GRID_SIZE/2, -GRID_DEPTH/2);
631 glVertex3f(-GRID_SIZE/2, GRID_SIZE/2, GRID_DEPTH/2);
632 glVertex3f( GRID_SIZE/2, GRID_SIZE/2, GRID_DEPTH/2);
633 glVertex3f( GRID_SIZE/2, GRID_SIZE/2, -GRID_DEPTH/2);
635 glBegin(GL_LINE_LOOP);
636 glVertex3f(-GRID_SIZE/2, -GRID_SIZE/2, -GRID_DEPTH/2);
637 glVertex3f(-GRID_SIZE/2, -GRID_SIZE/2, GRID_DEPTH/2);
638 glVertex3f( GRID_SIZE/2, -GRID_SIZE/2, GRID_DEPTH/2);
639 glVertex3f( GRID_SIZE/2, -GRID_SIZE/2, -GRID_DEPTH/2);
642 glVertex3f(-GRID_SIZE/2, -GRID_SIZE/2, -GRID_DEPTH/2);
643 glVertex3f(-GRID_SIZE/2, GRID_SIZE/2, -GRID_DEPTH/2);
644 glVertex3f(-GRID_SIZE/2, -GRID_SIZE/2, GRID_DEPTH/2);
645 glVertex3f(-GRID_SIZE/2, GRID_SIZE/2, GRID_DEPTH/2);
646 glVertex3f( GRID_SIZE/2, -GRID_SIZE/2, -GRID_DEPTH/2);
647 glVertex3f( GRID_SIZE/2, GRID_SIZE/2, -GRID_DEPTH/2);
648 glVertex3f( GRID_SIZE/2, -GRID_SIZE/2, GRID_DEPTH/2);
649 glVertex3f( GRID_SIZE/2, GRID_SIZE/2, GRID_DEPTH/2);
653 if (!MI_IS_WIREFRAME(mi)) glEnable(GL_LIGHTING);
654 if (!MI_IS_WIREFRAME(mi) && do_texture) glEnable(GL_TEXTURE_2D);
660 draw_floater (ModeInfo *mi, floater *f)
662 toaster_configuration *bp = &bps[MI_SCREEN(mi)];
668 glTranslatef (f->x, f->y, f->z);
672 glRotatef (180, 0, 1, 0);
674 glCallList (bp->dlists[BASE_TOASTER]);
675 mi->polygon_count += (*all_objs[BASE_TOASTER])->points / 3;
679 glTranslatef(0, 1.01, 0);
680 n = 0.91; glScalef(n,n,n);
681 glCallList (bp->dlists[SLOTS]);
682 mi->polygon_count += (*all_objs[SLOTS])->points / 3;
686 glRotatef (180, 0, 1, 0);
687 glTranslatef(0, -0.4, -2.38);
688 n = 0.33; glScalef(n,n,n);
689 glCallList (bp->dlists[HANDLE_SLOT]);
690 mi->polygon_count += (*all_objs[HANDLE_SLOT])->points / 3;
694 glTranslatef(0, -1.1, 3);
695 n = 0.3; glScalef (n,n,n);
696 glTranslatef(0, f->handle_pos * 4.8, 0);
697 glCallList (bp->dlists[HANDLE]);
698 mi->polygon_count += (*all_objs[HANDLE])->points / 3;
702 glRotatef (180, 0, 1, 0);
703 glTranslatef(0, -1.1, -3); /* where the handle is */
704 glTranslatef (1, -0.4, 0); /* down and to the left */
705 n = 0.08; glScalef (n,n,n);
706 glRotatef (f->knob_pos, 0, 0, 1);
707 glCallList (bp->dlists[KNOB]);
708 mi->polygon_count += (*all_objs[KNOB])->points / 3;
712 glRotatef (180, 0, 1, 0);
713 glTranslatef (0, -2.3, 0);
714 glCallList (bp->dlists[BASE]);
715 mi->polygon_count += (*all_objs[BASE])->points / 3;
719 glTranslatef(-4.8, 0, 0);
720 glCallList (bp->dlists[JET_WING]);
721 mi->polygon_count += (*all_objs[JET_WING])->points / 3;
722 glScalef (0.5, 0.5, 0.5);
723 glTranslatef (-2, -1, 0);
724 glCallList (bp->dlists[JET]);
725 mi->polygon_count += (*all_objs[JET])->points / 3;
729 glTranslatef(4.8, 0, 0);
732 glCallList (bp->dlists[JET_WING]);
733 mi->polygon_count += (*all_objs[JET_WING])->points / 3;
734 glScalef (0.5, 0.5, 0.5);
735 glTranslatef (-2, -1, 0);
736 glCallList (bp->dlists[JET]);
737 mi->polygon_count += (*all_objs[JET])->points / 3;
744 glTranslatef(0, 1.01, 0);
745 n = 0.91; glScalef(n,n,n);
746 glRotatef (90, 0, 0, 1);
747 glRotatef (90, 0, 1, 0);
748 glTranslatef(0, 0, -0.95);
749 glTranslatef(0, 0.72, 0);
752 glCallList (bp->dlists[TOAST]);
753 mi->polygon_count += (*all_objs[TOAST])->points / 3;
755 glTranslatef(0, -1.46, 0);
758 glCallList (bp->dlists[TOAST]);
759 mi->polygon_count += (*all_objs[TOAST])->points / 3;
766 glScalef (0.7, 0.7, 0.7);
767 if (f->toast_type == 0)
769 glCallList (bp->dlists[TOAST]);
770 mi->polygon_count += (*all_objs[TOAST])->points / 3;
774 glCallList (bp->dlists[TOAST_BITTEN]);
775 mi->polygon_count += (*all_objs[TOAST_BITTEN])->points / 3;
785 draw_toasters (ModeInfo *mi)
787 toaster_configuration *bp = &bps[MI_SCREEN(mi)];
788 Display *dpy = MI_DISPLAY(mi);
789 Window window = MI_WINDOW(mi);
792 if (!bp->glx_context)
795 glXMakeCurrent(MI_DISPLAY(mi), MI_WINDOW(mi), *(bp->glx_context));
797 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
800 glRotatef(bp->view_x, 1, 0, 0);
801 glRotatef(bp->view_y, 0, 1, 0);
802 gltrackball_rotate (bp->user_trackball);
814 F.dx = F.dy = F.dz = 0;
817 if (!MI_IS_WIREFRAME(mi)) glDisable(GL_LIGHTING);
818 if (!MI_IS_WIREFRAME(mi) && do_texture) glDisable(GL_TEXTURE_2D);
820 glVertex3f(-10, 0, 0); glVertex3f(10, 0, 0);
821 glVertex3f(0, -10, 0); glVertex3f(0, 10, 0);
822 glVertex3f(0, 0, -10); glVertex3f(0, 0, 10);
824 if (!MI_IS_WIREFRAME(mi)) glEnable(GL_LIGHTING);
825 if (!MI_IS_WIREFRAME(mi) && do_texture) glEnable(GL_TEXTURE_2D);
827 draw_floater (mi, &F);
829 if (mi->fps_p) do_fps (mi);
831 glXSwapBuffers(dpy, window);
836 glScalef (0.5, 0.5, 0.5);
838 glTranslatef (0, 0, -GRID_DEPTH/2.5);
841 mi->polygon_count = 0;
842 for (i = 0; i < bp->nfloaters; i++)
844 floater *f = &bp->floaters[i];
845 draw_floater (mi, f);
846 tick_floater (mi, f);
852 if (mi->fps_p) do_fps (mi);
855 glXSwapBuffers(dpy, window);
858 XSCREENSAVER_MODULE_2 ("FlyingToasters", flyingtoasters, toasters)