X-Git-Url: http://git.hungrycats.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=hacks%2Fglx%2Fglhanoi.c;h=865930f6736065653a841a6cd1ed57e0a5df37e1;hb=39809ded547bdbb08207d3e514950425215b4410;hp=6f52b3a1014e9f768dfb3cfaed5a24c4610e0c84;hpb=aa75c7476aeaa84cf3abc192b376a8b03c325213;p=xscreensaver diff --git a/hacks/glx/glhanoi.c b/hacks/glx/glhanoi.c index 6f52b3a1..865930f6 100644 --- a/hacks/glx/glhanoi.c +++ b/hacks/glx/glhanoi.c @@ -28,7 +28,7 @@ "*showFPS: False\n" \ "*wireframe: False\n" -# define refresh_glhanoi 0 +# define release_glhanoi 0 /* polygon resolution of poles and disks */ #define NSLICE 32 @@ -235,8 +235,8 @@ ENTRYPOINT ModeSpecOpt glhanoi_opts = { countof(opts), opts, countof(vars), vars #ifdef USE_MODULES ModStruct glhanoi_description = { - "glhanoi", "init_glhanoi", "draw_glhanoi", "release_glhanoi", - "draw_glhanoi", "init_glhanoi", NULL, &glhanoi_opts, + "glhanoi", "init_glhanoi", "draw_glhanoi", NULL, + "draw_glhanoi", "init_glhanoi", "free_glhanoi", &glhanoi_opts, 1000, 1, 2, 1, 4, 1.0, "", "Towers of Hanoi", 0, NULL }; @@ -1845,11 +1845,23 @@ static int drawTrails(glhcfg *glhanoi) { */ ENTRYPOINT void reshape_glhanoi(ModeInfo * mi, int width, int height) { - glViewport(0, 0, (GLint) width, (GLint) height); + glhcfg *glhanoi = &glhanoi_cfg[MI_SCREEN(mi)]; + double h = (GLfloat) height / (GLfloat) width; + int y = 0; + + if (width > height * 5) { /* tiny window: show middle */ + height = width * 9/16; + y = -height/2; + h = height / (GLfloat) width; + } + + glXMakeCurrent(MI_DISPLAY(mi), MI_WINDOW(mi), *(glhanoi->glx_context)); + + glViewport(0, y, (GLint) width, (GLint) height); glMatrixMode(GL_PROJECTION); glLoadIdentity(); - gluPerspective(30.0, (GLdouble) width / (GLdouble) height, 1.0, + gluPerspective(30.0, 1/h, 1.0, 2 * MAX_CAMERA_RADIUS); glMatrixMode(GL_MODELVIEW); @@ -1861,11 +1873,7 @@ ENTRYPOINT void reshape_glhanoi(ModeInfo * mi, int width, int height) ENTRYPOINT void init_glhanoi(ModeInfo * mi) { glhcfg *glhanoi; - if(!glhanoi_cfg) { - glhanoi_cfg = - (glhcfg *) calloc(MI_NUM_SCREENS(mi), sizeof(glhcfg)); - checkAllocAndExit(!!glhanoi_cfg, "configuration"); - } + MI_INIT(mi, glhanoi_cfg); glhanoi = &glhanoi_cfg[MI_SCREEN(mi)]; glhanoi->glx_context = init_GL(mi); @@ -2050,31 +2058,27 @@ ENTRYPOINT Bool glhanoi_handle_event(ModeInfo * mi, XEvent * event) return False; } -ENTRYPOINT void release_glhanoi(ModeInfo * mi) +ENTRYPOINT void free_glhanoi(ModeInfo * mi) { - if(glhanoi_cfg != NULL) { - int screen; - for(screen = 0; screen < MI_NUM_SCREENS(mi); screen++) { - int i; - int j; - glhcfg *glh = &glhanoi_cfg[screen]; - glDeleteLists(glh->floorList, 1); - glDeleteLists(glh->baseList, 1); - glDeleteLists(glh->poleList, 1); - glDeleteLists(glh->textureNames[0], 2); - for(j = 0; j < glh->numberOfDisks; ++j) { - glDeleteLists(glh->disk[j].displayList, 1); - } - free(glh->disk); - for(i = 0; i < glh->numberOfPoles; i++) { - if(glh->pole[i].data != NULL) { - free(glh->pole[i].data); - } + int i; + int j; + glhcfg *glh = &glhanoi_cfg[MI_SCREEN(mi)]; + if (glh->glx_context) { + glXMakeCurrent(MI_DISPLAY(mi), MI_WINDOW(mi), *(glh->glx_context)); + glDeleteLists(glh->floorList, 1); + glDeleteLists(glh->baseList, 1); + glDeleteLists(glh->poleList, 1); + glDeleteLists(glh->textureNames[0], 2); + for(j = 0; j < glh->numberOfDisks; ++j) { + glDeleteLists(glh->disk[j].displayList, 1); + } + free(glh->disk); + for(i = 0; i < glh->numberOfPoles; i++) { + if(glh->pole[i].data != NULL) { + free(glh->pole[i].data); } } } - free(glhanoi_cfg); - glhanoi_cfg = NULL; } XSCREENSAVER_MODULE ("GLHanoi", glhanoi)