~ubuntu-branches/ubuntu/karmic/xscreensaver/karmic

« back to all changes in this revision

Viewing changes to hacks/glx/flipflop.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
/* flipflop, Copyright (c) 2003 Kevin Ogden <kogden1@hotmail.com>
2
2
 *                     (c) 2006 Sergio Guti�rrez "Sergut" <sergut@gmail.com>
 
3
 *                     (c) 2008 Andrew Galante <a.drew7@gmail.com>
3
4
 *
4
5
 * Permission to use, copy, modify, distribute, and sell this software and its
5
6
 * documentation for any purpose is hereby granted without fee, provided that
15
16
 *                                   from the command line: size of the board, 
16
17
 *                                   rotation speed and number of free squares; also
17
18
 *                                   added the "sticks" mode.
 
19
 * 2008 Andrew Galante               Added -textured option: textures the board with
 
20
 *                                   an image which gets scrambled as the tiles move
18
21
 *
19
22
 */
20
23
 
21
 
#define DEF_FLIPFLOP_MODE  "tiles" /* Default mode (options: "tiles", "sticks") */
22
 
#define DEF_BOARD_X_SIZE   "9"     /* Default width of the board */
23
 
#define DEF_BOARD_Y_SIZE   "9"     /* Default length of the board */
 
24
#define DEF_MODE  "tiles" /* Default mode (options: "tiles", "sticks") */
 
25
#define DEF_SIZEX   "9"     /* Default width of the board */
 
26
#define DEF_SIZEY   "9"     /* Default length of the board */
24
27
 
25
28
#define DEF_BOARD_SIZE     "0"     /* "0" means "no value selected by user". It is changed */ 
26
29
#define DEF_NUMSQUARES     "0"     /* in function init_flipflop() to its correct value (that */ 
28
31
 
29
32
#define DEF_SPIN           "0.1"   /* Default angular velocity: PI/10 rads/s    */
30
33
 
 
34
#define DEF_TEXTURED       "False" /* Default: do not grab an image for texturing */
 
35
 
31
36
#define DEF_STICK_THICK   54       /* Thickness for the sticks mode (over 100)  */
32
37
#define DEF_STICK_RATIO   80       /* Ratio of sticks/total squares (over 100)  */
33
38
#define DEF_TILE_THICK     4       /* Thickness for the tiles mode (over 100)   */
57
62
    {"-tiles",          ".mode",            XrmoptionNoArg,  "tiles" },
58
63
    {"-mode",           ".mode",            XrmoptionSepArg, 0       },
59
64
    {"-size",           ".size",            XrmoptionSepArg, 0       },
60
 
    {"-size-x",         ".size_x",          XrmoptionSepArg, 0       },
61
 
    {"-size-y",         ".size_y",          XrmoptionSepArg, 0       },
 
65
    {"-size-x",         ".sizex",           XrmoptionSepArg, 0       },
 
66
    {"-size-y",         ".sizey",           XrmoptionSepArg, 0       },
62
67
    {"-count",          ".numsquares",      XrmoptionSepArg, 0       },
63
68
    {"-free",           ".freesquares",     XrmoptionSepArg, 0       },
64
69
    {"-spin",           ".spin",            XrmoptionSepArg, 0       },
 
70
    {"-texture",        ".textured",        XrmoptionNoArg,  "True"  },
 
71
    {"+texture",        ".textured",        XrmoptionNoArg,  "False" },
65
72
};
66
73
 
67
74
static int wire, clearbits;
70
77
static float half_thick;
71
78
static float spin;
72
79
static char* flipflopmode_str="tiles";
 
80
static int textured;
73
81
 
