-/* topblock, Copyright (c) 2006-2008
- * rednuht <topblock.xscreensaver@jumpstation.co.uk>
+/* topblock, Copyright (c) 2006-2012 rednuht <topblock.xscreensaver@jumpstation.co.uk>
*
* Permission to use, copy, modify, distribute, and sell this software and its
* documentation for any purpose is hereby granted without fee, provided that
#include "xlockmore.h"
#include "topblock.h"
#include "sphere.h"
+#include "tube.h"
#include "gltrackball.h"
#include <ctype.h>
#ifdef USE_GL /* whole file */
-#ifdef HAVE_COCOA
-# include <OpenGL/glu.h>
-#else
+#ifndef HAVE_COCOA
# include <GL/glu.h>
#endif
int plusheight;
GLuint carpet;
GLuint block;
+ int carpet_polys, block_polys;
NODE *blockNodeRoot;
NODE *blockNodeFollow;
GLfloat rotation;
} topBlockSTATE;
/* parameter vars */
-Bool override;
-Bool rotate;
-Bool follow;
-Bool drawCarpet;
-Bool drawBlob;
-Bool drawNipples;
-GLfloat rotateSpeed;
-GLfloat camX;
-GLfloat camY;
-GLfloat camZ;
-GLfloat dropSpeed;
-int maxFalling;
-int maxColors;
-int size;
-int spawn;
-int resolution;
+static Bool override;
+static Bool rotate;
+static Bool follow;
+static Bool drawCarpet;
+static Bool drawBlob;
+static Bool drawNipples;
+static GLfloat rotateSpeed;
+static GLfloat camX;
+static GLfloat camY;
+static GLfloat camZ;
+static GLfloat dropSpeed;
+static int maxFalling;
+static int maxColors;
+static int size;
+static int spawn;
+static int resolution;
static XrmOptionDescRec opts[] = {
{ "-size", ".size", XrmoptionSepArg, 0 },
{ "-override", ".override", XrmoptionNoArg, "True" },
};
-#define DEF_override "False"
-#define DEF_rotate "True"
-#define DEF_follow "False"
-#define DEF_drawCarpet "True"
-#define DEF_drawBlob "False"
-#define DEF_drawNipples "True"
-#define DEF_rotateSpeed "10"
-#define DEF_maxFalling "500"
-#define DEF_maxColors "7"
-#define DEF_size "2"
-#define DEF_spawn "50"
-#define DEF_resolution "4"
-#define DEF_camX "1"
-#define DEF_camY "20"
-#define DEF_camZ "25"
-#define DEF_dropSpeed "4"
+#define DEF_OVERRIDE "False"
+#define DEF_ROTATE "True"
+#define DEF_FOLLOW "False"
+#define DEF_CARPET "True"
+#define DEF_BLOB "False"
+#define DEF_NIPPLES "True"
+#define DEF_ROTATE_SPEED "10"
+#define DEF_MAX_FALLING "500"
+#define DEF_MAX_COLORS "7"
+#define DEF_SIZE "2"
+#define DEF_SPAWN "50"
+#define DEF_RESOLUTION "4"
+#define DEF_CAM_X "1"
+#define DEF_CAM_Y "20"
+#define DEF_CAM_Z "25"
+#define DEF_DROP_SPEED "4"
static argtype vars[] = {
- {&override, "override", "Override", DEF_override, t_Bool},
- {&rotate, "rotate", "Rotate", DEF_rotate, t_Bool},
- {&drawCarpet, "carpet", "Carpet", DEF_drawCarpet, t_Bool},
- {&drawNipples, "nipples", "Nipples", DEF_drawNipples, t_Bool},
- {&drawBlob, "blob", "Blob", DEF_drawBlob, t_Bool},
- {&rotateSpeed, "rotateSpeed", "RotateSpeed", DEF_rotateSpeed, t_Float},
- {&follow, "follow", "Follow", DEF_follow, t_Bool},
- {&camX, "camX", "camX", DEF_camX, t_Float},
- {&camY, "camY", "camY", DEF_camY, t_Float},
- {&camZ, "camZ", "camZ", DEF_camZ, t_Float},
- {&size, "size", "size", DEF_size, t_Int},
- {&spawn, "spawn", "spawn", DEF_spawn, t_Int},
- {&maxFalling, "maxFalling", "maxFalling", DEF_maxFalling, t_Int},
- {&resolution, "resolution", "resolution", DEF_resolution, t_Int},
- {&maxColors, "maxColors", "maxColors", DEF_maxColors, t_Int},
- {&dropSpeed, "dropSpeed", "DropSpeed", DEF_dropSpeed, t_Float},
+ {&override, "override", "Override", DEF_OVERRIDE, t_Bool},
+ {&rotate, "rotate", "Rotate", DEF_ROTATE, t_Bool},
+ {&drawCarpet, "carpet", "Carpet", DEF_CARPET, t_Bool},
+ {&drawNipples, "nipples", "Nipples", DEF_NIPPLES, t_Bool},
+ {&drawBlob, "blob", "Blob", DEF_BLOB, t_Bool},
+ {&rotateSpeed, "rotateSpeed", "RotateSpeed", DEF_ROTATE_SPEED, t_Float},
+ {&follow, "follow", "Follow", DEF_FOLLOW, t_Bool},
+ {&camX, "camX", "camX", DEF_CAM_X, t_Float},
+ {&camY, "camY", "camY", DEF_CAM_Y, t_Float},
+ {&camZ, "camZ", "camZ", DEF_CAM_Z, t_Float},
+ {&size, "size", "size", DEF_SIZE, t_Int},
+ {&spawn, "spawn", "spawn", DEF_SPAWN, t_Int},
+ {&maxFalling, "maxFalling", "maxFalling", DEF_MAX_FALLING, t_Int},
+ {&resolution, "resolution", "resolution", DEF_RESOLUTION, t_Int},
+ {&maxColors, "maxColors", "maxColors", DEF_MAX_COLORS, t_Int},
+ {&dropSpeed, "dropSpeed", "DropSpeed", DEF_DROP_SPEED, t_Float},
};
static topBlockSTATE *tbs = NULL;
-ModeSpecOpt topBlock_opts = {countof(opts), opts, countof(vars), vars, NULL};
+static ModeSpecOpt topBlock_opts = {countof(opts), opts, countof(vars), vars, NULL};
/* Window management, etc */
ENTRYPOINT void
-reshape_topBlock (ModeInfo *mi, int width, int height) {
+reshape_topBlock (ModeInfo *mi, int width, int height)
+{
GLfloat h = (GLfloat) height / (GLfloat) width;
glViewport (0, 0, (GLint) width, (GLint) height);
glMatrixMode(GL_PROJECTION);
/* clean up on exit, not required ... */
ENTRYPOINT void
- release_topBlock(ModeInfo *mi) {
+release_topBlock(ModeInfo *mi)
+{
topBlockSTATE *tb = &tbs[MI_SCREEN(mi)];
NODE *llCurrent, *llOld;
llCurrent = tb->blockNodeRoot;
if (!tbs) {
tbs = (topBlockSTATE *)
calloc (MI_NUM_SCREENS(mi), sizeof (topBlockSTATE));
- if (!tbs) {
- fprintf(stderr, "%s: out of memory\n", progname);
- exit(1);
- }
+ if (!tbs) abort();
}
tb = &tbs[MI_SCREEN(mi)];
reshape_topBlock (mi, MI_WIDTH(mi), MI_HEIGHT(mi));
- if (wire) { drawNipples=False; }
+/* if (wire) { drawNipples=False; }*/
tb->numFallingBlocks=0;
if (size>10) { size = 10; }
dropSpeed = 80/dropSpeed;
dropSpeed = (blockHeight/dropSpeed);
- tb->glx_context = init_GL(mi);
-
reshape_topBlock (mi, MI_WIDTH(mi), MI_HEIGHT(mi));
- if (0==1) {
- glClearColor(1.0f, 1.0f, 1.0f, 0.5f);
- } else {
- glClearColor(0.0f, 0.0f, 0.0f, 0.5f);
- }
glClearDepth(1.0f);
if (!wire) {
GLfloat pos[4] = {10.0, 10.0, 1.0, 0.0};
/* provides the per frame entertainment */
ENTRYPOINT void
-draw_topBlock (ModeInfo *mi) {
+draw_topBlock (ModeInfo *mi)
+{
Display *dpy = MI_DISPLAY(mi);
Window window = MI_WINDOW(mi);
NODE *llCurrent;
if (!tb->glx_context)
return;
glXMakeCurrent(MI_DISPLAY(mi), MI_WINDOW(mi), *(tb->glx_context));
+ mi->polygon_count = 0;
generateNewBlock(mi);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); /* clear current */
glLoadIdentity(); /* resets directions, do it every time ! */
+ glRotatef(current_device_rotation(), 0, 0, 1);
+
if (!follow) {
if (tb->highest>tb->eyeLine) { tb->eyeLine+=((tb->highest-tb->eyeLine)/100); } /* creates a smooth camera transition */
gluLookAt(camX, camY+tb->eyeLine, camZ, tb->eyeX, tb->eyeY+tb->eyeLine, tb->eyeZ, 0.0, 1.0, 0.0); /* setup viewer, xyz cam, xyz looking at and where is up normaly 0,1,0 */
glRotatef(90, 0.0, 0.0, 1.0); /* z axis */
followBlock(mi);
}
- glRotatef(-90, 1.0, 0.0, 0.0);
- gltrackball_rotate (tb->trackball);
- glRotatef(90, 1.0, 0.0, 0.0);
+
+ /* Rotate the scene around a point that's a little higher up. */
+ glTranslatef (0, 0, -5);
+ gltrackball_rotate (tb->trackball);
+ glTranslatef (0, 0, 5);
/* rotate the world */
glRotatef(tb->rotation, 0.0, 0.0, 1.0);
/* center carpet */
glTranslatef(0.0-(tb->carpetWidth/2),0.0-(tb->carpetLength/2),0.0);
glCallList(tb->carpet);
+ mi->polygon_count += tb->carpet_polys;
glTranslatef(0.0+(tb->carpetWidth/2),0.0+(tb->carpetLength/2),0.0);
glTranslatef(0.0,0.0,-0.55);
}
llCurrent = llCurrent->next;
/* draw */
glCallList(tb->block);
+ mi->polygon_count += tb->block_polys;
glPopMatrix(); /* restore state */
}
if (mi->fps_p) do_fps (mi);
/* camera is in follow mode, work out where we should be looking */
-static void followBlock(ModeInfo *mi) {
+static void followBlock(ModeInfo *mi)
+{
GLfloat xLen,yLen,cx,cy,rangle,xTarget,yTarget;
topBlockSTATE *tb = &tbs[MI_SCREEN(mi)];
cx=0;cy=0;
}
/* each quater of the circle has to be adjusted for */
-static double quadrantCorrection(double angle,int cx,int cy,int x,int y) {
+static double quadrantCorrection(double angle,int cx,int cy,int x,int y)
+{
if ((x>=cx) && (y>=cy)) {
angle += (90-(angle-90) * 2);
} else if ((x>=cx) && (y<=cy)) {
}
/* if random chance then create a new falling block */
-static void generateNewBlock(ModeInfo *mi) {
+static void generateNewBlock(ModeInfo *mi)
+{
NODE *llCurrent, *llTail;
GLfloat startOffx, startOffy;
int endOffx, endOffy;
tb->numFallingBlocks++;
llTail = tb->blockNodeRoot;
if (llTail == NULL) {
- if ((llCurrent = ((NODE*) malloc(sizeof(NODE)))) == NULL) { fprintf(stderr, "%s: out of memory.\n", progname); }
- llTail = llCurrent;
- tb->blockNodeRoot = llCurrent;
+ llCurrent = ((NODE*) malloc(sizeof(NODE)));
+ if (!llCurrent) abort();
+ llTail = llCurrent;
+ tb->blockNodeRoot = llCurrent;
} else {
if (tb->numFallingBlocks>=maxFalling) {
/* recycle */
llCurrent=llTail->next;
tb->blockNodeRoot=llCurrent->next;
} else {
- if ((llCurrent = ((NODE*) malloc(sizeof(NODE)))) == NULL) { fprintf(stderr, "%s: out of memory..\n", progname); }
+ llCurrent = ((NODE*) malloc(sizeof(NODE)));
+ if (!llCurrent) abort();
}
while (llTail->next != NULL) { llTail = llTail->next; } /* find last item in list */
}
}
/* called at init this creates the 'carpet' display list item */
-static void buildCarpet(ModeInfo *mi) {
+static void buildCarpet(ModeInfo *mi)
+{
int i,c,x,y;
GLfloat color[4];
int wire = MI_IS_WIREFRAME(mi);
topBlockSTATE *tb = &tbs[MI_SCREEN(mi)];
- GLUquadricObj *quadratic;
color[0] = 0.0f;
color[1] = 1.0f;
color[2] = 0.0f;
color[3] = 1.0f;
tb->carpet=glGenLists(1); /* only one */
glNewList(tb->carpet,GL_COMPILE);
+ tb->carpet_polys=0;
glPushMatrix(); /* save state */
x=tb->carpetWidth;
y=tb->carpetLength;
glVertex3f(x,0.0,0.0);
glVertex3f(x,y,0.0);
glVertex3f(0.0,y,0.0);
- if (wire) { glEnd(); }
- else {
+ tb->carpet_polys++;
+ if (!wire) {
/* add edge pieces */
/* side 1 */
glNormal3f( 0, -1, 0 );
glVertex3f(x,0.0,0.0);
glVertex3f(x,0,singleThick);
glVertex3f(0.0,0,singleThick);
+ tb->carpet_polys++;
/* side 2 */
glNormal3f( -1, 0, 0 );
glVertex3f(0.0,0.0,0.0);
glVertex3f(0,y,0.0);
glVertex3f(0,y,singleThick);
glVertex3f(0.0,0,singleThick);
+ tb->carpet_polys++;
/* side 3 */
glNormal3f( 1, 0, 0 );
glVertex3f(x,0.0,0.0);
glVertex3f(x,y,0.0);
glVertex3f(x,y,singleThick);
glVertex3f(x,0,singleThick);
+ tb->carpet_polys++;
/* side 4 */
glNormal3f( 0, 1, 0 );
glVertex3f(0,y,0.0);
glVertex3f(x,y,0.0);
glVertex3f(x,y,singleThick);
glVertex3f(0,y,singleThick);
+ tb->carpet_polys++;
}
glEnd();
/* nipples */
if (drawNipples) {
- quadratic=gluNewQuadric(); /* Create A Pointer To The Quadric Object */
- gluQuadricNormals(quadratic, GLU_SMOOTH); /* Create Smooth Normals */
- gluQuadricTexture(quadratic, GL_TRUE); /* Create Texture Coords */
glTranslatef(0.5f,0.5f,-.25); /* move to the cylinder center */
for (c=0;c<x;c++) {
glPushMatrix(); /* save state */
for (i=0;i<y;i++) {
- gluCylinder(quadratic, cylSize, cylSize, 0.25f, resolution, resolution); /* quad, radius(bottom, radius(top), height, subdivisions (around Z), subdevisions (along Z) */
- glRotatef(180, 0.0f, 1.0f, 0.0f); /* they are upside down */
- gluDisk(quadratic, 0.0f, cylSize, resolution, resolution ); /* inner size (cd hole), outer size (radius), subdivisions radial, subdivisions circular */
- glRotatef(180, 0.0f, 1.0f, 0.0f); /* recover */
- glTranslatef(0.0f,1.0f,0.0f); /* move to the next cylinder center (backward) */
+ tb->carpet_polys += tube(0, 0, -0.1,
+ 0, 0, 0.26,
+ cylSize, 0,
+ resolution, True, True,
+ wire);
+ glRotatef(180, 0.0f, 1.0f, 0.0f); /* they are upside down */
+ glRotatef(180, 0.0f, 1.0f, 0.0f); /* recover */
+ glTranslatef(0.0f,1.0f,0.0f); /* move to the next cylinder center (backward) */
}
glPopMatrix(); /* save state */
glTranslatef(1.0f,0.0f,0.0f); /* reset */
/* called at init this creates the 'block' display list item */
/* the spheres came about originaly as quick way to test the directional lighting/normals */
-static void buildBlock(ModeInfo *mi) {
+static void buildBlock(ModeInfo *mi)
+{
int i,c;
int wire = MI_IS_WIREFRAME(mi);
topBlockSTATE *tb = &tbs[MI_SCREEN(mi)];
- GLUquadricObj *quadratic;
tb->block=glGenLists(1); /* only one */
glNewList(tb->block,GL_COMPILE);
+ tb->block_polys=0;
glPushMatrix(); /* save state */
glRotatef(90, 0.0f, 1.0f, 0.0f);
/* base */
- polygonPlane(wire, 0,3,2,1,0);
- polygonPlane(wire, 2,3,7,6,1);
- polygonPlane(wire, 1,2,6,5,2);
- polygonPlane(wire, 4,5,6,7,3);
- polygonPlane(wire, 0,1,5,4,4);
+ polygonPlane(wire, 0,3,2,1,0); tb->block_polys++;
+ polygonPlane(wire, 2,3,7,6,1); tb->block_polys++;
+ polygonPlane(wire, 1,2,6,5,2); tb->block_polys++;
+ polygonPlane(wire, 4,5,6,7,3); tb->block_polys++;
+ polygonPlane(wire, 0,1,5,4,4); tb->block_polys++;
if (drawNipples) {
/* nipples */
/* draw 8 cylinders each with a disk cap */
- quadratic=gluNewQuadric(); /* Create A Pointer To The Quadric Object */
- gluQuadricNormals(quadratic, GLU_SMOOTH); /* Create Smooth Normals */
glRotatef(90, 0.0f, 1.0f, 0.0f); /* 'aim' the pointer ready for the cylinder */
glTranslatef(0.5f,0.5f,0.99f); /* move to the cylinder center */
for (c=0;c<2;c++) {
for (i=0;i<4;i++) {
- gluCylinder(quadratic, cylSize, cylSize, 0.25f, resolution, resolution); /* quad, radius(bottom, radius(top), height, subdivisions (around Z), subdevisions (along Z) */
+ tb->block_polys += tube(0, 0, 0,
+ 0, 0, 0.25,
+ cylSize, 0,
+ resolution, True, True,
+ wire);
glTranslatef(0.0f,0.0f,0.25f); /* move to the cylinder cap */
- gluDisk(quadratic, 0.0f, cylSize, resolution, resolution ); /* inner size (cd hole), outer size (radius), subdivisions radial, subdivisions circular */
glTranslatef(0.0f,0.0f,-0.25f); /* move back from the cylinder cap */
if (c==0) {
glTranslatef(0.0f,-1.0f,0.0f); /* move to the next cylinder center (forward) */
/* udders */
/* 3 cylinders on the underside */
glTranslatef(1.5f,-2.5f,-1.5f); /* move to the center, under the top of the brick */
+ if (! wire)
for (c=0;c<3;c++) {
- gluCylinder(quadratic, uddSize, uddSize, 1.5f, resolution, resolution); /* quad, radius(bottom, radius(top), height, subdivisions (around Z), subdevisions (along Z) */
- glTranslatef(0.0f,-1.0f,0.0f); /* move to the center */
+ tb->block_polys += tube(0, 0, 0.1,
+ 0, 0, 1.4,
+ uddSize, 0,
+ resolution, True, True, wire);
+ glTranslatef(0.0f,-1.0f,0.0f); /* move to the center */
}
}
glPopMatrix(); /* restore state */
rip off of the builBlock() function creating the GL compilied pointer "block" but only creates two spheres.
spheres are created with unit_sphere from spheres.h to allow wire frame
*/
-static void buildBlobBlock(ModeInfo *mi) {
+static void buildBlobBlock(ModeInfo *mi)
+{
int wire = MI_IS_WIREFRAME(mi);
topBlockSTATE *tb = &tbs[MI_SCREEN(mi)];
tb->block=glGenLists(1); /* only one */
/* handle input events or not if daemon running the show */
ENTRYPOINT Bool
-topBlock_handle_event (ModeInfo *mi, XEvent *event) {
+topBlock_handle_event (ModeInfo *mi, XEvent *event)
+{
topBlockSTATE *tb = &tbs[MI_SCREEN(mi)];
if (event->xany.type == KeyPress) {
KeySym keysym;
}
/* this is tha main change for v5 compatability and acompanying ENTRYPOINTS */
-XSCREENSAVER_MODULE_2 ("topBlock", topblock, topBlock)
+XSCREENSAVER_MODULE_2 ("TopBlock", topblock, topBlock)
#endif /* USE_GL */