X-Git-Url: http://git.hungrycats.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=hacks%2Fglx%2Fblocktube.c;h=d4a402e71987ff11a277215d4955ac2d3ee82cbe;hb=78add6e627ee5f10e1fa6f3852602ea5066eee5a;hp=b38668b22ac2672e3f9b7515c0c59f34fe9dc30f;hpb=49f5b54f312fe4ac2e9bc47581a72451bd0e8439;p=xscreensaver diff --git a/hacks/glx/blocktube.c b/hacks/glx/blocktube.c index b38668b2..d4a402e7 100644 --- a/hacks/glx/blocktube.c +++ b/hacks/glx/blocktube.c @@ -16,9 +16,10 @@ #define DEFAULTS "*delay: 40000 \n" \ "*wireframe: False \n" \ "*showFPS: False \n" \ + "*suppressRotationAnimation: True\n" \ -# define refresh_blocktube 0 -# define blocktube_handle_event 0 +# define release_blocktube 0 +# define blocktube_handle_event xlockmore_no_events #undef countof #define countof(x) (sizeof((x))/sizeof((*x))) @@ -37,10 +38,10 @@ #if defined(USE_XPM) || defined(USE_XPMINC) || defined(STANDALONE) /* USE_XPM & USE_XPMINC in xlock mode ; HAVE_XPM in xscreensaver mode */ -#include "xpm-ximage.h" +#include "ximage-loader.h" #define I_HAVE_XPM -#include "../images/blocktube.xpm" +#include "images/gen/blocktube_png.h" #endif /* HAVE_XPM */ typedef struct { @@ -71,6 +72,7 @@ typedef struct { GLfloat tunnelLength; GLfloat tunnelWidth; + int polys; } blocktube_configuration; @@ -107,8 +109,8 @@ ENTRYPOINT ModeSpecOpt blocktube_opts = {countof(opts), opts, countof(vars), var #ifdef USE_MODULES ModStruct blocktube_description = - {"blocktube", "init_blocktube", "draw_blocktube", "release_blocktube", - "draw_blocktube", "init_blocktube", (char *)NULL, &blocktube_opts, + {"blocktube", "init_blocktube", "draw_blocktube", (char *)NULL, + "draw_blocktube", "init_blocktube", "free_blocktube", &blocktube_opts, 40000, 30, 1, 1, 64, 1.0, "", "A shifting tunnel of reflective blocks", 0, NULL}; #endif /* USE_MODULES */ @@ -122,18 +124,20 @@ static Bool LoadGLTextures(ModeInfo *mi) status = True; glGenTextures(1, &lp->envTexture); glBindTexture(GL_TEXTURE_2D, lp->envTexture); - lp->texti = xpm_to_ximage(MI_DISPLAY(mi), MI_VISUAL(mi), MI_COLORMAP(mi), - blocktube_xpm); + lp->texti = image_data_to_ximage(MI_DISPLAY(mi), MI_VISUAL(mi), + blocktube_png, sizeof(blocktube_png)); if (!lp->texti) { status = False; } else { glPixelStorei(GL_UNPACK_ALIGNMENT,1); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, lp->texti->width, lp->texti->height, 0, - GL_RGBA, GL_UNSIGNED_INT_8_8_8_8_REV, lp->texti->data); + GL_RGBA, GL_UNSIGNED_BYTE, lp->texti->data); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); +# ifndef HAVE_JWZGLES /* #### Sphere maps unimplemented */ glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP); glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP); +# endif } return status; } @@ -197,7 +201,7 @@ static void tick(blocktube_configuration *lp) } } -static void cube_vertices(float x, float y, float z, int wire); +static int cube_vertices(float x, float y, float z, int wire); ENTRYPOINT void reshape_blocktube (ModeInfo *mi, int width, int height); @@ -208,15 +212,7 @@ ENTRYPOINT void init_blocktube (ModeInfo *mi) blocktube_configuration *lp; int wire = MI_IS_WIREFRAME(mi); - if (!lps) { - lps = (blocktube_configuration *) - calloc (MI_NUM_SCREENS(mi), sizeof (blocktube_configuration)); - if (!lps) { - fprintf(stderr, "%s: out of memory\n", progname); - exit(1); - } - lp = &lps[MI_SCREEN(mi)]; - } + MI_INIT(mi, lps); lp = &lps[MI_SCREEN(mi)]; lp->glx_context = init_GL(mi); @@ -234,7 +230,7 @@ ENTRYPOINT void init_blocktube (ModeInfo *mi) lp->block_dlist = glGenLists (1); glNewList (lp->block_dlist, GL_COMPILE); - cube_vertices(0.15, 1.2, 5.25, wire); + lp->polys = cube_vertices(0.15, 1.2, 5.25, wire); glEndList (); #if defined( I_HAVE_XPM ) @@ -260,7 +256,6 @@ ENTRYPOINT void init_blocktube (ModeInfo *mi) glShadeModel(GL_SMOOTH); glEnable(GL_DEPTH_TEST); glEnable(GL_CULL_FACE); - glClearColor(0.0f, 0.0f, 0.0f, 0.0f); glClearDepth(1.0f); if (!do_texture && !wire) { @@ -292,38 +287,53 @@ ENTRYPOINT void init_blocktube (ModeInfo *mi) glFlush(); } -ENTRYPOINT void release_blocktube (ModeInfo *mi) +ENTRYPOINT void free_blocktube (ModeInfo *mi) { - if (lps) { - int screen; - for (screen = 0; screen < MI_NUM_SCREENS(mi); screen++) { - blocktube_configuration *lp = &lps[screen]; + blocktube_configuration *lp = &lps[MI_SCREEN(mi)]; # if defined ( I_HAVE_XPM ) - if (lp->envTexture) - glDeleteTextures(1, &lp->envTexture); - if (lp->texti) - XDestroyImage(lp->texti); -# endif - } - free (lps); - lps = 0; + if (lp->glx_context) { + glXMakeCurrent(MI_DISPLAY(mi), MI_WINDOW(mi), *(lp->glx_context)); + + if (lp->envTexture) + glDeleteTextures(1, &lp->envTexture); + if (lp->texti) + XDestroyImage(lp->texti); } - FreeAllGL(mi); +# endif } ENTRYPOINT void reshape_blocktube (ModeInfo *mi, int width, int height) { + blocktube_configuration *lp = &lps[MI_SCREEN(mi)]; GLfloat h = (GLfloat) height / (GLfloat) width; + int y = 0; - glViewport(0, 0, (GLint) width, (GLint) height); + glXMakeCurrent(MI_DISPLAY(mi), MI_WINDOW(mi), *(lp->glx_context)); + + if (width > height * 5) { /* tiny window: show middle */ + height = width; + y = -height/2; + h = height / (GLfloat) width; + } + + glViewport(0, y, (GLint) width, (GLint) height); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(45.0, 1/h, 1.0, 100.0); glMatrixMode(GL_MODELVIEW); + +# ifdef HAVE_MOBILE /* Keep it the same relative size when rotated. */ + { + int o = (int) current_device_rotation(); + if (o != 0 && o != 180 && o != -180) + glScalef (1/h, 1/h, 1/h); + } +# endif } -static void cube_vertices(float x, float y, float z, int wire) +static int cube_vertices(float x, float y, float z, int wire) { + int polygon_count = 0; float x2, y2, z2, nv = 0.7; x2 = x/2; y2 = y/2; @@ -337,6 +347,7 @@ static void cube_vertices(float x, float y, float z, int wire) glTexCoord2f(1.0, 0.0); glVertex3f( x2, y2, z2); glTexCoord2f(1.0, 1.0); glVertex3f( x2, -y2, z2); glTexCoord2f(0.0, 1.0); glVertex3f(-x2, -y2, z2); + polygon_count++; glEnd(); glNormal3f(0, 0, -nv); @@ -345,6 +356,7 @@ static void cube_vertices(float x, float y, float z, int wire) glTexCoord2f(1.0, 1.0); glVertex3f( x2, -y2, -z2); glTexCoord2f(0.0, 1.0); glVertex3f( x2, y2, -z2); glTexCoord2f(0.0, 0.0); glVertex3f(-x2, y2, -z2); + polygon_count++; glEnd(); glNormal3f(0, nv, 0); @@ -353,6 +365,7 @@ static void cube_vertices(float x, float y, float z, int wire) glTexCoord2f(0.0, 0.0); glVertex3f( x2, y2, -z2); glTexCoord2f(1.0, 0.0); glVertex3f( x2, y2, z2); glTexCoord2f(1.0, 1.0); glVertex3f(-x2, y2, z2); + polygon_count++; glEnd(); glNormal3f(0, -nv, 0); @@ -361,9 +374,10 @@ static void cube_vertices(float x, float y, float z, int wire) glTexCoord2f(0.0, 1.0); glVertex3f(-x2, -y2, z2); glTexCoord2f(0.0, 0.0); glVertex3f( x2, -y2, z2); glTexCoord2f(1.0, 0.0); glVertex3f( x2, -y2, -z2); + polygon_count++; glEnd(); - if (wire) return; + if (wire) return polygon_count; glNormal3f(nv, 0, 0); glBegin (wire ? GL_LINE_LOOP : GL_QUADS); @@ -371,6 +385,7 @@ static void cube_vertices(float x, float y, float z, int wire) glTexCoord2f(1.0, 1.0); glVertex3f( x2, -y2, z2); glTexCoord2f(0.0, 1.0); glVertex3f( x2, y2, z2); glTexCoord2f(0.0, 0.0); glVertex3f( x2, y2, -z2); + polygon_count++; glEnd(); glNormal3f(-nv, 0, 0); @@ -379,13 +394,17 @@ static void cube_vertices(float x, float y, float z, int wire) glTexCoord2f(1.0, 0.0); glVertex3f(-x2, y2, -z2); glTexCoord2f(1.0, 1.0); glVertex3f(-x2, y2, z2); glTexCoord2f(0.0, 1.0); glVertex3f(-x2, -y2, z2); + polygon_count++; glEnd(); + + return polygon_count; } static void draw_block(ModeInfo *mi, entity *ent) { blocktube_configuration *lp = &lps[MI_SCREEN(mi)]; glCallList (lp->block_dlist); + mi->polygon_count += lp->polys; } ENTRYPOINT void @@ -400,6 +419,8 @@ draw_blocktube (ModeInfo *mi) if (!lp->glx_context) return; + mi->polygon_count = 0; + glXMakeCurrent(MI_DISPLAY(mi), MI_WINDOW(mi), *(lp->glx_context)); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);