74
82
static argtype vars[] = {
75
 
    { &flipflopmode_str, "mode",        "Mode",     DEF_FLIPFLOP_MODE,  t_String},
 
83
    { &flipflopmode_str, "mode",        "Mode",     DEF_MODE,  t_String},
76
84
    { &board_avg_size,   "size",        "Integer",  DEF_BOARD_SIZE,     t_Int},
77
 
    { &board_x_size,     "size_x",      "Integer",  DEF_BOARD_X_SIZE,   t_Int},
78
 
    { &board_y_size,     "size_y",      "Integer",  DEF_BOARD_Y_SIZE,   t_Int},
 
85
    { &board_x_size,     "sizex",       "Integer",  DEF_SIZEX,   t_Int},
 
86
    { &board_y_size,     "sizey",       "Integer",  DEF_SIZEY,   t_Int},
79
87
    { &numsquares,       "numsquares",  "Integer",  DEF_NUMSQUARES,     t_Int},
80
88
    { &freesquares,      "freesquares", "Integer",  DEF_NUMSQUARES,     t_Int},
81
89
    { &spin,             "spin",        "Float",    DEF_SPIN,           t_Float},
 
90
    { &textured,         "textured",    "Bool",     DEF_TEXTURED,       t_Bool},
82
91
};
83
92
 
84
93
ENTRYPOINT ModeSpecOpt flipflop_opts = {countof(opts), opts, countof(vars), vars, NULL};
111
120
    /* eg. color[ 5*3 + 2 ] is the blue  component of square 5 */
112
121
    /*            ^-- n is the number of square */
113
122
    float *color; /* size: numsquares * 3 */
114
 
} randsheet;    
 
123
    /* array of texcoords for each square */
 
124
    /* tex[ n*4 + 0 ] is x texture coordinate of square n's left side */
 
125
    /* tex[ n*4 + 1 ] is y texture coordinate of square n's top side */
 
126
    /* tex[ n*4 + 2 ] is x texture coordinate of square n's right side */
 
127
    /* tex[ n*4 + 3 ] is y texture coordinate of square n's bottom side */
 
128
    float *tex; /* size: numsquares * 4 */
 
129
} randsheet;
115
130
 
116
131
typedef struct {
117
132
    GLXContext *glx_context;
119
134
    trackball_state *trackball;
120
135
    Bool button_down_p;
121
136
 
122
 
        randsheet *sheet;
 
137
    randsheet *sheet;
123
138
 
124
139
    float theta;      /* angle of rotation of the board                */
125
140
    float flipspeed;  /* amount of flip;  1 is a entire flip           */
126
141
    float reldist;    /* relative distace of camera from center        */
127
142
    float energy;     /* likelyhood that a square will attempt to move */
128
143
 
 
144
    /* texture rectangle */
 
145
    float tex_x;
 
146
    float tex_y;
 
147
    float tex_width;
 
148
    float tex_height;
 
149
 
 
150
    /* id of texture in use */
 
151
    GLuint texid;
 
152
 
 
153
    Bool mipmap;
 
154
    Bool got_texture;
 
155
 
 
156
    GLfloat anisotropic;
 
157
 
129
158
} Flipflopcreen;
130
159
 
131
160
static Flipflopcreen *qs = NULL;
132
161
 
 
162
#include "grab-ximage.h"
 
163
 
133
164
static void randsheet_create( randsheet *rs );
134
165
static void randsheet_initialize( randsheet *rs );
135
166
static void randsheet_free( randsheet *rs );
136
167
static int  randsheet_new_move( randsheet* rs );
137
168
static void randsheet_move( randsheet *rs, float rot );
138
 
static void randsheet_draw( randsheet *rs );
 
169
static int randsheet_draw( randsheet *rs );
139
170
static void setup_lights(void);
140
 
static void drawBoard(Flipflopcreen *);
141
 
static void display(Flipflopcreen *c);
142
 
static void draw_sheet(void);
 
171
static int drawBoard(Flipflopcreen *);
 
172
static int display(Flipflopcreen *c);
 
173
static int draw_sheet(float *tex);
143
174
 
144
175
 
145
176
/* configure lighting */
205
236
}
206
237
 
207
238
/* draw board */
208
 
static void
 
239
static int
209
240
drawBoard(Flipflopcreen *c)
210
241
{
211
242
    int i;
213
244
        randsheet_new_move( c->sheet );
214
245
        }
