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

« back to all changes in this revision

Viewing changes to hacks/glx/glhanoi.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:
15
15
 
16
16
#include "rotator.h"
17
17
 
18
 
#define DEF_DELAY     "15000"
19
 
#define DEF_DISKS     "0"         /* < 2 means 3-12 */
20
 
#define DEF_WIRE      "False"
21
18
#define DEF_LIGHT     "True"
22
 
#define DEF_FPS       "False"
23
19
#define DEF_FOG       "False"
24
20
#define DEF_TEXTURE   "True"
25
21
 
26
 
#define DEFAULTS "*delay:     " DEF_DELAY     "\n" \
27
 
                                 "*count:     " DEF_DISKS     "\n" \
28
 
                                 "*showFPS:   " DEF_FPS       "\n" \
29
 
                                 "*wireframe: " DEF_WIRE      "\n"
 
22
#define DEFAULTS "*delay:     15000\n" \
 
23
                                 "*count:     0\n" \
 
24
                                 "*showFPS:   False\n" \
 
25
                                 "*wireframe: False\n"
30
26
 
31
27
# define refresh_glhanoi 0
32
28
 
96
92
        GLfloat t1, t2;
97
93
        GLfloat ucostheta, usintheta;
98
94
        GLdouble rotAngle;
 
95
    int polys;
99
96
} Disk;
100
97
 
101
98
typedef struct {
139
136
        GLint floorList;
140
137
        GLint baseList;
141
138
        GLint poleList;
 
139
    int floorpolys, basepolys, polepolys;
142
140
        GLfloat camera[3];
143
141
        GLfloat centre[3];
144
142
        rotator *the_rotator;
594
592
 * people's hardware supports 3D textures, so I didn't bother (xorg
595
593
 * ATI server doesn't :-( )
596
594
 */
597
 
static void drawTube(GLdouble bottomRadius, GLdouble topRadius,
 
595
static int drawTube(GLdouble bottomRadius, GLdouble topRadius,
598
596
                          GLdouble bottomThickness, GLdouble topThickness,
599
597
                          GLdouble height, GLuint nSlice, GLuint nLoop)
600
598
{
 
599
    int polys = 0;
601
600
        GLfloat y;
602
601
        GLfloat *cosCache = malloc(sizeof(GLfloat) * nSlice);
603
602
        GLfloat *sinCache = malloc(sizeof(GLfloat) * nSlice);
659
658
                /* yTexCoord, */
660
659
                /* midTexCoord + cosCache[slice] * outerTexCoordSize); */
661
660
                glVertex3f(radius * sinCache[slice], y, radius * cosCache[slice]);
 
661
        polys++;
662
662
        }
663
663
        glEnd();
664
664
 
684
684
                                           upperRadius * cosCache[slice]);
685
685
                        glVertex3f(lowerRadius * sinCache[slice], lowerY,
686
686
                                           lowerRadius * cosCache[slice]);
 
687
            polys++;
687
688
                }
688
689
                glNormal3f(0.0, 0.0, 1.0);
689
690
                glVertex3f(0.0, upperY, upperRadius);
690
691
                glVertex3f(0.0, lowerY, lowerRadius);
 
692
        polys++;
691
693
                glEnd();
692
694
 
693
695
                /* inside */
706
708
                                           upperRadius * cosCache[slice]);
707
709
                        glVertex3f(lowerRadius * sinCache[slice], lowerY,
708
710
                                           lowerRadius * cosCache[slice]);
 
711
            polys++;
709
712
                }
710
713
                glEnd();
711
714
        }
722
725
                                   innerRadius * cosCache[slice]);
723
726
 
724
727
                glVertex3f(radius * sinCache[slice], y, radius * cosCache[slice]);
 
728
        polys++;
725
729
        }
726
730
        glVertex3f(0.0, y, innerRadius);
727
731
        glVertex3f(0.0, y, radius);
728
732
        glEnd();
729
 
}
730
 
 
731
 
static void drawPole(GLfloat radius, GLfloat length)
732
 
{
733
 
        drawTube(radius, radius, radius, radius, length, NSLICE, NLOOPS);
734
 
}
735
 
 
736
 
static void drawDisk3D(GLdouble inner_radius, GLdouble outer_radius,
737
 
                                GLdouble height)
738
 
{
739
 
        drawTube(outer_radius, outer_radius, outer_radius - inner_radius,
740
 
                         outer_radius - inner_radius, height, NSLICE, NLOOPS);
741
 
}
742
 
 
743
 
static void drawCuboid(GLfloat length, GLfloat width, GLfloat height)
 
733
    return polys;
 
734
}
 
735
 
 
736
static int drawPole(GLfloat radius, GLfloat length)
 
