~ubuntu-branches/ubuntu/quantal/xscreensaver/quantal

« back to all changes in this revision

Viewing changes to hacks/glx/gleidescope.c

  • Committer: Bazaar Package Importer
  • Author(s): Ted Gould
  • Date: 2008-08-28 16:15:25 UTC
  • mfrom: (1.1.6 upstream) (2.1.3 lenny)
  • Revision ID: james.westby@ubuntu.com-20080828161525-mxga521aoezxjq8h
Tags: 5.07-0ubuntu1
* Upgrade upstream version
* debian/control: Remove suggest xdaliclock as it is no longer
  included
* Remove 10_jwz-screensaver-randr-patch-3.patch as it has been merged
  upstream.
* Add 24_hacks_xsublim_enable.patch as it seems that xsublim was dropped
  from the build files.  There is nothing in the Changelog about it
  so I believe it was accidental.
* Updating the .desktop files from the XML files using gnome-screensaver's
  utility to do so.  Lots of text updates.  Also:
    * Added: abstractile.desktop
    * Added: cwaves.desktop
    * Added: m6502.desktop
    * Added: skytentacles.desktop
    * Removed: xteevee.desktop
* xscreensaver-gl-extra.files: Added skytentacles
* xscreensaver-data-extra.files: Added abstractile, cwaves and m6502
* xscreensaver-data.files: Remove partial abstractile, m6502 and cwaves

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* -*- Mode: C; tab-width: 4 -*- */
 
2
/* vim: set ai ts=4 sw=4: */
2
3
 
3
4
#if !defined( lint ) && !defined( SABER )
4
5
/*static const char sccsid[] = "@(#)gleidescope.c       1.0 03/06/27 xlockmore";*/
5
6
#endif
6
7
 
7
 
/* enable -grab switch */
8
 
/*#define       GRAB*/
 
8
/* enable -grab switch for animations */
 
9
#undef  GRAB
 
10
 
 
11
#undef DISPLAY_TEXTURE
9
12
 
10
13
/*-
11
14
 * Permission to use, copy, modify, and distribute this software and its
40
43
 *                                                                      no preference is given.
41
44
 *                                                              Made grid slightly bigger so you can't see
42
45
 *                                                                      the edge when zooming and moving.
 
46
 *      20061226        1.4             acd             Now uses GL Display Lists.
 
47
 *      20070318        1.5             acd             Generates textures.
 
48
 *                                                              Fixed texture size problem (and introduced another).
 
49
 *      20070412        1.6             acd             Textures now have independant sizes.
 
50
 *      20070413        1.7             acd             Added Lissajous movement pattern.
 
51
 *      20070414        1.8             acd             Added corners movement pattern.
 
52
 *      20080319        1.9             acd             Changes to arguments for saner gleidescope.xml.
 
53
 *
 
54
 * TODO
 
55
 * generate textures myself - render random shapes to 256x256 texture. (done)
 
56
 * lower res for checks and random - use 256 and 4x4 or 8x8 pixels. (disabled for now)
 
57
 * gnome-saver doesn't let you specify source directory so add that to this.
 
58
 * image loading routine is too slow - rotation grinds to a halt - stop using it. (better in version 5)
 
59
 * image loading also looks bad for non-square images - edges are black. (fixed)
 
60
 * possible to see edge of the world on widescreen terminals - use larger grid and hidden hex removal?
 
61
 * fading textures may have different max_tx - use two sets. (done)
 
62
 * choice of movement patterns. (3 implemented, chooseable at compile time)
 
63
 * look into rangle and tangle.
43
64
 */
44
65
 
45
66
/*
52
73
# define DEFAULTS \
53
74
                "*delay:                20000           \n"     \
54
75
                "*showFPS:              False           \n"     \
55
 
                "*size:                 -1                      \n"     \
 
76
                "*size:                 0                       \n"     \
56
77
                "*useSHM:               True            \n"
57
78
 
58
79
# define refresh_gleidescope 0
67
88
#include "xpm-ximage.h"
68
89
#include "grab-ximage.h"
69
90
 
 
91
#ifdef GRAB
 
92
void grab_frame(Display *display, Window window);
 
93
#endif
 
94
 
70
95
/* acd TODO should all these be in gleidestruct? */
71
96
/* they can't be, because of the idiotic way the xlockmore "argtype vars"
72
97
   interface works. -jwz */
82
107
static char             *image;                 /* name of texture to load */
83
108
static int              duration;               /* length of time to display grabbed image */
84
109
 
85
 
#define MAX_TANGLE_VEL  2.0
86
 
#define MAX_RANGLE_VEL  1.5
 
110
#define MAX_CAM_SPEED                   1.0
 
111
#define MAX_ANGLE_VEL                   1.0
 
112
#define INITIAL_ANGLE_VEL               0.2
 
113
#define INITIAL_ANGLE_ACC               0.001
 
114
#define TWISTING_PROBABILITY    1000    /* 1 in ... of change of acceleration */
 
115
 
 
116
#define RADIANS (M_PI / 180)
 
117
#define ANGLE_120       (M_PI * 2 / 3)
 
118
#define ANGLE_240       (M_PI * 4 / 3)
 
119
 
 
120
#define DEF_GRAB        "False"
 
121
#define DEF_MOVE        "False"
 
122
#define DEF_NOMOVE      "False"
 
123
#define DEF_ROTATE      "False"
 
124
#define DEF_NOROTATE    "False"
 
125
#define DEF_ZOOM        "False"
 
126
#define DEF_NOZOOM      "False"
 
127
#define DEF_IMAGE       "DEFAULT"
 
128
#define DEF_DURATION    "30"
 
129
 
87
130
 