215
246
    randsheet_move( c->sheet, c->flipspeed * 3.14159 );
216
 
    randsheet_draw( c->sheet );
 
247
    return randsheet_draw( c->sheet );
217
248
}
218
249
 
219
250
 
220
 
static void
 
251
static int
221
252
display(Flipflopcreen *c)
222
253
{
223
254
    GLfloat amb[] = { 0.8, 0.8, 0.8, 1.0 };
 
255
    int polys = 0;
224
256
 
225
257
 
226
258
    glClear(clearbits);
240
272
    glRotatef(c->theta*100, 0.0, 1.0, 0.0);
241
273
    glTranslatef(-0.5*board_x_size, 0.0, -0.5*board_y_size); /* Center the board */
242
274
 
243
 
    drawBoard(c);
 
275
    /* set texture */
 
276
    if(textured)
 
277
      glBindTexture(GL_TEXTURE_2D, c->texid);
 
278
 
 
279
    polys = drawBoard(c);
244
280
 
245
281
    if (!c->button_down_p) {
246
282
        c->theta += .01 * spin;
247
 
        }
 
283
    }
248
284
 
 
285
    return polys;
249
286
}
250
287
 
251
288
ENTRYPOINT void
259
296
    glMatrixMode(GL_MODELVIEW);
260
297
}
261
298
 
 
299
static void
 
300
image_loaded_cb (const char *filename, XRectangle *geometry,
 
301
                 int image_width, int image_height, 
 
302
                 int texture_width, int texture_height,
 
303
                 void *closure)
 
304
{
 
305
    Flipflopcreen *c = (Flipflopcreen *)closure;
 
306
    int i, j;
 
307
    int index = 0;
 
308
    randsheet *rs = c->sheet;
 
309
 
 
310
    c->tex_x = (float)geometry->x / (float)texture_width;
 
311
    c->tex_y = (float)geometry->y / (float)texture_height;
 
312
    c->tex_width = (float)geometry->width / (float)texture_width; 
 
313
    c->tex_height = (float)geometry->height / (float)texture_height;
 
314
 
 
315
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
 
316
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
 
317
        (c->mipmap ? GL_LINEAR_MIPMAP_LINEAR : GL_LINEAR));
 
318
 
 
319
    if(c->anisotropic >= 1)
 
320
        glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, c->anisotropic);
 
321
 
 
322
    glEnable(GL_TEXTURE_2D);
 
323
    glEnable(GL_BLEND);
 
324
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
 
325
 
 
326
    for(i = 0; i < board_x_size && index < numsquares; i++)
 
327
        for(j = 0; j < board_y_size && index < numsquares; j++)
 
328
        {
 
329
            /* arrange squares to form loaded image */
 
330
            rs->tex[ index*4 + 0 ] = c->tex_x + c->tex_width  / board_x_size * (i + 0);
 
331
            rs->tex[ index*4 + 1 ] = c->tex_y + c->tex_height / board_y_size * (j + 1);
 
332
            rs->tex[ index*4 + 2 ] = c->tex_x + c->tex_width  / board_x_size * (i + 1);
 
333
            rs->tex[ index*4 + 3 ] = c->tex_y + c->tex_height / board_y_size * (j + 0);
 
334
            rs->color[ index*3 + 0 ] = 1;
 
335
            rs->color[ index*3 + 1 ] = 1;
 
336
            rs->color[ index*3 + 2 ] = 1;
 
337
            index++;
 
338
        }
 
339
 
 
340
    c->got_texture = True;
 
341
}
 
342
 
 
343
static void
 
344
get_texture(ModeInfo *modeinfo)
 
345
{
 
346
    Flipflopcreen *c = &qs[MI_SCREEN(modeinfo)];
 
347
 
 
348
    c->got_texture = False;
 
349
    c->mipmap = True;
 
350
    load_texture_async (modeinfo->xgwa.screen, modeinfo->window,
 
351
                      *c->glx_context, 0, 0, c->mipmap, c->texid,
 
352
                      image_loaded_cb, c);
 
353
}
 
354
 