737
{
 
738
  return drawTube(radius, radius, radius, radius, length, NSLICE, NLOOPS);
 
739
}
 
740
 
 
741
static int drawDisk3D(GLdouble inner_radius, GLdouble outer_radius,
 
742
                      GLdouble height)
 
743
{
 
744
  return drawTube(outer_radius, outer_radius, outer_radius - inner_radius,
 
745
                  outer_radius - inner_radius, height, NSLICE, NLOOPS);
 
746
}
 
747
 
 
748
static int drawCuboid(GLfloat length, GLfloat width, GLfloat height)
744
749
{
745
750
        GLfloat xmin = -length / 2.0f;
746
751
        GLfloat xmax = length / 2.0f;
748
753
        GLfloat zmax = width / 2.0f;
749
754
        GLfloat ymin = 0.0f;
750
755
        GLfloat ymax = height;
 
756
    int polys = 0;
751
757
 
752
758
        glBegin(GL_QUADS);
753
759
        /* front */
756
762
        glVertex3f(xmax, ymin, zmax);   /* 1 */
757
763
        glVertex3f(xmax, ymax, zmax);   /* 2 */
758
764
        glVertex3f(xmin, ymax, zmax);   /* 3 */
 
765
    polys++;
759
766
        /* right */
760
767
        glNormal3fv(right);
761
768
        glVertex3f(xmax, ymin, zmax);   /* 1 */
762
769
        glVertex3f(xmax, ymin, zmin);   /* 5 */
763
770
        glVertex3f(xmax, ymax, zmin);   /* 6 */
764
771
        glVertex3f(xmax, ymax, zmax);   /* 2 */
 
772
    polys++;
765
773
        /* back */
766
774
        glNormal3fv(back);
767
775
        glVertex3f(xmax, ymin, zmin);   /* 5 */
768
776
        glVertex3f(xmin, ymin, zmin);   /* 4 */
769
777
        glVertex3f(xmin, ymax, zmin);   /* 7 */
770
778
        glVertex3f(xmax, ymax, zmin);   /* 6 */
 
779
    polys++;
771
780
        /* left */
772
781
        glNormal3fv(left);
773
782
        glVertex3f(xmin, ymin, zmin);   /* 4 */
774
783
        glVertex3f(xmin, ymin, zmax);   /* 0 */
775
784
        glVertex3f(xmin, ymax, zmax);   /* 3 */
776
785
        glVertex3f(xmin, ymax, zmin);   /* 7 */
 
786
    polys++;
777
787
        /* top */
778
788
        glNormal3fv(up);
779
789
        glVertex3f(xmin, ymax, zmax);   /* 3 */
780
790
        glVertex3f(xmax, ymax, zmax);   /* 2 */
781
791
        glVertex3f(xmax, ymax, zmin);   /* 6 */
782
792
        glVertex3f(xmin, ymax, zmin);   /* 7 */
 
793
    polys++;
783
794
        /* bottom */
784
795
        glNormal3fv(down);
785
796
        glVertex3f(xmin, ymin, zmin);   /* 4 */
786
797
        glVertex3f(xmax, ymin, zmin);   /* 5 */
787
798
        glVertex3f(xmax, ymin, zmax);   /* 1 */
788
799
        glVertex3f(xmin, ymin, zmax);   /* 0 */
 
800
    polys++;
789
801
        glEnd();
 
802
    return polys;
790
803
}
791
804
 
792
 
static void drawDisks(glhcfg *glhanoi)
 
805
static int drawDisks(glhcfg *glhanoi)
793
806
{
794
807
        int i;
 
808
    int polys = 0;
795
809
 
796
810
        glPushMatrix();
797
811
        glTranslatef(0.0f, glhanoi->baseHeight, 0.0f);
808
822
                        glTranslatef(0.0, -glhanoi->diskHeight / 2.0, 0.0);
809
823
                }
810
824
                glCallList(disk->displayList);
 
825
        polys += disk->polys;
811
826
                glPopMatrix();
812
827
        }
813
828
        glPopMatrix();
 
829
    return polys;
814
830
}
815
831
 
816
832
static GLfloat getDiskRadius(glhcfg *glhanoi, int i)
1096
1112
        const float *col = cWhite;
1097
1113
        float texIncr = 1.0 / BOARD_SQUARES;
1098
1114
 
 
1115
    glhanoi->floorpolys = 0;
1099
1116
        if((glhanoi->floorList = glGenLists(1)) == 0) {
1100
1117
                fprintf(stderr, "can't allocate memory for floor display list\n");
1101
1118
                exit(EXIT_FAILURE);
1137
1154
 
1138
1155
                        glTexCoord2d(tx1, tz0);
1139
1156
                        glVertex3f(x1, 0.0, z0);
 
1157
            glhanoi->floorpolys++;
1140
1158
                        glEnd();
1141
1159
                }