88
131
static XrmOptionDescRec opts[] =
89
132
{
94
137
        {"-no-move",    ".gleidescope.nomove",          XrmoptionNoArg,         "true"},
95
138
        {"-rotate",             ".gleidescope.rotate",          XrmoptionNoArg,         "true"},
96
139
        {"-no-rotate",  ".gleidescope.norotate",        XrmoptionNoArg,         "true"},
97
 
        /*{"-size",             ".gleidescope.size",            XrmoptionNoArg,         "-1"},*/
98
140
        {"-zoom",               ".gleidescope.zoom",            XrmoptionNoArg,         "true"},
99
141
        {"-no-zoom",    ".gleidescope.nozoom",          XrmoptionNoArg,         "true"},
100
142
        {"-image",              ".gleidescope.image",           XrmoptionSepArg,        "DEFAULT"},
104
146
 
105
147
static argtype vars[] = {
106
148
#ifdef GRAB
107
 
        {&grab,                 "grab",         "Grab",         "False",        t_Bool},
 
149
        {&grab,                 "grab",         "Grab",         DEF_GRAB,       t_Bool},
108
150
#endif
109
 
        {&move,                 "move",         "Move",         "False",        t_Bool},
110
 
        {&nomove,               "nomove",       "noMove",       "False",        t_Bool},
111
 
        {&rotate,               "rotate",       "Rotate",       "False",        t_Bool},
112
 
        {&norotate,             "norotate",     "noRotate",     "False",        t_Bool},
113
 
        /*{&size,               "size",         "Size",         "-1",           t_Int},*/
114
 
        {&zoom,                 "zoom",         "Zoom",         "False",        t_Bool},
115
 
        {&nozoom,               "nozoom",       "noZoom",       "False",        t_Bool},
116
 
        {&image,                "image",        "Image",        "DEFAULT",      t_String},
117
 
        {&duration,             "duration",     "Duration",     "30",           t_Int},
 
151
        {&move,                 "move",         "Move",         DEF_MOVE,       t_Bool},
 
152
        {&nomove,               "nomove",       "noMove",       DEF_NOMOVE,     t_Bool},
 
153
        {&rotate,               "rotate",       "Rotate",       DEF_ROTATE,     t_Bool},
 
154
        {&norotate,             "norotate",     "noRotate",     DEF_NOROTATE,   t_Bool},
 
155
        {&zoom,                 "zoom",         "Zoom",         DEF_ZOOM,       t_Bool},
 
156
        {&nozoom,               "nozoom",       "noZoom",       DEF_NOZOOM,     t_Bool},
 
157
        {&image,                "image",        "Image",        DEF_IMAGE,      t_String},
 
158
        {&duration,             "duration",     "Duration",     DEF_DURATION,           t_Int},
118
159
};
119
160
 
120
161
static OptionStruct desc[] = {
125
166
        {"-no-move",    "camera won't move"},
126
167
        {"-rotate",             "camera will rotate"},
127
168
        {"-no-rotate",  "camera won't rotate"},
128
 
        /*{"-size",             "size of the hexagons (1-10)"},*/
129
169
        {"-zoom",               "camera will zoom"},
130
170
        {"-no-zoom",    "camera won't zoom"},
131
171
        {"-image",              "xpm / xbm image file to use for texture"},
162
202
        GLfloat z;
163
203
} vectorf;
164
204
 
 
205
typedef struct {
 
206
        GLfloat x;
 
207
        GLfloat y;
 
208
} vector2f;
 
209
 
 
210
typedef struct {
 
211
        GLuint                  id;                             /* opengl texture id */
 
212
        GLfloat                 width, height;  /* texture width and height */
 
213
        GLfloat                 min_tx, min_ty; /* minimum texture sizes */
 
214
        GLfloat                 max_tx, max_ty; /* maximum texture sizes */
 
215
        time_t                  start_time;
 
216
        Bool                    button_down_p;
 
217
    Bool                        mipmap_p;
 
218
    Bool                        waiting_for_image_p;
 
219
        /* r_phase is for triangle rotation speed */
 
220
        GLfloat                 x_period, y_period, r_period;
 
221
        GLfloat                 x_phase, y_phase, r_phase;
 
222
} texture;
 
223
 
165
224
#define MAX_FADE        500     /* number of fade cycles */
166
225
 
167
226
typedef struct {
170
229
        float                   tic;
171
230
        GLXContext              *glx_context;
172
231
        Window                  window;
173
 
        GLfloat                 max_tx, max_ty; /* maximum texture sizes */
174
 
        GLuint                  textures[2];    /* texture handles */
175
 
        GLuint                  visible;                /* texture handle for new texture */
 
232
        texture                 textures[2];    /* texture handles */
 
233
        GLuint                  visible;                /* index for current texture */
176
234
        GLint                   fade;
177
235
        time_t                  start_time;
178
236
        Bool                    button_down_p;
179
237
 
180
238
    int         size;
 
239
        int             list;
181
240
 
182
 
    float       tangle;         /* texture angle */
 
241
    float       tangle;         /* texture angle (degrees) */
183
242
    float       tangle_vel;     /* texture velocity */
184
243
    float       tangle_acc;     /* texture acceleration */
185
244
 
198
257
 
199
258
} gleidestruct;
200
259
 
 
260
#define frandrange(x, y)        (x + frand(y - x))
 
261
 
201
262
#define XOFFSET (0.8660254f)    /* sin 60' */
202
263
#define YOFFSET (1.5000000f)    /* cos 60' + 1 */
203
264
 
231
292
}
232
293
#endif
233
294
 
 
295
/* acd - this is terrible - 120+ hexes */
234
296
static const hex_t hex[] = {
235
297
        /* edges of size 7 */
236
298
        /* number of hexagons required to cover screen depends on camera distance */
474
536
                 int texture_width, int texture_height,
475
537
                 void *closure)
476
538
{
477
 
  gleidestruct *gp = (gleidestruct *) closure;
478
 
 
479
 
  gp->max_tx = (GLfloat) image_width  / texture_width;
480
 
  gp->max_ty = (GLfloat) image_height / texture_height;
481
 
 
482
 
  glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
483
 
  glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
484
 
                   (gp->mipmap_p ? GL_LINEAR_MIPMAP_LINEAR : GL_LINEAR));
485
 
 
486
 
  gp->waiting_for_image_p = False;
487
 
  gp->start_time = time ((time_t *) 0);
 
539
        texture *tp = (texture *) closure;
 
540
 
 
541
#if 0
 
542
        gp->max_tx = (GLfloat) image_width  / texture_width;
 
543
        gp->max_ty = (GLfloat) image_height / texture_height;
 
544
#endif
 
545
 
 
546
        /* new - taken from flipscreen */
 
547
        tp->width = texture_width;
 
548
        tp->height = texture_height;
 
549
        tp->min_tx = (GLfloat) geometry->x / tp->width;
 
550
        tp->min_ty = (GLfloat) geometry->y / tp->height;
 
551
        tp->max_tx = (GLfloat) (geometry->x + geometry->width)  / tp->width;
 
552
        tp->max_ty = (GLfloat) (geometry->y + geometry->height) / tp->height;
 
553
 
 
554
#ifdef DEBUG
 
555
        printf("Image w,h: (%d, %d)\n", image_width, image_height);
 
556
        printf("Texture w,h: (%d, %d)\n", texture_width, texture_height);
 
557
        printf("Geom x,y: (%d, %d)\n", geometry->x, geometry->y);
 
558
        printf("Geom w,h: (%d, %d)\n", geometry->width, geometry->height);
 
559
        printf("Max Tx,Ty: (%f, %f)\n", tp->max_tx, tp->max_ty);
 
560
#endif
 
561
 
 
562
        glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
 
563
        glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
 
564
                        (tp->mipmap_p ? GL_LINEAR_MIPMAP_LINEAR : GL_LINEAR));
 
565
 
 
566
        tp->waiting_for_image_p = False;
 
567
        tp->start_time = time ((time_t *) 0);
488
568
}
489
569
 
490
 
 
491
570
static void
492
 
getSnapshot(ModeInfo *mi, GLuint name)
 
571
getSnapshot(ModeInfo *mi, texture *texture)
493
572
{
494
573
        gleidestruct *gp = &gleidescope[MI_SCREEN(mi)];
495
574
 
 
575
#ifdef DEBUG
 
576
        printf("getSnapshot");
 
577
#endif
 
578
 
496
579
        if (MI_IS_WIREFRAME(mi))
497
580
                return;
498
581
 
499
582
    gp->mipmap_p = True;
500
583
    load_texture_async (mi->xgwa.screen, mi->window,
501
584
                        *gp->glx_context, 0, 0, gp->mipmap_p, 
502
 
                        name, image_loaded_cb, gp);
503
 
}
504
 
 
505
 
 
506
 
static void
507
 
setup_file_texture (ModeInfo *mi, char *filename, GLuint name)
 
585
                        texture->id, image_loaded_cb, texture);
 
586
        texture->start_time = time((time_t *)0);
 
587
}
 
588
 
 
589
#define TEXTURE_SIZE    256
 
590
 
 
591
static void
 