262
355
ENTRYPOINT void
263
356
init_flipflop(ModeInfo *mi)
264
357
{
265
 
        int screen; 
 
358
    int screen; 
266
359
    Flipflopcreen *c;
267
360
 
268
 
        /* Set all constants to their correct values */
269
 
        if (board_avg_size != 0) {  /* general size specified by user */
270
 
                board_x_size = board_avg_size;
271
 
                board_y_size = board_avg_size;
272
 
        } else {
273
 
                board_avg_size = (board_x_size + board_y_size) / 2;
274
 
        }
275
 
        if ((numsquares == 0) && (freesquares != 0)) {
276
 
                numsquares = board_x_size * board_y_size - freesquares; 
277
 
        }
278
 
        if (strcmp(flipflopmode_str, "tiles")) {
279
 
                half_thick = 1.0 * DEF_STICK_THICK / 100.0; 
280
 
                if (numsquares == 0) {  /* No value defined by user */
281
 
                        numsquares = board_x_size * board_y_size * DEF_STICK_RATIO / 100;
282
 
                }
283
 
        } else {
284
 
                half_thick = 1.0 * DEF_TILE_THICK / 100.0; 
285
 
                if (numsquares == 0) {  /* No value defined by user */
286
 
                        numsquares = board_x_size * board_y_size * DEF_TILE_RATIO/ 100;;
287
 
                }
288
 
        }
289
 
        if (board_avg_size < 2) {
290
 
                fprintf (stderr,"%s: the board must be at least 2x2.\n", progname);
291
 
                exit(1);
292
 
        }
293
 
        if ((board_x_size < 1) || (board_y_size < 1) || (numsquares < 1)) {
294
 
                fprintf (stderr,"%s: the number of elements ('-count') and the dimensions of the board ('-size-x', '-size-y') must be positive integers.\n", progname);
295
 
                exit(1);
296
 
        }
297
 
        if (board_x_size * board_y_size <= numsquares) {
298
 
                fprintf (stderr,"%s: the number of elements ('-count') that you specified is too big \n for the dimensions of the board ('-size-x', '-size-y'). Nothing will move.\n", progname);
299
 
        }
 
361
    if (MI_IS_WIREFRAME(mi)) textured = 0;
 
362
 
 
363
    /* Set all constants to their correct values */
 
364
    if (board_avg_size != 0) {  /* general size specified by user */
 
365
        board_x_size = board_avg_size;
 
366
        board_y_size = board_avg_size;
 
367
    } else {
 
368
        board_avg_size = (board_x_size + board_y_size) / 2;
 
369
    }
 
370
    if ((numsquares == 0) && (freesquares != 0)) {
 
371
        numsquares = board_x_size * board_y_size - freesquares; 
 
372
    }
 
373
    if (strcmp(flipflopmode_str, "tiles")) {
 
374
      textured = 0;  /* textures look dumb in stick mode */
 
375
        half_thick = 1.0 * DEF_STICK_THICK / 100.0; 
 
376
        if (numsquares == 0) {  /* No value defined by user */
 
377
            numsquares = board_x_size * board_y_size * DEF_STICK_RATIO / 100;
 
378
        }
 
379
    } else {
 
380
        half_thick = 1.0 * DEF_TILE_THICK / 100.0; 
 
381
        if (numsquares == 0) {  /* No value defined by user */
 
382
            numsquares = board_x_size * board_y_size * DEF_TILE_RATIO/ 100;;
 
383
        }
 
384
    }
 
385
    if (board_avg_size < 2) {
 
386
        fprintf (stderr,"%s: the board must be at least 2x2.\n", progname);
 
387
        exit(1);
 
388
    }
 
389
    if ((board_x_size < 1) || (board_y_size < 1) ||     (numsquares < 1)) {
 
390
        fprintf (stderr,"%s: the number of elements ('-count') and the dimensions of the board ('-size-x', '-size-y') must be positive integers.\n", progname);
 
391
        exit(1);
 
392
    }
 
393
    if (board_x_size * board_y_size <= numsquares) {
 
394
        fprintf (stderr,"%s: the number of elements ('-count') that you specified is too big \n for the dimensions of the board ('-size-x', '-size-y'). Nothing will move.\n", progname);
 
395
    }
300
396
 
301
397
    screen = MI_SCREEN(mi);
302
398
    wire = MI_IS_WIREFRAME(mi);
335
431
    clearbits |= GL_DEPTH_BUFFER_BIT;
336
432
    glEnable(GL_CULL_FACE);
337
433
    glCullFace(GL_BACK);
 
434
 
338
435
    randsheet_initialize( c->sheet );
 
436
    if( textured ){
 
437
        /* check for anisotropic filtering */
 
438
        if(strstr((char *)glGetString(GL_EXTENSIONS),
 
439
            "GL_EXT_texture_filter_anisotropic"))
 
440
            glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &c->anisotropic);
 
441
        else
 
442
            c->anisotropic = 0;
 
443
 
 
444
        /* allocate a new texture and get it */
 
445
        glGenTextures(1, &c->texid);
 
446
        get_texture(mi);
 
447
    }
