ftp://ftp.krokus.ru/pub/OpenBSD/distfiles/xscreensaver-4.22.tar.gz
[xscreensaver] / hacks / glx / endgame.c
index 41131c28d325c032fa3879becbd0c04127e5fc8b..c22c33905d70a5d2da3d5eb2e800307c14865c57 100644 (file)
 # define EVENT_MASK       PointerMotionMask
 # define chess_opts  xlockmore_opts
 
-#define DEFAULTS       "*delay:       20000       \n" \
-                       "*showFPS:       False       \n" \
-                      "*wireframe:     False     \n"   \
-                      "*reflections:   True     \n"    \
-                      "*shadows:       True     \n"    \
+#define DEFAULTS       "*delay:     20000 \n" \
+                       "*showFPS:   False \n" \
+                      "*wireframe: False \n" \
 
 # include "xlockmore.h"
 
 #define countof(x) (sizeof((x))/sizeof((*x)))
 
 static XrmOptionDescRec opts[] = {
-  {"+rotate", ".chess.rotate", XrmoptionNoArg, (caddr_t) "false" },
-  {"-rotate", ".chess.rotate", XrmoptionNoArg, (caddr_t) "true" },
-  {"+reflections", ".chess.reflections", XrmoptionNoArg, (caddr_t) "false" },
-  {"-reflections", ".chess.reflections", XrmoptionNoArg, (caddr_t) "true" },
-  {"+shadows", ".chess.shadows", XrmoptionNoArg, (caddr_t) "false" },
-  {"-shadows", ".chess.shadows", XrmoptionNoArg, (caddr_t) "true" },
-  {"+smooth", ".chess.smooth", XrmoptionNoArg, (caddr_t) "false" },
-  {"-smooth", ".chess.smooth", XrmoptionNoArg, (caddr_t) "true" },
+  {"+rotate", ".chess.rotate", XrmoptionNoArg, "false" },
+  {"-rotate", ".chess.rotate", XrmoptionNoArg, "true" },
+  {"+reflections", ".chess.reflections", XrmoptionNoArg, "false" },
+  {"-reflections", ".chess.reflections", XrmoptionNoArg, "true" },
+  {"+shadows", ".chess.shadows", XrmoptionNoArg, "false" },
+  {"-shadows", ".chess.shadows", XrmoptionNoArg, "true" },
+  {"+smooth", ".chess.smooth", XrmoptionNoArg, "false" },
+  {"-smooth", ".chess.smooth", XrmoptionNoArg, "true" },
 };
 
 int rotate, reflections, smooth, shadows;