592
plot(unsigned char *buffer, int x, int y, int r, int g, int b, int a) {
 
593
        int c;
 
594
        if (x < 0 || x >= TEXTURE_SIZE || y < 0 || y >= TEXTURE_SIZE) {
 
595
                return;
 
596
        }
 
597
        c = ((x * TEXTURE_SIZE) + y) * 4;
 
598
        /*printf("(%d,%d)[%d]\n", x, y, c);*/
 
599
        buffer[c + 0] = r;
 
600
        buffer[c + 1] = g;
 
601
        buffer[c + 2] = b;
 
602
        buffer[c + 3] = a;
 
603
}
 
604
 
 
605
#if 0
 
606
static void
 
607
plot2(unsigned char *buffer, int x, int y, int r, int g, int b, int a) {
 
608
        int c;
 
609
        if (x < 0 || x >= TEXTURE_SIZE || y < 0 || y >= TEXTURE_SIZE) {
 
610
                return;
 
611
        }
 
612
        c = ((x * TEXTURE_SIZE) + y) * 4;
 
613
        /*printf("(%d,%d)[%d]\n", x, y, c);*/
 
614
        buffer[c + 0] = r;
 
615
        buffer[c + 1] = g;
 
616
        buffer[c + 2] = b;
 
617
        buffer[c + 3] = a;
 
618
        
 
619
        if (y + 1 < TEXTURE_SIZE) {
 
620
                buffer[c + 4] = r;
 
621
                buffer[c + 5] = g;
 
622
                buffer[c + 6] = b;
 
623
                buffer[c + 7] = a;
 
624
        }
 
625
 
 
626
        if (x + 1 < TEXTURE_SIZE) {
 
627
                c += (TEXTURE_SIZE * 4);
 
628
                buffer[c + 0] = r;
 
629
                buffer[c + 1] = g;
 
630
                buffer[c + 2] = b;
 
631
                buffer[c + 3] = a;
 
632
                if (y + 1 < TEXTURE_SIZE) {
 
633
                        buffer[c + 4] = r;
 
634
                        buffer[c + 5] = g;
 
635
                        buffer[c + 6] = b;
 
636
                        buffer[c + 7] = a;
 
637
                }
 
638
        }
 
639
}
 
640
#endif
 
641
 
 
642
/* draw geometric shapes to texture */
 
643
/* modifies passed in buffer */
 
644
static void
 
645
draw_shapes (unsigned char *buffer) {
 
646
        int a = 0xff;
 
647
        int x, y, w, h;
 
648
        int i, j;
 
649
        int s;
 
650
        float left, right;
 
651
 
 
652
        for (i = 0 ; i < TEXTURE_SIZE * TEXTURE_SIZE * 4 ; i += 4) {
 
653
                buffer[i + 0] = 0x00;
 
654
                buffer[i + 1] = 0x00;
 
655
                buffer[i + 2] = 0x00;
 
656
                buffer[i + 3] = 0xff;
 
657
        }
 
658
 
 
659
        for (s = 0 ; s < 25 ; s++) {
 
660
                int shape = random() % 3;
 
661
 
 
662
                /* 8 bits */
 
663
                int r = (random() & 0xff);
 
664
                int g = (random() & 0xff);
 
665
                int b = (random() & 0xff);
 
666
 
 
667
                switch (shape) {
 
668
                        case 0:
 
669
                                /* rectangle */
 
670
                                x = (random() % TEXTURE_SIZE) - (TEXTURE_SIZE / 4);     /* top left */
 
671
                                y = (random() % TEXTURE_SIZE) - (TEXTURE_SIZE / 4);
 
672
                                w = 10 + random() % (TEXTURE_SIZE / 4); /* size */
 
673
                                h = 10 + random() % (TEXTURE_SIZE / 4);
 
674
#ifdef DEBUG
 
675
                                printf("Rectangle: (%d, %d)(%d, %d)\n", x, y, w, h);
 
676
#endif
 
677
                                if (x < 0) {
 
678
                                        x = 0;
 
679
                                }
 
680
                                if (y < 0) {
 
681
                                        y = 0;
 
682
                                }
 
683
                                for (i = x ; i < x + w && i < TEXTURE_SIZE; i++) {
 
684
                                        for (j = y ; j < y + h && j < TEXTURE_SIZE; j++) {
 
685
                                                plot(buffer, i, j, r, g, b, a);
 
686
                                        }
 
687
                                }
 
688
                                break;
 
689
 
 
690
                        case 1:
 
691
                                /* circle */
 
692
                                x = random() % TEXTURE_SIZE;    /* centre */
 
693
                                y = random() % TEXTURE_SIZE;
 
694
                                h = 10 + random() % (TEXTURE_SIZE / 8); /* radius */
 
695
#ifdef DEBUG
 
696
                                printf("Circle: %d, %d, %d\n", x, y, h);
 
697
#endif
 
698
                                for (i = 0 ; i < h ; i++) {
 
699
                                        int xdist = i * i;
 
700
                                        for (j = 0 ; j < h ; j++) {
 
701
                                                int ydist = j * j;
 
702
                                                /*
 
703
                                                printf("xdist: %d\n", xdist);
 
704
                                                printf("ydist: %d\n", ydist);
 
705
                                                printf("radius: %d\n", h * h);
 
706
                                                */
 
707
                                                if ((xdist + ydist) < (h * h)) {
 
708
                                                        plot(buffer, x + i, y + j, r, b, g, a);
 
709
                                                        /* check we haven't already done these */
 
710
                                                        if (j != 0) {
 
711
                                                                plot(buffer, x + i, y - j, r, b, g, a);
 
712
                                                        }
 
713
                                                        if (i != 0) {
 
714
                                                                plot(buffer, x - i, y + j, r, b, g, a);
 
715
                                                                if (j != 0) {
 
716
                                                                plot(buffer, x - i, y - j, r, b, g, a);
 
717
                                                                }
 
718
                                                        }
 
719
                                                }
 
720
                                        }
 
721
                                }
 
722
                                break;
 
723
 
 
724
                        case 2:
 
725
                                /* triangle */
 
726
                                x = random() % TEXTURE_SIZE;    /* top */
 
727
                                y = random() % TEXTURE_SIZE;
 
728
                                h = 10 + random() % (TEXTURE_SIZE / 4); /* height */
 
729
#ifdef DEBUG
 
730
                                printf("Triangle: %d, %d, %d\n", x, y, h);
 
731
#endif
 
732
                                left = x;
 
733
                                right = x;
 
734
                                for (i = 0 ; i < h ; i++) {
 
735
                                        for (j = left ; j < right ; j++) {
 
736
                                                plot(buffer, j, y + i, r, g, b, a);
 
737
                                        }
 
738
                                        left -= .5;
 
739
                                        right += .5;
 
740
                                }
 
741
                                break;
 
742
                }
 
743
        }
 
744
}
 
745
 
 
746
static void
 
747
setup_random_texture (ModeInfo *mi, texture *texture)
 
