X-Git-Url: http://git.hungrycats.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=hacks%2Fglx%2Fjuggler3d.c;h=031502912cc5584eede216f33ddf86bfec725e9c;hb=39809ded547bdbb08207d3e514950425215b4410;hp=5697ed263af32c44e98aed77dde5e2e6320627c5;hpb=f0261d8acab611f3433160e4f07367b870439739;p=xscreensaver diff --git a/hacks/glx/juggler3d.c b/hacks/glx/juggler3d.c index 5697ed26..03150291 100644 --- a/hacks/glx/juggler3d.c +++ b/hacks/glx/juggler3d.c @@ -131,11 +131,11 @@ "*count: 200 \n" \ "*cycles: 1000 \n" \ "*ncolors: 32 \n" \ - "*titleFont: -*-helvetica-bold-r-normal-*-180-*\n" \ + "*titleFont: -*-helvetica-bold-r-normal-*-*-180-*-*-*-*-*-*\n" \ "*showFPS: False \n" \ "*wireframe: False \n" \ -# define refresh_juggle 0 +# define release_juggle 0 #undef countof #define countof(x) (sizeof((x))/sizeof((*x))) @@ -144,7 +144,7 @@ #include "tube.h" #include "rotator.h" #include "gltrackball.h" -#include "glxfonts.h" +#include "texfont.h" #include #ifdef USE_GL /* whole file */ @@ -579,9 +579,7 @@ typedef struct { ObjType objtypes; Object *objects; struct patternindex patternindex; - - XFontStruct *mode_font; - GLuint font_dlist; + texture_font_data *font_data; } jugglestruct; static jugglestruct *juggles = (jugglestruct *) NULL; @@ -638,8 +636,10 @@ trajectory_destroy(Trajectory *t) { REMOVE(t); /* Unlink and free */ } -static void -free_juggle(jugglestruct *sp) { +ENTRYPOINT void +free_juggle(ModeInfo *mi) { + jugglestruct *sp = &juggles[MI_SCREEN(mi)]; + if (sp->head != NULL) { while (sp->head->next != sp->head) { trajectory_destroy(sp->head->next); @@ -658,20 +658,17 @@ free_juggle(jugglestruct *sp) { free(sp->pattern); sp->pattern = NULL; } - if (sp->mode_font!=None) { - XFreeFontInfo(NULL,sp->mode_font,1); - sp->mode_font = None; - } } static Bool -add_throw(jugglestruct *sp, char type, int h, Notation n, const char* name) +add_throw(ModeInfo *mi, char type, int h, Notation n, const char* name) { + jugglestruct *sp = &juggles[MI_SCREEN(mi)]; Trajectory *t; ADD_ELEMENT(Trajectory, t, sp->head->prev); if(t == NULL){ /* Out of Memory */ - free_juggle(sp); + free_juggle(mi); return False; } t->object = NULL; @@ -693,7 +690,6 @@ add_throw(jugglestruct *sp, char type, int h, Notation n, const char* name) static Bool program(ModeInfo *mi, const char *patn, const char *name, int cycles) { - jugglestruct *sp = &juggles[MI_SCREEN(mi)]; const char *p; int w, h, i, seen; Notation notation; @@ -745,7 +741,7 @@ program(ModeInfo *mi, const char *patn, const char *name, int cycles) case ' ': if (seen) { i++; - if (!add_throw(sp, type, h, notation, title)) + if (!add_throw(mi, type, h, notation, title)) return False; title = NULL; type=' '; @@ -765,7 +761,7 @@ program(ModeInfo *mi, const char *patn, const char *name, int cycles) } } if (seen) { /* end of sequence */ - if (!add_throw(sp, type, h, notation, title)) + if (!add_throw(mi, type, h, notation, title)) return False; title = NULL; } @@ -866,8 +862,9 @@ name(jugglestruct *sp) /* ..nm.. -> .. LTn LC RTm RC .. */ static Bool -part(jugglestruct *sp) +part(ModeInfo *mi) { + jugglestruct *sp = &juggles[MI_SCREEN(mi)]; Trajectory *t, *nt, *p; Hand hand = (LRAND() & 1) ? RIGHT : LEFT; @@ -912,7 +909,7 @@ part(jugglestruct *sp) t->action = CATCH; ADD_ELEMENT(Trajectory, nt, p); if(nt == NULL){ - free_juggle(sp); + free_juggle(mi); return False; } nt->object = NULL; @@ -1696,6 +1693,8 @@ show_arms(ModeInfo * mi) int soffx = 10; int soffy = 11; + glFrontFace(GL_CCW); + j = 1; for(side = LEFT; side <= RIGHT; side = (Hand)((int)side + 1)) { /* Translate into device coords */ @@ -1799,6 +1798,8 @@ show_figure(ModeInfo * mi, Bool init) glMaterialfv (GL_FRONT, GL_AMBIENT_AND_DIFFUSE, gcolor); + glFrontFace(GL_CCW); + { GLfloat scale = ((GLfloat) a[10].x - a[9].x) / 2; int slices = 12; @@ -2065,6 +2066,8 @@ show_ball(ModeInfo *mi, unsigned long color, Trace *s) gcolor2[1] = gcolor1[1] / 3; gcolor2[2] = gcolor1[2] / 3; + glFrontFace(GL_CCW); + { GLfloat scale = BALLRADIUS; glPushMatrix(); @@ -2092,8 +2095,7 @@ show_europeanclub(ModeInfo *mi, unsigned long color, Trace *s) GLfloat gcolor1[4] = { 0, 0, 0, 1 }; GLfloat gcolor2[4] = { 1, 1, 1, 1 }; int slices = 16; - int divs = s->divisions; - divs = 4; + int divs = 4; /* 6 6 +-+ @@ -2120,6 +2122,8 @@ show_europeanclub(ModeInfo *mi, unsigned long color, Trace *s) gcolor1[1] = mi->colors[color].green / 65536.0; gcolor1[2] = mi->colors[color].blue / 65536.0; + glFrontFace(GL_CCW); + { GLfloat scale = radius; glPushMatrix(); @@ -2241,6 +2245,8 @@ show_knife(ModeInfo *mi, unsigned long color, Trace *s) gcolor1[1] = mi->colors[color].green / 65536.0; gcolor1[2] = mi->colors[color].blue / 65536.0; + glFrontFace(GL_CCW); + glPushMatrix(); glTranslatef(x, y, 0); glScalef (2, 2, 2); @@ -2299,6 +2305,8 @@ show_ring(ModeInfo *mi, unsigned long color, Trace *s) gcolor2[1] = gcolor1[1] / 3; gcolor2[2] = gcolor1[2] / 3; + glFrontFace(GL_CCW); + glPushMatrix(); glTranslatef(0, 0, 12); /* back of ring in hand */ @@ -2318,11 +2326,12 @@ show_ring(ModeInfo *mi, unsigned long color, Trace *s) glNormal3f (0, 0, j*1); glBegin (wire_p ? GL_LINES : GL_QUAD_STRIP); for (i = 0; i < slices + (wire_p ? 0 : 1); i++) { + GLfloat th, cth, sth; glMaterialfv (GL_FRONT, GL_AMBIENT_AND_DIFFUSE, (i % (slices/3) ? gcolor1 : gcolor2)); - GLfloat th = i * width; - GLfloat cth = cos(th); - GLfloat sth = sin(th); + th = i * width; + cth = cos(th); + sth = sin(th); glVertex3f (cth * ra, sth * ra, z); glVertex3f (cth * rb, sth * rb, z); polys++; @@ -2387,6 +2396,8 @@ show_bball(ModeInfo *mi, unsigned long color, Trace *s) gcolor1[1] = mi->colors[color].green / 65536.0; gcolor1[2] = mi->colors[color].blue / 65536.0; + glFrontFace(GL_CCW); + { GLfloat scale = radius; glPushMatrix(); @@ -2433,19 +2444,6 @@ show_bball(ModeInfo *mi, unsigned long color, Trace *s) **************************************************************************/ -ENTRYPOINT void -release_juggle (ModeInfo * mi) -{ - if (juggles != NULL) { - int screen; - - for (screen = 0; screen < MI_NUM_SCREENS(mi); screen++) - free_juggle(&juggles[screen]); - free(juggles); - juggles = (jugglestruct *) NULL; - } -} - /* FIXME: refill_juggle currently just appends new throws to the * programme. This is fine if the programme is empty, but if there * are still some trajectories left then it really should take these @@ -2562,7 +2560,7 @@ refill_juggle(ModeInfo * mi) name(sp); - if (!part(sp)) + if (!part(mi)) return; lob(mi); @@ -2572,7 +2570,7 @@ refill_juggle(ModeInfo * mi) positions(sp); if (!projectile(sp)) { - free_juggle(sp); + free_juggle(mi); return; } @@ -2637,22 +2635,17 @@ init_juggle (ModeInfo * mi) jugglestruct *sp = 0; int wire = MI_IS_WIREFRAME(mi); - if (!juggles) { - juggles = (jugglestruct *) - calloc (MI_NUM_SCREENS(mi), sizeof (jugglestruct)); - if (!juggles) { - fprintf(stderr, "%s: out of memory\n", progname); - exit(1); - } - } + MI_INIT (mi, juggles); sp = &juggles[MI_SCREEN(mi)]; - sp->glx_context = init_GL(mi); + if (!sp->glx_context) /* re-initting breaks print_texture_label */ + sp->glx_context = init_GL(mi); - load_font (mi->dpy, "titleFont", &sp->mode_font, &sp->font_dlist); + sp->font_data = load_texture_font (mi->dpy, "titleFont"); reshape_juggle (mi, MI_WIDTH(mi), MI_HEIGHT(mi)); + clear_gl_error(); /* WTF? sometimes "invalid op" from glViewport! */ if (!wire) { @@ -2682,7 +2675,7 @@ init_juggle (ModeInfo * mi) double spin_accel = 0.05; sp->rot = make_rotator (0, spin_speed, 0, spin_accel, wander_speed, False); - sp->trackball = gltrackball_init (); + sp->trackball = gltrackball_init (False); } if (only && *only && strcmp(only, " ")) { @@ -2736,14 +2729,14 @@ init_juggle (ModeInfo * mi) /* create circular trajectory list */ ADD_ELEMENT(Trajectory, sp->head, sp->head); if(sp->head == NULL){ - free_juggle(sp); + free_juggle(mi); return; } /* create circular object list */ ADD_ELEMENT(Object, sp->objects, sp->objects); if(sp->objects == NULL){ - free_juggle(sp); + free_juggle(mi); return; } @@ -2806,51 +2799,15 @@ juggle_handle_event (ModeInfo *mi, XEvent *event) { jugglestruct *sp = &juggles[MI_SCREEN(mi)]; - if (event->xany.type == ButtonPress && - event->xbutton.button == Button1) - { - sp->button_down_p = True; - gltrackball_start (sp->trackball, - event->xbutton.x, event->xbutton.y, - MI_WIDTH (mi), MI_HEIGHT (mi)); - return True; - } - else if (event->xany.type == ButtonRelease && - event->xbutton.button == Button1) - { - sp->button_down_p = False; - return True; - } - else if (event->xany.type == ButtonPress && - (event->xbutton.button == Button4 || - event->xbutton.button == Button5 || - event->xbutton.button == Button6 || - event->xbutton.button == Button7)) + if (gltrackball_event_handler (event, sp->trackball, + MI_WIDTH (mi), MI_HEIGHT (mi), + &sp->button_down_p)) + return True; + else if (screenhack_event_helper (MI_DISPLAY(mi), MI_WINDOW(mi), event)) { - gltrackball_mousewheel (sp->trackball, event->xbutton.button, 10, - !!event->xbutton.state); + change_juggle (mi); return True; } - else if (event->xany.type == MotionNotify && - sp->button_down_p) - { - gltrackball_track (sp->trackball, - event->xmotion.x, event->xmotion.y, - MI_WIDTH (mi), MI_HEIGHT (mi)); - return True; - } - else if (event->xany.type == KeyPress) - { - KeySym keysym; - char c = 0; - XLookupString (&event->xkey, &c, 1, &keysym, 0); - if (c == ' ' || c == '\n' || c == '\r' || c == '\t') - { - change_juggle (mi); - return True; - } - } - return False; } @@ -2882,6 +2839,7 @@ draw_juggle (ModeInfo *mi) glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glPushMatrix (); + glRotatef(current_device_rotation(), 0, 0, 1); glTranslatef(0,-3,0); @@ -3035,12 +2993,10 @@ draw_juggle (ModeInfo *mi) } } - if(sp->mode_font != None) { - print_gl_string (mi->dpy, sp->mode_font, sp->font_dlist, - mi->xgwa.width, mi->xgwa.height, - 10, mi->xgwa.height - 10, - sp->pattern, False); - } + glColor3f (1, 1, 0); + print_texture_label (mi->dpy, sp->font_data, + mi->xgwa.width, mi->xgwa.height, + 1, sp->pattern); #ifdef MEMTEST if((int)(sp->time/10) % 1000 == 0) @@ -3050,7 +3006,6 @@ draw_juggle (ModeInfo *mi) if (future < sp->time + 100 * THROW_CATCH_INTERVAL) { refill_juggle(mi); } else if (sp->time > 1<<30) { /* Hard Reset before the clock wraps */ - release_juggle(mi); init_juggle(mi); }