@@ -206,7 +204,7 @@ double theta = 0.0;
 Bool chess_handle_event (ModeInfo *mi, XEvent *event) {
   Chesscreen *c = &qs[MI_SCREEN(mi)];
 
-  if(event->xany.type == ButtonPress && event->xbutton.button & Button1) {
+  if(event->xany.type == ButtonPress && event->xbutton.button == Button1) {
     c->button_down_p = True;
     gltrackball_start (c->trackball,
                       event->xbutton.x, event->xbutton.y,
@@ -214,10 +212,18 @@ Bool chess_handle_event (ModeInfo *mi, XEvent *event) {
     return True;
   }
   else if(event->xany.type == ButtonRelease 
-         && event->xbutton.button & Button1) {
+         && 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, 5,
+                              !event->xbutton.state);
+      return True;
+    }
   else if(event->xany.type == MotionNotify && c->button_down_p) {
     gltrackball_track (c->trackball,
                       event->xmotion.x, event->xmotion.y,
@@ -427,13 +433,15 @@ void drawBoard(void) {
   glEnd();
 }
 
-void draw_pieces(void) {
-  glEnable(GL_TEXTURE_2D);
-  glBindTexture(GL_TEXTURE_2D, piecetexture);
-  glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
+void draw_pieces(int wire) {
+  if (!wire) {
+    glEnable(GL_TEXTURE_2D);
+    glBindTexture(GL_TEXTURE_2D, piecetexture);
+    glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
 
-  glColor4f(0.5, 0.5, 0.5, 1.0);
-  glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialShadow);
+    glColor4f(0.5, 0.5, 0.5, 1.0);
+    glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialShadow);
+  }
 
   drawPieces();
   if(moving) drawMovingPiece(0);
@@ -441,12 +449,13 @@ void draw_pieces(void) {
   glDisable(GL_TEXTURE_2D);
 }
 
-void draw_shadow_pieces(void) {
-  glEnable(GL_TEXTURE_2D);
-  glBindTexture(GL_TEXTURE_2D, piecetexture);
-  glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
+void draw_shadow_pieces(int wire) {
+  if (!wire) {
+    glEnable(GL_TEXTURE_2D);
+    glBindTexture(GL_TEXTURE_2D, piecetexture);
+    glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
+  }
 
-  
   drawPiecesShadow();
   if(moving) drawMovingPiece(shadows);
   if(take) drawTakePiece(shadows);
@@ -525,7 +534,7 @@ void draw_reflections(void) {
   glTranslatef(0.5, 0.0, 0.5);
 
   glLightfv(GL_LIGHT0, GL_POSITION, position);
-  draw_pieces();
+  draw_pieces(wire);
   glPopMatrix();
   
   glDisable(GL_STENCIL_TEST);
@@ -557,17 +566,19 @@ void display(Chesscreen *c) {
   position2[0] = 4.0 + 8.0*-sin(theta*100*M_PI/180.0);
   position2[2] = 4.0 + 8.0*cos(theta*100*M_PI/180.0);
 
-  glEnable(GL_LIGHTING);
-  glLightfv(GL_LIGHT0, GL_POSITION, position);
-  glLightfv(GL_LIGHT1, GL_POSITION, position2);
-  glEnable(GL_LIGHT0);
+  if (!wire) {
+    glEnable(GL_LIGHTING);
+    glLightfv(GL_LIGHT0, GL_POSITION, position);
+    glLightfv(GL_LIGHT1, GL_POSITION, position2);
+    glEnable(GL_LIGHT0);
+  }
 
   /** draw board, pieces */
   if(!wire) {
     glEnable(GL_LIGHTING);
     glEnable(GL_COLOR_MATERIAL);
 
-    if(reflections) {
+    if(reflections && !wire) {
       draw_reflections();
       glEnable(GL_BLEND);
     }
@@ -592,7 +603,7 @@ void display(Chesscreen *c) {
       glTranslatef(0.0, 0.001, 0.0);
       glMultMatrixf(m[0]);
       glTranslatef(0.5, 0.01, 0.5);
-      draw_shadow_pieces();
+      draw_shadow_pieces(wire);
       glPopMatrix();      
 
       glEnable(GL_LIGHTING);
@@ -607,7 +618,7 @@ void display(Chesscreen *c) {
     drawBoard();
  
   glTranslatef(0.5, 0.0, 0.5);
-  draw_pieces();
+  draw_pieces(wire);
 
   if(!wire) {
     glDisable(GL_COLOR_MATERIAL);
@@ -649,13 +660,15 @@ void init_chess(ModeInfo *mi) {
 
   glClearColor(0.0, 0.0, 0.0, 0.0);
 
-  glDepthFunc(GL_LEQUAL);
-  glClearStencil(0);
-  glEnable(GL_CULL_FACE);
-  glCullFace(GL_BACK);
+  if (!wire) {
+    glDepthFunc(GL_LEQUAL);
+    glClearStencil(0);
+    glEnable(GL_CULL_FACE);
+    glCullFace(GL_BACK);
 
-  make_piece_texture();
-  make_board_texture();
+    make_piece_texture();
+    make_board_texture();
+  }
   gen_model_lists();
 
   if(!wire) {
@@ -666,7 +679,7 @@ void init_chess(ModeInfo *mi) {
     glEnable(GL_DEPTH_TEST);
   }
   else
-    glPolygonMode(GL_FRONT, GL_LINE);
+    glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
 }
 
 int oldgame = -1;