748
{
 
749
        int width = 0, height = 0;
 
750
        char buf[1024];
 
751
        unsigned char *my_data = NULL;
 
752
#if 0
 
753
        int i, j, c;
 
754
        int style;
 
755
        int r0, g0, b0, a0, r1, g1, b1, a1;
 
756
#endif
 
757
 
 
758
#ifdef DEBUG
 
759
        printf("RandomTexture\n");
 
760
#endif
 
761
 
 
762
        /* use this texture */
 
763
        glBindTexture(GL_TEXTURE_2D, texture->id);
 
764
 
 
765
        clear_gl_error();
 
766
 
 
767
        /*
 
768
         * code for various generated patterns - noise, stripes, checks etc.
 
769
         * random geometric shapes looked the best.
 
770
         */
 
771
 
 
772
#if 0
 
773
        style = random() & 0x3;
 
774
        r0 = random() & 0xff; 
 
775
        g0 = random() & 0xff; 
 
776
        b0 = random() & 0xff; 
 
777
        a0 = 0xff;
 
778
        r1 = random() & 0xff; 
 
779
        g1 = random() & 0xff; 
 
780
        b1 = random() & 0xff; 
 
781
        a1 = 0xff;
 
782
 
 
783
        switch (style) {
 
784
                case 0: /* random */
 
785
                        printf("Random0\n");
 
786
                        height = width = TEXTURE_SIZE;
 
787
                        my_data = (void *)malloc(width * height * 4);
 
788
                        for (i = 0 ; i < width ; i += 2) {
 
789
                                for (j = 0 ; j < height ; j += 2) {
 
790
                                        r0 = random() & 0xff; 
 
791
                                        g0 = random() & 0xff; 
 
792
                                        b0 = random() & 0xff; 
 
793
                                        a0 = 0xff;
 
794
                                        plot2(my_data, i, j, r0, g0, b0, a0);
 
795
                                }
 
796
                        }
 
797
                        break;
 
798
 
 
799
                case 1: /* shapes */
 
800
#endif
 
801
#ifdef DEBUG
 
802
                        printf("Shapes\n");
 
803
#endif
 
804
                        height = width = TEXTURE_SIZE;
 
805
                        my_data = (void *)malloc(width * height * 4);
 
806
                        draw_shapes(my_data);
 
807
#if 0
 
808
                        break;
 
809
 
 
810
                case 2: /* check */
 
811
                        printf("Check\n");
 
812
                        height = width = TEXTURE_SIZE;
 
813
                        my_data = (void *)malloc(width * height * 4);
 
814
                        for (i = 0 ; i < height ; i += 2) {
 
815
                                for (j = 0 ; j < width ; j += 2) {
 
816
                                        if (((i + j) & 0x3) == 0) {
 
817
                                                plot2(my_data, i, j, r0, g0, b0, a0);
 
818
                                        } else {
 
819
                                                plot2(my_data, i, j, r1, g1, b1, a1);
 
820
                                        }
 
821
                                }
 
822
                        }
 
823
                        break;
 
824
 
 
825
                case 3: /* random stripes */
 
826
                        printf("Stripes 2\n");
 
827
                        height = width = TEXTURE_SIZE;
 
828
                        my_data = (void *)malloc(width * height * 4);
 
829
                        for (i = 0 ; i < height ; i += 2) {
 
830
                                r0 = random() & 0xff; 
 
831
                                g0 = random() & 0xff; 
 
832
                                b0 = random() & 0xff; 
 
833
                                a0 = 0xff;
 
834
                                for (j = 0 ; j < width ; j += 2) {
 
835
                                        plot2(my_data, i, j, r0, g0, b0, a0);
 
836
                                }
 
837
                        }
 
838
                        break;
 
839
        }
 
840
#endif
 
841
 
 
842
        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA,
 
843
                        width, height, 0,
 
844
                        GL_RGBA, GL_UNSIGNED_BYTE, my_data);
 
845
        sprintf (buf, "random texture: (%dx%d)",
 
846
                        width, height);
 
847
        check_gl_error(buf);
 
848
 
 
849
        /* setup parameters for texturing */
 
850
        glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
 
851
        glPixelStorei(GL_UNPACK_ROW_LENGTH, width);
 
852
 
 
853
        glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
 
854
        glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
 
855
        glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
 
856
        if (random() & 0x1) {
 
857
                glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
 
858
                glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
 
859
        } else {
 
860
                glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
 
861
                glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
 
862
        }
 
863
 
 
864
        if (my_data != NULL) {
 
865
                free(my_data);
 
866
                my_data = NULL;
 
867
        }
 
868
 
 
869
        /* use full texture */
 
870
        /* acd - was 1.0 */
 
871
        texture->min_tx = 0.0;
 
872
        texture->max_tx = 2.0;
 
873
        texture->min_ty = 0.0;
 
874
        texture->max_ty = 2.0;
 
875
        texture->start_time = time((time_t *)0);
 
876
}
 
877
 
 
878
static void
 
879
setup_file_texture (ModeInfo *mi, char *filename, texture *texture)
508
880
{
509
881
        Display *dpy = mi->dpy;
510
882
        Visual *visual = mi->xgwa.visual;
513
885
        Colormap cmap = mi->xgwa.colormap;
514
886
        XImage *image = xpm_file_to_ximage (dpy, visual, cmap, filename);
515
887
 
 
888
#ifdef DEBUG
 
889
        printf("FileTexture\n");
 
890
#endif
 
891
 
516
892
        /* use this texture */
517
 
        glBindTexture(GL_TEXTURE_2D, name);
 
893
        glBindTexture(GL_TEXTURE_2D, texture->id);
518
894
 
519
895
        clear_gl_error();
520
896
        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA,
533
909
        glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
534
910
        glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
535
911
        glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
 
912
 
 
913
        /* use full texture */
 
914
        texture->min_tx = 0.0;
 
915
        texture->max_tx = 1.0;
 
916
        texture->min_ty = 0.0;
 
917
        texture->max_ty = 1.0;
 
918
        texture->start_time = time((time_t *)0);
536
919
}
537
920
 
538
921
static void
539
 
setup_texture(ModeInfo * mi, GLuint id)
 
922
setup_texture(ModeInfo * mi, texture *texture)
540
923
{
541
924
        gleidestruct *gp = &gleidescope[MI_SCREEN(mi)];
542
925
 
543
926
        if (!image || !*image || !strcmp(image, "DEFAULT")) {
544
 
                /* no image specified - grab screen */
545
 
                getSnapshot(mi, id);
546
 
                /* max_tx and max_ty set in getSnapshot() */
 
927
                /* no image specified - use system settings */
 
928
#ifdef DEBUG
 
929
                printf("SetupTexture: get_snapshot\n");
 
930
#endif
 
931
                getSnapshot(mi, texture);
547
932
        } else {
548
 
                /* use supplied image file */
549
 
                setup_file_texture(mi, image, id);
550
 
 
551
 
                /* set tx params to use whole image */
552
 
                gp->max_tx = 1.0f;
553
 
                gp->max_ty = 1.0f;
 
933
                if (strcmp(image, "GENERATE") == 0) {
 
934
#ifdef DEBUG
 
935
                        printf("SetupTexture: random_texture\n");
 
936
#endif
 
937
                        setup_random_texture(mi, texture);
 
938
                } else {
 
939
                        /* use supplied image file */
 
940
#ifdef DEBUG
 
941
                        printf("SetupTexture: file_texture\n");
 
942
#endif
 
943
                        setup_file_texture(mi, image, texture);
 
944
                }
554
945
        }
 
946
        /* copy start time from texture */
 
947
        gp->start_time = texture->start_time;
555
948
 
556
949
        check_gl_error("texture initialization");
557
950
 
558
 
        /* Need to flip the texture top for bottom for some reason. */
559
 
        glMatrixMode (GL_TEXTURE);
560
 
        glScalef (1, -1, 1);
561
 
        glMatrixMode (GL_MODELVIEW);
 
951
        /* acd 
 
952
         * resultant loaded image is upside down BUT
 
953
         * it's a kaledescope and half of the hexagon is backwards anyway...
 
954
         */
 
955
 
 
956
        /* TODO: values for lissajous movement */
 
957
        texture->x_period = frandrange(-2.0, 2.0);
 
958
        texture->y_period = frandrange(-2.0, 2.0);
 
959
        texture->r_period = frandrange(-2.0, 2.0);
 
960
        texture->x_phase = frand(M_PI * 2);
 
961
        texture->y_phase = frand(M_PI * 2);
 
962
        texture->r_phase = frand(M_PI * 2);
 
963
#ifdef DEBUG
 
964
        printf("XPeriod %f XPhase %f\n", texture->x_period, texture->x_phase);
 
965
        printf("YPeriod %f YPhase %f\n", texture->y_period, texture->y_phase);
 
966
        printf("RPeriod %f RPhase %f\n", texture->r_period, texture->r_phase);
 
967
#endif
562
968
}
563
969
 