339
448
}
340
449
 
341
450
ENTRYPOINT void
345
454
    Window w = MI_WINDOW(mi);
346
455
    Display *disp = MI_DISPLAY(mi);
347
456
 
348
 
    if(!c->glx_context)
 
457
    if(!c->glx_context || (textured && !c->got_texture))
349
458
        return;
350
459
 
351
460
    glXMakeCurrent(disp, w, *(c->glx_context));
352
461
 
353
 
    display(c);
 
462
    mi->polygon_count = display(c);
354
463
 
355
464
    if(mi->fps_p){
356
465
        do_fps(mi);
388
497
 
389
498
/*** ADDED RANDSHEET FUNCTIONS ***/
390
499
 
391
 
static void
392
 
draw_sheet(void)
 
500
static int
 
501
draw_sheet(float *tex)
393
502
{
 
503
    int polys = 0;
394
504
    glBegin( wire ? GL_LINE_LOOP : GL_QUADS );
395
505
 
396
506
    glNormal3f( 0, -1, 0 );
 
507
    glTexCoord2f(tex[0], tex[3]);
397
508
    glVertex3f( half_thick,  -half_thick,  half_thick );
 
509
    glTexCoord2f(tex[2], tex[3]);
398
510
    glVertex3f( 1-half_thick,   -half_thick, half_thick );
 
511
    glTexCoord2f(tex[2], tex[1]);
399
512
    glVertex3f( 1-half_thick, -half_thick,  1-half_thick);
 
513
    glTexCoord2f(tex[0], tex[1]);
400
514
    glVertex3f( half_thick, -half_thick, 1-half_thick );
 
515
    polys++;
401
516
 
402
517
    if (wire) { glEnd(); glBegin (GL_LINE_LOOP); }
403
518
 
404
519
    /* back */
405
520
    glNormal3f( 0, 1, 0 );
 
521
    glTexCoord2f(tex[0], tex[1]);
406
522
    glVertex3f( half_thick, half_thick, 1-half_thick );
 
523
    glTexCoord2f(tex[2], tex[1]);
407
524
    glVertex3f( 1-half_thick, half_thick,  1-half_thick);
 
525
    glTexCoord2f(tex[2], tex[3]);
408
526
    glVertex3f( 1-half_thick,   half_thick, half_thick );
 
527
    glTexCoord2f(tex[0], tex[3]);
409
528
    glVertex3f( half_thick,  half_thick,  half_thick );
 
529
    polys++;
410
530
 
411
 
    if (wire) { glEnd(); return; }
 
531
    if (wire) { glEnd(); return polys; }
412
532
 
413
533
    /* 4 edges!!! weee.... */
414
534
    glNormal3f( 0, 0, -1 );
 
535
    glTexCoord2f(tex[0], tex[3]);
415
536
    glVertex3f( half_thick, half_thick, half_thick );
 
537
    glTexCoord2f(tex[2], tex[3]);
416
538
    glVertex3f( 1-half_thick, half_thick, half_thick );
 
539
    glTexCoord2f(tex[2], tex[3]);
417
540
    glVertex3f( 1-half_thick, -half_thick, half_thick );
 
541
    glTexCoord2f(tex[0], tex[3]);
418
542
    glVertex3f( half_thick, -half_thick, half_thick );
 
543
    polys++;
419
544
    glNormal3f( 0, 0, 1 );
 
545
    glTexCoord2f(tex[0], tex[1]);
420
546
    glVertex3f( half_thick, half_thick, 1-half_thick );
 
547
    glTexCoord2f(tex[0], tex[1]);
421
548
    glVertex3f( half_thick, -half_thick, 1-half_thick );
 
549
    glTexCoord2f(tex[2], tex[1]);
422
550
    glVertex3f( 1-half_thick, -half_thick, 1-half_thick );
 
551
    glTexCoord2f(tex[2], tex[1]);
423
552
    glVertex3f( 1-half_thick, half_thick, 1-half_thick );
 
553
    polys++;
424
554
    glNormal3f( 1, 0, 0 );
 
555
    glTexCoord2f(tex[2], tex[1]);
425
556
    glVertex3f( 1-half_thick, half_thick, 1-half_thick );
 
557
    glTexCoord2f(tex[2], tex[1]);
426
558
    glVertex3f( 1-half_thick, -half_thick, 1-half_thick );
 
559
    glTexCoord2f(tex[2], tex[3]);
427
560
    glVertex3f( 1-half_thick, -half_thick, half_thick );
 
561
    glTexCoord2f(tex[2], tex[3]);
428
562
    glVertex3f( 1-half_thick, half_thick, half_thick );
 
563
    polys++;
429
564
    glNormal3f( -1, 0, 0 );
 
565
    glTexCoord2f(tex[0], tex[1]);
430
566
    glVertex3f( half_thick, half_thick, 1-half_thick );
 
567
    glTexCoord2f(tex[0], tex[3]);
431
568
    glVertex3f( half_thick, half_thick, half_thick );
 
569
    glTexCoord2f(tex[0], tex[3]);
432
570
    glVertex3f( half_thick, -half_thick, half_thick );
 
571
    glTexCoord2f(tex[0], tex[1]);
433
572
    glVertex3f( half_thick, -half_thick, 1-half_thick );
 
573
    polys++;
434
574
    glEnd();
 
575
 
 
576
    return polys;
435
577
}
436
578
 
437
579
/* Reserve memory for the randsheet */
444
586
        rs -> direction = (int*) malloc(numsquares * sizeof(int));
445
587
        rs -> angle     = (float*) malloc(numsquares * sizeof(float));
446
588
        rs -> color     = (float*) malloc(numsquares*3 * sizeof(float));
 
589
        rs -> tex       = (float*) malloc(numsquares*4 * sizeof(float));
447
590
}
448
591
 
