+ENTRYPOINT void
+init_stonerview (ModeInfo *mi)
+{
+ stonerview_configuration *bp;
+
+ if (!bps) {
+ bps = (stonerview_configuration *)
+ calloc (MI_NUM_SCREENS(mi), sizeof (stonerview_configuration));
+ if (!bps) {
+ fprintf(stderr, "%s: out of memory\n", progname);
+ exit(1);
+ }
+ }
+
+ bp = &bps[MI_SCREEN(mi)];
+
+ bp->glx_context = init_GL(mi);
+
+ bp->trackball = gltrackball_init ();
+ bp->st = init_view(MI_IS_WIREFRAME(mi), transparent_p);
+ init_move(bp->st);
+
+ reshape_stonerview (mi, MI_WIDTH(mi), MI_HEIGHT(mi));
+ clear_gl_error(); /* WTF? sometimes "invalid op" from glViewport! */
+}
+
+
+ENTRYPOINT void
+draw_stonerview (ModeInfo *mi)
+{
+ stonerview_configuration *bp = &bps[MI_SCREEN(mi)];
+
+ glXMakeCurrent(MI_DISPLAY(mi), MI_WINDOW(mi), *(bp->glx_context));
+
+ glPushMatrix ();
+ gltrackball_rotate (bp->trackball);
+ win_draw(bp->st);
+ if (! bp->button_down_p)
+ move_increment(bp->st);
+ glPopMatrix ();
+
+ mi->polygon_count = NUM_ELS;
+ if (mi->fps_p) do_fps (mi);
+ glFinish();
+
+ glXSwapBuffers(MI_DISPLAY (mi), MI_WINDOW(mi));
+}
+
+ENTRYPOINT void
+release_stonerview (ModeInfo *mi)
+{
+ if (bps) {
+ int screen;
+ for (screen = 0; screen < MI_NUM_SCREENS(mi); screen++) {
+ stonerview_configuration *bp = &bps[screen];
+ if (bp->st)
+ win_release (bp->st);
+ }
+ free (bps);
+ bps = 0;
+ }
+ FreeAllGL(mi);
+}
+
+ENTRYPOINT Bool
+stonerview_handle_event (ModeInfo *mi, XEvent *event)
+{
+ stonerview_configuration *bp = &bps[MI_SCREEN(mi)];
+
+ if (event->xany.type == ButtonPress &&
+ event->xbutton.button == Button1)
+ {
+ bp->button_down_p = True;
+ gltrackball_start (bp->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)
+ {
+ bp->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))
+ {
+ gltrackball_mousewheel (bp->trackball, event->xbutton.button, 10,
+ !!event->xbutton.state);
+ return True;
+ }
+ else if (event->xany.type == MotionNotify &&
+ bp->button_down_p)