564
970
#define VERTEX0 glVertex3f( 0.0000f,  0.000f, 0.0f);
569
975
#define VERTEX5 glVertex3f(-XOFFSET, -0.500f, 0.0f);
570
976
#define VERTEX6 glVertex3f(-XOFFSET,  0.500f, 0.0f);
571
977
 
572
 
static void
573
 
draw_hexagons(ModeInfo *mi, int translucency, GLuint texture)
 
978
/*
 
979
** Three different functions for calculating texture coordinates
 
980
** which modify how the texture triangle moves over the source image.
 
981
** Choose one.
 
982
*/
 
983
 
 
984
#if 0
 
985
/* the classic equilateral triangle rotating around centre */
 
986
static void
 
987
calculate_texture_coords(ModeInfo *mi, texture *texture, vector2f t[3]) {
 
988
 
 
989
        gleidestruct *gp = &gleidescope[MI_SCREEN(mi)];
 
990
        GLfloat centre_x = 0.5;
 
991
        GLfloat centre_y = 0.5;
 
992
        GLfloat radius_x = (texture->max_tx - texture->min_tx) / 2;
 
993
        GLfloat radius_y = (texture->max_ty - texture->min_ty) / 2;
 
994
        GLfloat tangle2;
 
995
        t[0].x = centre_x;
 
996
        t[0].y = centre_y;
 
997
 
 
998
        /* t[1] */
 
999
        t[1].x = centre_x + .95 * radius_x * cos((gp->ymouse * 2 * M_PI) + (gp->tangle * RADIANS));
 
1000
        t[1].y = centre_y + .95 * radius_y * sin((gp->ymouse * 2 * M_PI) + (gp->tangle * RADIANS));
 
1001
 
 
1002
        /* t[2] is always 60' further around than t2 */
 
1003
        tangle2 = (gp->ymouse * 2 * M_PI) + (gp->tangle * RADIANS) + (M_PI * 2 / 6);
 
1004
        t[2].x = centre_x + .95 * radius_x * cos(tangle2);
 
1005
        t[2].y = centre_y + .95 * radius_y * sin(tangle2);
 
1006
#if 0
 
1007
        printf("texcoords:[%f,%f]->[%f,%f](%f,%f)\n", t[0].x, t[0].y, t[1].x, t[1].y, texture->max_tx, texture->max_ty);
 
1008
#endif
 
1009
}
 
1010
#endif
 
1011
 
 
1012
#if 1
 
1013
/* new lissajous movement pattern */
 
1014
static void
 
1015
calculate_texture_coords(ModeInfo *mi, texture *texture, vector2f t[3]) {
 
1016
 
 
1017
        /* equilateral triangle rotating around centre */
 
1018
        gleidestruct *gp = &gleidescope[MI_SCREEN(mi)];
 
1019
        GLfloat width = texture->max_tx - texture->min_tx;
 
1020
        GLfloat height = texture->max_ty - texture->min_ty;
 
1021
        /* centre */
 
1022
        GLfloat centre_x = texture->min_tx + (width * .5);
 
1023
        GLfloat centre_y = texture->min_ty + (height * .5);
 
1024
        /* m radius and t radius should be = .5 */
 
1025
        /* triangle radius is 30% available space */
 
1026
        GLfloat t_radius_x = width * .3;
 
1027
        GLfloat t_radius_y = height * .3;
 
1028
        /* movement radius is 30% available space */
 
1029
        GLfloat m_radius_x = width * .2;
 
1030
        GLfloat m_radius_y = height * .2;
 
1031
        GLfloat angle2;
 
1032
 
 
1033
        /* centre of triangle */
 
1034
        GLfloat angle = (gp->ymouse * 2 * M_PI) + (gp->tangle * RADIANS);       /* to radians */
 
1035
        GLfloat t_centre_x = centre_x + m_radius_x * cos(texture->x_period * angle + texture->x_phase);
 
1036
        GLfloat t_centre_y = centre_y + m_radius_y * sin(texture->y_period * angle + texture->y_phase);
 
1037
 
 
1038
#if 0
 
1039
        printf("WH: %f, %f - tWH: %f, %f\n", width, height, texture->width, texture->height);
 
1040
        printf("size: (%f, %f)\n", width, height);
 
1041
        printf("centre: (%f, %f)\n", centre_x, centre_y);
 
1042
#endif
 
1043
 
 
1044
        angle2 = texture->r_period * angle + texture->r_phase;
 
1045
        t[0].x = t_centre_x + t_radius_x * cos(angle2);
 
1046
        t[0].y = t_centre_y + t_radius_y * sin(angle2);
 
1047
        t[1].x = t_centre_x + t_radius_x * cos(angle2 + ANGLE_120);
 
1048
        t[1].y = t_centre_y + t_radius_y * sin(angle2 + ANGLE_120);
 
1049
        t[2].x = t_centre_x + t_radius_x * cos(angle2 + ANGLE_240);
 
1050
        t[2].y = t_centre_y + t_radius_y * sin(angle2 + ANGLE_240);
 
1051
 
 
1052
#if 0
 
1053
        printf("texcoords:[%f,%f]->[%f,%f](%f,%f)\n", t[0].x, t[0].y, t[1].x, t[1].y, texture->max_tx, texture->max_ty);
 
1054
#endif
 
1055
}
 
1056
#endif
 
1057
 
 
1058
#if 0
 
1059
/* corners into corners - meant to maximise coverage */
 
1060
static void
 