449
592
/* Free reserved memory for the randsheet */
456
599
        free(rs->direction);
457
600
        free(rs->angle);
458
601
        free(rs->color);
 
602
        free(rs->tex);
459
603
}
460
604
 
461
605
static void
474
618
                            rs->occupied[ i * board_y_size + j ] = index;
475
619
                            rs->xpos[ index ] = i;
476
620
                            rs->ypos[ index ] = j;
477
 
                            /* have the square colors start out as a pattern */
478
 
                            rs->color[ index*3 + 0 ] = ((i+j)%3 == 0)||((i+j+1)%3 == 0);
479
 
                            rs->color[ index*3 + 1 ] = ((i+j+1)%3 == 0);
480
 
                            rs->color[ index*3 + 2 ] = ((i+j+2)%3 == 0);
 
621
                                                        /* have the square colors start out as a pattern */
 
622
                                                        rs->color[ index*3 + 0 ] = ((i+j)%3 == 0)||((i+j+1)%3 == 0);
 
623
                                                        rs->color[ index*3 + 1 ] = ((i+j+1)%3 == 0);
 
624
                                                        rs->color[ index*3 + 2 ] = ((i+j+2)%3 == 0);
481
625
                            index++;
482
626
                        }
483
627
                    /* leave everything else empty*/
