From http://www.jwz.org/xscreensaver/xscreensaver-5.37.tar.gz
[xscreensaver] / hacks / glx / flipscreen3d.c
index 12107e269e16b3e5ac8d5952d9a40df2c8fdf46a..9bd6995650328eeddb4049edd6812787f740d0e7 100644 (file)
 #define DEFAULTS "*delay:     20000 \n" \
                  "*showFPS:   False \n" \
                  "*wireframe: False \n" \
-                 "*useSHM:    True  \n"
+                 "*useSHM:    True  \n" \
+                "*suppressRotationAnimation: True\n" \
 
 # define refresh_screenflip 0
+# define release_screenflip 0
 # include "xlockmore.h"                         /* from the xscreensaver distribution */
 # include "gltrackball.h"
 #else  /* !STANDALONE */
 
 #ifdef USE_GL
 
+/* Should be in <GL/glext.h> */
+# ifndef  GL_TEXTURE_MAX_ANISOTROPY_EXT
+#  define GL_TEXTURE_MAX_ANISOTROPY_EXT     0x84FE
+# endif
+# ifndef  GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT
+#  define GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT 0x84FF
+# endif
+
+#define DEF_ROTATE "True"
 static int rotate;
 
 #define QW 12
@@ -50,7 +61,7 @@ static XrmOptionDescRec opts[] = {
 
 
 static argtype vars[] = {
-  {&rotate, "rotate", "Rotate", "True", t_Bool},
+  {&rotate, "rotate", "Rotate", DEF_ROTATE, t_Bool},
 };
 
 
@@ -60,7 +71,7 @@ ENTRYPOINT ModeSpecOpt screenflip_opts = {countof(opts), opts, countof(vars), va
 
 #ifdef USE_MODULES
 ModStruct   screenflip_description =
-{"screenflip", "init_screenflip", "draw_screenflip", "release_screenflip",
+{"screenflip", "init_screenflip", "draw_screenflip", NULL,
  "draw_screenflip", "init_screenflip", NULL, &screenflip_opts,
  1000, 1, 2, 1, 4, 1.0, "",
  "Screenflips", 0, NULL};
@@ -99,54 +110,36 @@ typedef struct {
   Bool waiting_for_image_p;
   Bool first_image_p;
 
+  GLfloat anisotropic;
+
 } Screenflip;
 
 static Screenflip *screenflip = NULL;
 
 #include "grab-ximage.h"
 
-#ifndef M_PI
-#define M_PI 3.14159265
-#endif
-
 static const GLfloat viewer[] = {0.0, 0.0, 15.0};
 
 
+static void getSnapshot (ModeInfo *);
+
+
 ENTRYPOINT Bool
 screenflip_handle_event (ModeInfo *mi, XEvent *event)
 {
   Screenflip *c = &screenflip[MI_SCREEN(mi)];
 
-  if (event->xany.type == ButtonPress &&
-      event->xbutton.button == Button1)
-    {
-      c->button_down_p = True;
-      gltrackball_start (c->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)
-    {
-      c->button_down_p = False;
-      return True;
-    }
-  else if (event->xany.type == ButtonPress &&
-           (event->xbutton.button == Button4 ||
-            event->xbutton.button == Button5))
-    {
-      gltrackball_mousewheel (c->trackball, event->xbutton.button, 10,
-                              !!event->xbutton.state);
-      return True;
-    }
-  else if (event->xany.type == MotionNotify &&
-           c->button_down_p)
+  if (gltrackball_event_handler (event, c->trackball,
+                                 MI_WIDTH (mi), MI_HEIGHT (mi),
+                                 &c->button_down_p))
+    return True;
+  else if (screenhack_event_helper (MI_DISPLAY(mi), MI_WINDOW(mi), event))
     {
-      gltrackball_track (c->trackball,
-                         event->xmotion.x, event->xmotion.y,
-                         MI_WIDTH (mi), MI_HEIGHT (mi));
-      return True;
+      if (!c->waiting_for_image_p)
+        {
+          getSnapshot (mi);
+          return True;
+        }
     }
 
   return False;
@@ -313,12 +306,23 @@ static void drawgrid(void)
 static void display(Screenflip *c, int wire)
 {
   int frozen;
+/*  GLfloat rot = current_device_rotation();*/
 
   glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
   glLoadIdentity();
   gluLookAt(viewer[0], viewer[1], viewer[2], 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
   glPushMatrix();
 
+/*
+  glRotatef(rot, 0, 0, 1);
+  if ((rot >  45 && rot <  135) ||
+      (rot < -45 && rot > -135))
+    {
+      GLfloat s = c->winw / (GLfloat) c->winh;
+      glScalef (s, 1/s, 1);
+    }
+*/
+
   if (inposition(c)) {
     frozen = 0;
     glTranslatef(5 * sin(c->theta), 5 * sin(c->rho), 10 * cos(c->gamma) - 10);
@@ -331,7 +335,9 @@ static void display(Screenflip *c, int wire)
       if (random() % 2)
         c->dgamma = 1/60 - (float)(random() % 100)/3000;
     }
+/*    glRotatef(-rot, 0, 0, 1);*/
     gltrackball_rotate (c->trackball);
+/*    glRotatef(rot, 0, 0, 1);*/
     if (rotate) glRotatef(c->rot, c->rx, c->ry, c->rz);
 /* update variables with each frame */
     if(!c->button_down_p && !c->fadetime) {
@@ -405,6 +411,10 @@ image_loaded_cb (const char *filename, XRectangle *geometry,
   glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
                    (c->mipmap_p ? GL_LINEAR_MIPMAP_LINEAR : GL_LINEAR));
 
+  if (c->anisotropic >= 1.0)
+    glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, 
+                     c->anisotropic);
+
   c->waiting_for_image_p = False;
   c->first_image_p = False;
 }
@@ -429,15 +439,11 @@ ENTRYPOINT void init_screenflip(ModeInfo *mi)
   int screen = MI_SCREEN(mi);
   Screenflip *c;
 
- if (screenflip == NULL) {
-   if ((screenflip = (Screenflip *) calloc(MI_NUM_SCREENS(mi),
-                                        sizeof(Screenflip))) == NULL)
-          return;
- }
+ MI_INIT(mi, screenflip, NULL);
  c = &screenflip[screen];
  c->window = MI_WINDOW(mi);
 
- c->trackball = gltrackball_init ();
+ c->trackball = gltrackball_init (False);
 
  if ((c->glx_context = init_GL(mi)) != NULL) {
       reshape_screenflip(mi, MI_WIDTH(mi), MI_HEIGHT(mi));
@@ -457,8 +463,6 @@ ENTRYPOINT void init_screenflip(ModeInfo *mi)
  c->show_colors[0] = c->show_colors[1] = 
    c->show_colors[2] = c->show_colors[3] = 1;
 
- glClearColor(0.0,0.0,0.0,0.0);
-
  if (! MI_IS_WIREFRAME(mi))
    {
      glShadeModel(GL_SMOOTH);
@@ -469,6 +473,12 @@ ENTRYPOINT void init_screenflip(ModeInfo *mi)
      glDisable(GL_LIGHTING);
    }
 
+ if (strstr ((char *) glGetString(GL_EXTENSIONS),
+             "GL_EXT_texture_filter_anisotropic"))
+   glGetFloatv (GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &c->anisotropic);
+ else
+   c->anisotropic = 0.0;
+
  glGenTextures(1, &c->texid);
 
  c->first_image_p = True;
@@ -503,15 +513,6 @@ ENTRYPOINT void draw_screenflip(ModeInfo *mi)
   glXSwapBuffers(disp, w);
 }
 
-ENTRYPOINT void release_screenflip(ModeInfo *mi)
-{
-  if (screenflip != NULL) {
-   (void) free((void *) screenflip);
-   screenflip = NULL;
-  }
-  FreeAllGL(mi);
-}
-
 XSCREENSAVER_MODULE_2 ("FlipScreen3D", flipscreen3d, screenflip)
 
 #endif