1061
calculate_texture_coords(ModeInfo *mi, texture *texture, vector2f t[3]) {
 
1062
 
 
1063
        /* equilateral triangle rotating around centre */
 
1064
        gleidestruct *gp = &gleidescope[MI_SCREEN(mi)];
 
1065
        GLfloat width = texture->max_tx - texture->min_tx;
 
1066
        GLfloat height = texture->max_ty - texture->min_ty;
 
1067
        /* centre */
 
1068
        GLfloat centre_x = texture->min_tx + (width * .5);
 
1069
        GLfloat centre_y = texture->min_ty + (height * .5);
 
1070
        /* m radius and t radius should be = .5 */
 
1071
        /* triangle radius calculated using maths 8) */
 
1072
#define TRADIUS (M_SQRT2 - 1.0)
 
1073
#define MRADIUS (1.0 - (M_SQRT2 / 2.0))
 
1074
        GLfloat t_radius_x = width * TRADIUS * .95;
 
1075
        GLfloat t_radius_y = height * TRADIUS * .95;
 
1076
        /* movement radius also calculated using maths */
 
1077
        GLfloat m_radius_x = width * MRADIUS * .95;
 
1078
        GLfloat m_radius_y = height * MRADIUS * .95;
 
1079
        GLfloat angle, angle2;
 
1080
        GLfloat t_centre_x, t_centre_y;
 
1081
 
 
1082
        /* centre of triangle */
 
1083
        angle = gp->tangle * RADIANS;   /* to radians */
 
1084
        t_centre_x = centre_x + m_radius_x * cos(angle);
 
1085
        t_centre_y = centre_y + m_radius_y * sin(angle);
 
1086
#if 0
 
1087
        printf("angle: %f, %f\n", angle, gp->tangle);
 
1088
        printf("tcentre: %f,%f\n", t_centre_x, t_centre_y);
 
1089
        printf("tradius: %f,%f\n", t_radius_x, t_radius_y);
 
1090
 
 
1091
        printf("size: (%f, %f)\n", width, height);
 
1092
        printf("centre: (%f, %f)\n", centre_x, centre_y);
 
1093
        printf("centre: (%f, %f)\n", centre_x, centre_y);
 
1094
        printf("TRADIUS: %f\n", TRADIUS);
 
1095
        printf("MRADIUS: %f\n", MRADIUS);
 
1096
#endif
 
1097
 
 
1098
        /* angle2 is tied to tangle */
 
1099
        angle2 = (180.0 - ((30.0 / 90.0) * gp->tangle)) * RADIANS; 
 
1100
#if 0
 
1101
        printf("Angle1: %f\tAngle2: %f\n", angle / RADIANS, angle2 / RADIANS);
 
1102
#endif
 
1103
        t[0].x = t_centre_x + t_radius_x * cos(angle2);
 
1104
        t[0].y = t_centre_y + t_radius_y * sin(angle2);
 
1105
        t[1].x = t_centre_x + t_radius_x * cos(angle2 + ANGLE_120);
 
1106
        t[1].y = t_centre_y + t_radius_y * sin(angle2 + ANGLE_120);
 
1107
        t[2].x = t_centre_x + t_radius_x * cos(angle2 + ANGLE_240);
 
1108
        t[2].y = t_centre_y + t_radius_y * sin(angle2 + ANGLE_240);
 
1109
 
 
1110
#if 0
 
1111
        printf("texcoords:[%f,%f][%f,%f][%f,%f]\n", t[0].x, t[0].y, t[1].x, t[1].y, t[2].x, t[2].y);
 
1112
#endif
 
1113
}
 
1114
#endif
 
1115
 
 
1116
static int
 
1117
draw_hexagons(ModeInfo *mi, int translucency, texture *texture)
574
1118
{
 
1119
    int polys = 0;
575
1120
        int             i;
576
1121
        GLfloat col[4];
577
 
        GLfloat t1x, t1y, t2x, t2y, t3x, t3y;
 
1122
        vector2f t[3];
578
1123
        gleidestruct *gp = &gleidescope[MI_SCREEN(mi)];
579
 
        GLfloat tangle2;
580
1124
 
581
1125
        col[0] = 1.0;
582
1126
        col[1] = 1.0;
583
1127
        col[2] = 1.0;
584
1128
        col[3] = (float)translucency / MAX_FADE;
585
1129
 
586
 
        /* calculate vertices of equilateral triangle within image. */
587
 
        /* t1 is always in centre */
588
 
        t1x = gp->max_tx / 2;
589
 
        t1y = gp->max_ty / 2;
590
 
        /* t2 rotates */
591
 
        t2x = (gp->max_tx / 2) * (1 + cos((gp->ymouse * 2 * M_PI) + (gp->tangle * M_PI / 180)));
592
 
        t2y = (gp->max_ty / 2) * (1 + sin((gp->ymouse * 2 * M_PI) + (gp->tangle * M_PI / 180)));
593
 
        /* t3 is always 60' further around than t2 */
594
 
        tangle2 = (gp->ymouse * 2 * M_PI) + (gp->tangle * M_PI / 180) + (M_PI * 2 / 6);
595
 
        t3x = (gp->max_tx / 2) * (1 + (cos(tangle2)));
596
 
        t3y = (gp->max_ty / 2) * (1 + (sin(tangle2)));
597
 
        /* NB image is flipped vertically hence: */
598
 
        t1y = 1 - t1y;
599
 
        t2y = 1 - t2y;
600
 
        t3y = 1 - t3y;
601
 
        /*printf("texcoords:[%f,%f]->[%f,%f](%f,%f)\n", t1x, t1y, t2x, t2y, gp->max_tx, gp->max_ty);*/
 
1130
        calculate_texture_coords(mi, texture, t);
602
1131
 
603
1132
        glColor4f(1.0, 1.0, 1.0, (float)translucency / MAX_FADE);
604
1133
        glEnable(GL_TEXTURE_2D);
605
1134
        glEnable(GL_BLEND);
606
1135
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
607
1136
        glDepthMask(GL_FALSE);
608
 
        glBindTexture(GL_TEXTURE_2D, gp->textures[texture]);
609
 
 
 
1137
        glBindTexture(GL_TEXTURE_2D, texture->id);
 
1138
 
 
1139
        if (gp->list == -1) {
 
1140
                gp->list = glGenLists(1);
 
1141
        }
 
1142
 
 
1143
        /* compile new list */
 
1144
        glNewList(gp->list, GL_COMPILE);
 
1145
        glBegin(GL_TRIANGLES);
 
1146
 
 
1147
        /*
 
1148
        ** six triangles to each hexagon
 
1149
        */
 
1150
 
 
1151
        glTexCoord2f(t[0].x, t[0].y);
 
1152
        VERTEX0;
 
1153
        glTexCoord2f(t[1].x, t[1].y);
 
1154
        VERTEX1;
 
1155
        glTexCoord2f(t[2].x, t[2].y);
 
1156
        VERTEX6;
 
1157
 
 
1158
        glTexCoord2f(t[0].x, t[0].y);
 
1159
        VERTEX0;
 
1160
        glTexCoord2f(t[2].x, t[2].y);
 
1161
        VERTEX6;
 
1162
        glTexCoord2f(t[1].x, t[1].y);
 
1163
        VERTEX5;
 
1164
 
 
1165
        glTexCoord2f(t[0].x, t[0].y);
 
1166
        VERTEX0;
 
1167
        glTexCoord2f(t[1].x, t[1].y);
 
1168
        VERTEX5;
 
1169
        glTexCoord2f(t[2].x, t[2].y);
 
1170
        VERTEX4;
 
1171
 
 
1172
        glTexCoord2f(t[0].x, t[0].y);
 
1173
        VERTEX0;
 
1174
        glTexCoord2f(t[2].x, t[2].y);
 
1175
        VERTEX4;
 
1176
        glTexCoord2f(t[1].x, t[1].y);
 
1177
        VERTEX3;
 
1178
 
 
1179
        glTexCoord2f(t[0].x, t[0].y);
 
1180
        VERTEX0;
 
1181
        glTexCoord2f(t[1].x, t[1].y);
 
1182
        VERTEX3;
 
1183
        glTexCoord2f(t[2].x, t[2].y);
 
1184
        VERTEX2;
 
1185
 
 
1186
        glTexCoord2f(t[0].x, t[0].y);
 
1187
        VERTEX0;
 
1188
        glTexCoord2f(t[2].x, t[2].y);
 
1189
        VERTEX2;
 
1190
        glTexCoord2f(t[1].x, t[1].y);
 
1191
        VERTEX1;
 
1192
 
 
1193
        glEnd();
 
1194
        glEndList();
 
1195
 
 
1196
        /* call the list n times */
610
1197
        for (i = 0 ; i < sizeof(hex) / sizeof(hex[0]) ; i++) {
611
1198
 
612
1199
                glPushMatrix();
613
1200
 
614
1201
                glTranslatef(hex[i].x, hex[i].y, 0.0);
615
 
 
616
 
                glBegin(GL_TRIANGLES);
617
 
 
618
 
                /*
619
 
                ** six triangles to each hexagon
620
 
                */
621
 
 
622
 
                glTexCoord2f(t1x, t1y);
623
 
                VERTEX0;
624
 
                glTexCoord2f(t2x, t2y);
625
 
                VERTEX1;
626
 
                glTexCoord2f(t3x, t3y);
627
 
                VERTEX6;
628
 
 
629
 
                glTexCoord2f(t1x, t1y);
630
 
                VERTEX0;
631
 
                glTexCoord2f(t3x, t3y);
632
 
                VERTEX6;
633
 
                glTexCoord2f(t2x, t2y);
634
 
                VERTEX5;
635
 
 
636
 
                glTexCoord2f(t1x, t1y);
637
 
                VERTEX0;
638
 
                glTexCoord2f(t2x, t2y);
639
 
                VERTEX5;
640
 
                glTexCoord2f(t3x, t3y);
641
 
                VERTEX4;
642
 
 
643
 
                glTexCoord2f(t1x, t1y);
644
 
                VERTEX0;
645
 
                glTexCoord2f(t3x, t3y);
646
 
                VERTEX4;
647
 
                glTexCoord2f(t2x, t2y);
648
 
                VERTEX3;
649
 
 
650
 
                glTexCoord2f(t1x, t1y);
651
 
                VERTEX0;
652
 
                glTexCoord2f(t2x, t2y);
653
 
                VERTEX3;
654
 
                glTexCoord2f(t3x, t3y);
655
 
                VERTEX2;
656
 
 
657
 
                glTexCoord2f(t1x, t1y);
658
 
                VERTEX0;
659
 
                glTexCoord2f(t3x, t3y);
660
 
                VERTEX2;
661
 
                glTexCoord2f(t2x, t2y);
662
 
                VERTEX1;
663
 
 
664
 
                glEnd();
 
1202
                glCallList(gp->list);
 
1203
        polys += 6;
665
1204
 
666
1205
                glPopMatrix();
667
1206
        }
680
1219
        glVertex3f(1.0, 1.0, -0.1);
681
1220
        glTexCoord2f(0.0, 1.0);
682
1221
        glVertex3f(0.0, 1.0, -0.1);
 
1222
    polys++;
683
1223
        glEnd();
684
1224
        /* acd debug - display texture triangle */
685
 
        glColor4f(1.0, 1.0, 1.0, 1.0);
 
1225
        glColor4f(1.0, 0.5, 1.0, 1.0);
686
1226
        glBegin(GL_LINE_LOOP);
687
 
        glVertex3f(t1x, t1y, -0.11);
688
 
        glVertex3f(t2x, t2y, -0.11);
689
 
        glVertex3f(t3x, t3y, -0.11);
 
1227
        glVertex3f(t[0].x, t[0].y, -0.11);
 
1228
        glVertex3f(t[1].x, t[1].y, -0.11);
 
1229
        glVertex3f(t[2].x, t[2].y, -0.11);
 
1230
    polys++;
690
1231
        glEnd();
691
1232
        glPopMatrix();
692
1233
#endif
694
1235
        glDisable(GL_TEXTURE_2D);
695
1236
        glDepthMask(GL_TRUE);
696
1237
        glDisable(GL_BLEND);
 
1238
    return polys;
697
1239
}
698
1240
 