586
730
randsheet_move( randsheet *rs, float rot )
587
731
{
588
732
    int i, j, index;
 
733
    float tmp;
589
734
    for( index = 0 ; index < numsquares; index++ )
590
735
        {
591
736
            i = rs->xpos[ index ];
597
742
                    break;
598
743
                case 1:
599
744
                    /* move up in x */
 
745
                    if( textured && rs->angle[ index ] == 0 )
 
746
                        {
 
747
                            tmp = rs->tex[ index * 4 + 0 ];
 
748
                            rs->tex[ index * 4 + 0 ] = rs->tex[ index * 4 + 2 ];
 
749
                            rs->tex[ index * 4 + 2 ] = tmp;
 
750
                        }
600
751
                    rs->angle[ index ] += rot;
601
752
                    /* check to see if we have finished moving */
602
753
                    if( rs->angle[ index ] >= M_PI  )
608
759
                    break;
609
760
                case 2:
610
761
                    /* move up in y */
 
762
                    if( textured && rs->angle[ index ] == 0 )
 
763
                        {
 
764
                            tmp = rs->tex[ index * 4 + 1 ];
 
765
                            rs->tex[ index * 4 + 1 ] = rs->tex[ index * 4 + 3 ];
 
766
                            rs->tex[ index * 4 + 3 ] = tmp;
 
767
                        }
611
768
                    rs->angle[ index ] += rot;
612
769
                    /* check to see if we have finished moving */
613
770
                    if( rs->angle[ index ] >= M_PI  )
626
783
                            rs->xpos[ index ] -= 1;
627
784
                            rs->direction[ index ] = 0;
628
785
                            rs->angle[ index ] = 0;
 
786
                            if( textured )
 
787
                            {
 
788
                                                            tmp = rs->tex[ index * 4 + 0 ];
 
789
                                                            rs->tex[ index * 4 + 0 ] = rs->tex[ index * 4 + 2 ];
 
790
                                                            rs->tex[ index * 4 + 2 ] = tmp;
 
791
                            }
629
792
                        }
630
793
                    break;
631
794
                case 4:
632
 
                    /* up in x */
 
795
                    /* down in y */
633
796
                    rs->angle[ index ] += rot;
634
797
                    /* check to see if we have finished moving */
635
798
                    if( rs->angle[ index ] >= M_PI  )
637
800
                            rs->ypos[ index ] -= 1;
638
801
                            rs->direction[ index ] = 0;
639
802
                            rs->angle[ index ] = 0;
 
803
                            if( textured )
 
804
                            {
 
805
                                tmp = rs->tex[ index * 4 + 1 ];
 
806
                                rs->tex[ index * 4 + 1 ] = rs->tex[ index * 4 + 3 ];
 
807
                                rs->tex[ index * 4 + 3 ] = tmp;
 
808
                            }
640
809
                        }
641
810
                    break;
642
811
                default:
647
816
 
648
817
 
649
818
/* draw all the moving squares  */
650
 
static void
 
819
static int
651
820
randsheet_draw( randsheet *rs )
652
821
{
653
 
    int i, j;
 
822
    int i, j, polys = 0;
654
823
    int index;
 
824
 
655
825
    /* for all moving squares ... */
656
826
    for( index = 0; index < numsquares; index++ )
657
827
        {
692
862
                default:
693
863
                    break;
694
864
                }
695
 
            draw_sheet();
 
865
            polys += draw_sheet( rs->tex + index*4 );
696
866
            glPopMatrix();
697
867
 
698
868
        }
 
869
    return polys;
699
870
}
700
871
 
701
872
/**** END RANDSHEET_BAK FUNCTIONS ***/
702
873
 
703
 
XSCREENSAVER_MODULE ("Flipflop", flipflop)
 
874
XSCREENSAVER_MODULE ("FlipFlop", flipflop)
704
875
 
705
876
#endif /* USE_GL */