1142
1160
        }
1151
1169
        }
1152
1170
        glNewList(glhanoi->baseList, GL_COMPILE);
1153
1171
        setMaterial(baseColor, cWhite, 50);
1154
 
        drawCuboid(glhanoi->baseLength, glhanoi->baseWidth,
1155
 
                           glhanoi->baseHeight);
 
1172
    glhanoi->basepolys = drawCuboid(glhanoi->baseLength, glhanoi->baseWidth,
 
1173
                                    glhanoi->baseHeight);
1156
1174
        glEndList();
1157
1175
 
1158
1176
 
1164
1182
        glPushMatrix();
1165
1183
        glTranslatef(0.0f, glhanoi->baseHeight, 0.0f);
1166
1184
        setMaterial(poleColor, cWhite, 50);
1167
 
        drawPole(glhanoi->poleRadius, glhanoi->poleHeight);
 
1185
    glhanoi->polepolys = drawPole(glhanoi->poleRadius, glhanoi->poleHeight);
1168
1186
        glPushMatrix();
1169
1187
        glTranslatef(-glhanoi->poleOffset, 0.0, 0.0);
1170
 
        drawPole(glhanoi->poleRadius, glhanoi->poleHeight);
 
1188
        glhanoi->polepolys += drawPole(glhanoi->poleRadius, glhanoi->poleHeight);
1171
1189
        glPopMatrix();
1172
1190
        glTranslatef(glhanoi->poleOffset, 0.0, 0.0);
1173
 
        drawPole(glhanoi->poleRadius, glhanoi->poleHeight);
 
1191
        glhanoi->polepolys += drawPole(glhanoi->poleRadius, glhanoi->poleHeight);
1174
1192
        glPopMatrix();
1175
1193
        glEndList();
1176
1194
}
1216
1234
                disk->rotation[0] = 0.0;
1217
1235
                disk->rotation[1] = 0.0;
1218
1236
                disk->rotation[2] = 0.0;
 
1237
                disk->polys = 0;
1219
1238
 
1220
1239
                color[0] = diskColor;
1221
1240
                color[1] = 1.0f;
1229
1248
                }
1230
1249
                glNewList(disk->displayList, GL_COMPILE);
1231
1250
                setMaterial(color, cWhite, 100.0);
1232
 
                drawDisk3D(glhanoi->poleRadius, 
1233
 
                           getDiskRadius(glhanoi, i),
1234
 
                           glhanoi->diskHeight);
 
1251
                disk->polys += drawDisk3D(glhanoi->poleRadius, 
 
1252
                                  getDiskRadius(glhanoi, i),
 
1253
                                  glhanoi->diskHeight);
1235
1254
                glEndList();
1236
1255
        }
1237
1256
        for(i = glhanoi->maxDiskIdx; i >= 0; --i) {
1263
1282
        }
1264
1283
}
1265
1284
 
1266
 
static void drawFloor(glhcfg *glhanoi)
 
1285
static int drawFloor(glhcfg *glhanoi)
1267
1286
{
1268
1287
        glCallList(glhanoi->floorList);
 
1288
    return glhanoi->floorpolys;
1269
1289
}
1270
1290
 
1271
 
static void drawTowers(glhcfg *glhanoi)
 
1291
static int drawTowers(glhcfg *glhanoi)
1272
1292
{
1273
1293
        glCallList(glhanoi->baseList);
1274
1294
        glCallList(glhanoi->poleList);
 
1295
    return glhanoi->basepolys + glhanoi->polepolys;
1275
1296
}
1276
1297
 
1277
1298
/* Window management, etc
1376
1397
        glPolygonMode(GL_FRONT, glhanoi->wire ? GL_LINE : GL_FILL);
1377
1398
 
1378
1399
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
 
1400
    mi->polygon_count = 0;
1379
1401
 
1380
1402
        glLoadIdentity();
1381
1403
 
1385
1407
        if(!glhanoi->wire && glhanoi->texture) {
1386
1408
                glEnable(GL_TEXTURE_2D);
1387
1409
        }
1388
 
        drawFloor(glhanoi);
 
1410
    mi->polygon_count += drawFloor(glhanoi);
1389
1411
        glDisable(GL_TEXTURE_2D);
1390
1412
 
1391
 
        drawTowers(glhanoi);
1392
 
        drawDisks(glhanoi);
 
1413
        mi->polygon_count += drawTowers(glhanoi);
 
1414
        mi->polygon_count += drawDisks(glhanoi);
1393
1415
 
1394
1416
        if(mi->fps_p) {
1395
1417
                do_fps(mi);