699
1241
/*
707
1249
        vectorf v1;
708
1250
        GLfloat pos[4];
709
1251
 
 
1252
    mi->polygon_count = 0;
 
1253
 
710
1254
        glClearColor(0.5, 0.5, 0.5, 1.0);
711
1255
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
712
1256
        glLoadIdentity();
718
1262
        z_angle = gp->cam_z_phase + gp->tic * gp->cam_z_speed;
719
1263
 
720
1264
        if (move) {
721
 
                v1.x = 2 * sin(x_angle);
722
 
                v1.y = 2 * sin(y_angle);
 
1265
                v1.x = 1 * sin(x_angle);
 
1266
                v1.y = 1 * sin(y_angle);
723
1267
        } else {
724
1268
                v1.x = 0;
725
1269
                v1.y = 0;
730
1274
        if (gp->size > 10) {
731
1275
                gp->size = 10;
732
1276
        }
733
 
        if (gp->size < -1) {
734
 
                gp->size = -1;
 
1277
        if (gp->size <= 0) {
 
1278
                gp->size = 0;
735
1279
        }
736
 
        if (gp->size != -1) {
 
1280
        if (gp->size > 0) {
737
1281
                /* user defined size */
738
1282
                v1.z = gp->size;
739
1283
        } else if (zoom) {
740
1284
                /* max distance given by adding the constant and the multiplier */
741
 
                v1.z = 5.0 + 4.0 * sin(z_angle);
 
1285
                v1.z = 5.0 + 3.0 * sin(z_angle);
742
1286
        } else {
743
1287
                /* default */
744
1288
                v1.z = 7.0;
752
1296
                /* update camera rotation angle and velocity */
753
1297
                gp->rangle += gp->rangle_vel;
754
1298
                new_rangle_vel = gp->rangle_vel + gp->rangle_acc;
755
 
                if (new_rangle_vel > -MAX_RANGLE_VEL && new_rangle_vel < MAX_RANGLE_VEL)
 
1299
                if (new_rangle_vel > -MAX_ANGLE_VEL && new_rangle_vel < MAX_ANGLE_VEL)
756
1300
                {
757
1301
                        /* new velocity is within limits */
758
1302
                        gp->rangle_vel = new_rangle_vel;
759
1303
                }
760
1304
 
761
 
                /* randomly change twisting speed */
762
 
                if ((random() % 1000) < 1)
763
 
                {
764
 
                        gp->rangle_acc = frand(0.002) - 0.001;
 
1305
                /* randomly change twisting speed - 3ff = 1024 */
 
1306
                if ((random() % TWISTING_PROBABILITY) < 1.0) {
 
1307
                        gp->rangle_acc = INITIAL_ANGLE_ACC * frand(1.0);
 
1308
                        if (gp->rangle_vel > 0.0) {
 
1309
                                gp->rangle_acc = -gp->rangle_acc;
 
1310
                        }
765
1311
                }
766
1312
        }
 
1313
#if 0
 
1314
        printf("Rangle: %f : %f : %f\n", gp->rangle, gp->rangle_vel, gp->rangle_acc);
 
1315
        printf("Tangle: %f : %f : %f\n", gp->tangle, gp->tangle_vel, gp->tangle_acc);
 
1316
#endif
767
1317
 
768
1318
#ifdef WOBBLE
769
1319
        /* this makes the image wobble - requires -move and a larger grid */
775
1325
        gluLookAt(
776
1326
                        v1.x, v1.y, v1.z,
777
1327
                        v1.x, v1.y, 0.0,
778
 
                        sin((gp->xmouse * M_PI * 2) + gp->rangle * M_PI / 180),
779
 
                        cos((gp->xmouse * M_PI * 2) + gp->rangle * M_PI / 180),
 
1328
                        sin((gp->xmouse * M_PI * 2) + gp->rangle * RADIANS),
 
1329
                        cos((gp->xmouse * M_PI * 2) + gp->rangle * RADIANS),
780
1330
                        0.0);
781
1331
#endif
782
1332
 
789
1339
        if (gp->fade == 0)
790
1340
        {
791
1341
                /* not fading */
792
 
                draw_hexagons(mi, MAX_FADE, gp->visible);
 
1342
      mi->polygon_count += 
 
1343
        draw_hexagons(mi, MAX_FADE, &gp->textures[gp->visible]);
793
1344
        }
794
1345
        else
795
1346
        {
796
 
                /* fading - show both textures with alpha */
797
 
                draw_hexagons(mi, MAX_FADE - gp->fade, gp->visible);
798
 
                draw_hexagons(mi, gp->fade, 1 - gp->visible);
 
1347
                /* fading - show both textures with alpha
 
1348
                NB first is always max alpha */
 
1349
        mi->polygon_count += 
 
1350
          draw_hexagons(mi, MAX_FADE, &gp->textures[1 - gp->visible]);
 
1351
        mi->polygon_count += 
 
1352
                  draw_hexagons(mi, MAX_FADE - gp->fade, &gp->textures[gp->visible]);
799
1353
 
800
1354
                /* fade some more */
801
1355
                gp->fade++;
819
1373
 
820
1374
                /* work out new texture angle velocity */
821
1375
                new_tangle_vel = gp->tangle_vel + gp->tangle_acc;
822
 
                if (new_tangle_vel > -MAX_TANGLE_VEL && new_tangle_vel < MAX_TANGLE_VEL)
 
1376
                if (new_tangle_vel > -MAX_ANGLE_VEL && new_tangle_vel < MAX_ANGLE_VEL)
823
1377
                {
824
1378
                        /* new velocity is inside limits */
825
1379
                        gp->tangle_vel = new_tangle_vel;
826
1380
                }
827
1381
 
828
 
                /* randomly change texture angle acceleration */
829
 
                if ((random() % 1000) < 1)
830
 
                {
831
 
                        gp->tangle_acc = frand(0.002) - 0.001;
 
1382
                /* randomly change twisting speed - 3ff = 1024 */
 
1383
                if ((random() % TWISTING_PROBABILITY) < 1.0) {
 
1384
                        gp->tangle_acc = INITIAL_ANGLE_ACC * frand(1.0);
 
1385
                        if (gp->tangle_vel > 0.0) {
 
1386
                                gp->tangle_acc = -gp->tangle_acc;
 
1387
                        }
832
1388
                }
833
1389
        }
834
1390
 
861
1417
        gp->start_time = (time_t)0;
862
1418
 
863
1419
        /* set the texture size to default */
 
1420
        /*
864
1421
        gp->max_tx = 1.0;
865
1422
        gp->max_ty = 1.0;
 
1423
        */
866
1424
 
867
1425
        /* no fading */
868
1426
        gp->fade = 0;
874
1432
        glDisable(GL_LIGHTING);
875
1433
 
876
1434
        /* space for textures */
877
 
        glGenTextures(1, &gp->textures[0]);
878
 
        glGenTextures(1, &gp->textures[1]);
 
1435
        glGenTextures(1, &gp->textures[0].id);
 
1436
        glGenTextures(1, &gp->textures[1].id);
879
1437
        gp->visible = 0;
880
1438
 
881
 
        setup_texture(mi, gp->textures[gp->visible]);
 
1439
        setup_texture(mi, &gp->textures[gp->visible]);
882
1440
 
883
1441
        /*
884
1442
        **      want to choose a value for arg randomly if neither -arg nor -no-arg
922
1480
        }
923
1481
 
924
1482
        /* define cam variables */
925
 
        gp->cam_x_speed = frand(3.0) - 1.5;
 
1483
        gp->cam_x_speed = MAX_CAM_SPEED * frandrange(-.5, 0.5);
926
1484
        gp->cam_x_phase = random() % 360;
927
 
        gp->cam_y_speed = frand(3.0) - 1.5;
 
1485
        gp->cam_y_speed = MAX_CAM_SPEED * frandrange(-.5, 0.5);
928
1486
        gp->cam_y_phase = random() % 360;
929
 
        gp->cam_z_speed = frand(3.0) - 1.5;
 
1487
        gp->cam_z_speed = MAX_CAM_SPEED * frandrange(-.5, 0.5);
930
1488
        gp->cam_z_phase = random() % 360;
931
1489
 
932
1490
        /* initial angular speeds */
933
 
        gp->rangle_vel = frand(0.2) - 0.1;
934
 
        gp->tangle_vel = frand(0.2) - 0.1;
935
 
        gp->rangle_acc = frand(0.002) - 0.001;
936
 
        gp->tangle_acc = frand(0.002) - 0.001;
 
1491
        gp->rangle_vel = INITIAL_ANGLE_VEL * frandrange(-.5, 0.5);
 
1492
        gp->tangle_vel = INITIAL_ANGLE_VEL * frandrange(-.5, 0.5);
 
1493
        gp->rangle_acc = INITIAL_ANGLE_ACC * frandrange(-.5, 0.5);
 
1494
        gp->tangle_acc = INITIAL_ANGLE_ACC * frandrange(-.5, 0.5);
937
1495
 
938
1496
    /* jwz */
 
1497
#if 0
939
1498
    {
940
1499
      GLfloat speed = 15;
941
1500
      gp->rangle_vel *= speed;
943
1502
      gp->rangle_acc *= speed;
944
1503
      gp->tangle_acc *= speed;
945
1504
    }
 
1505
#endif
946
1506
 
947
1507
        /* distance is 11 - size */
948
1508
        if (gp->size != -1) {
969
1529
        gleidestruct *gp;
970
1530
        int screen = MI_SCREEN(mi);
971
1531
 
972
 
 
973
1532
        if (gleidescope == NULL) {
974
1533
                gleidescope = (gleidestruct *) calloc(MI_NUM_SCREENS(mi), sizeof (gleidestruct));
975
1534
                if (gleidescope == NULL) {
979
1538
        gp = &gleidescope[screen];
980
1539
        gp->window = MI_WINDOW(mi);
981
1540
    gp->size = -1;
 
1541
    gp->list = -1;
982
1542
 
983
1543
        if ((gp->glx_context = init_GL(mi)) != NULL) {
984
1544
 
1022
1582
 
1023
1583
#ifdef GRAB
1024
1584
        if (grab) {
1025
 
                grab_frame(mi);
 
1585
                grab_frame(display, window);
1026
1586
        }
1027
1587
#endif
1028
1588
 
1029
1589
        /* need to change texture? */
1030
1590
        if ((gp->start_time != 0) && (duration != -1) && gp->fade == 0) {
1031
1591
                if (gp->start_time + duration <= time((time_t *)0)) {
 
1592
#ifdef DEBUG
 
1593
                        printf("Start Time: %lu - Current Time: %lu\n", (unsigned long)gp->start_time, (unsigned long)time((time_t *)0));
 
1594
                        printf("Changing Texture\n");
 
1595
#endif
1032
1596
                        /* get new snapshot (into back buffer) and start fade count */
1033
 
                        getSnapshot(mi, gp->textures[1 - gp->visible]);
 
1597
                        setup_texture(mi, &gp->textures[1 - gp->visible]);
 
1598
                        /* restart fading */
1034
1599
                        gp->fade = 1;
1035
1600
                }
1036
1601
        }