X-Git-Url: http://git.hungrycats.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=hacks%2Fglx%2Fendgame.c;h=281f5a98dc9e2bdffc7946b84a07f02019242112;hb=e4fa2ac140f7bc56571373a7b7eb585fa4500e38;hp=83ce4e412559d880035f1a2d3c7f034c3073e121;hpb=6cee540bdbb571485cd5e519f89f389faebd0495;p=xscreensaver diff --git a/hacks/glx/endgame.c b/hacks/glx/endgame.c index 83ce4e41..281f5a98 100644 --- a/hacks/glx/endgame.c +++ b/hacks/glx/endgame.c @@ -29,6 +29,7 @@ #define DEFAULTS "*delay: 20000 \n" \ "*showFPS: False \n" \ "*wireframe: False \n" \ + "*reflections: True \n" \ # include "xlockmore.h" @@ -48,12 +49,18 @@ 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" }, + {"+smooth", ".chess.smooth", XrmoptionNoArg, (caddr_t) "false" }, + {"-smooth", ".chess.smooth", XrmoptionNoArg, (caddr_t) "true" }, }; -int rotate; +int rotate, reflections, smooth; static argtype vars[] = { - {(caddr_t *) &rotate, "rotate", "Rotate", "True", t_Bool}, + {&rotate, "rotate", "Rotate", "True", t_Bool}, + {&reflections, "reflections", "Reflections", "True", t_Bool}, + {&smooth, "smooth", "Smooth", "True", t_Bool}, }; ModeSpecOpt chess_opts = {countof(opts), opts, countof(vars), vars, NULL}; @@ -94,71 +101,35 @@ GLfloat colors[2][3] = {0.5, 0.5, 0.5}, }; -/* well, i prefer silver tip */ -GLfloat whites[3][3] = +#define WHITES 5 + +/* i prefer silvertip */ +GLfloat whites[WHITES][3] = { {1.0, 0.5, 0.0}, - {0.8, 0.45, 1.0}, - {0.37, 0.56, 0.87}, + {0.9, 0.6, 0.9}, + {0.43, 0.54, 0.76}, + {0.8, 0.8, 0.8}, + {0.15, 0.77, 0.54}, }; -/* int board[BOARDSIZE][BOARDSIZE]; */ - #include "chessgames.h" ChessGame game; - -/* void buildBoard(void) { */ -/* board[0][5] = BKING; */ -/* board[1][4] = BPAWN; */ -/* board[1][2] = BPAWN; */ -/* board[1][0] = BPAWN; */ -/* board[2][2] = BPAWN; */ -/* board[2][4] = BPAWN; */ -/* board[2][7] = KNIGHT; */ -/* board[3][0] = PAWN; */ -/* board[3][2] = ROOK; */ -/* board[4][0] = PAWN; */ -/* board[4][4] = KING; */ -/* board[4][5] = PAWN; */ -/* board[6][0] = BPAWN; */ -/* board[6][7] = PAWN; */ -/* board[7][0] = BBISHOP; */ -/* } */ +int oldwhite = -1; void build_colors(void) { - int white = random()%3; - colors[0][0] = whites[white][0]; - colors[0][1] = whites[white][1]; - colors[0][2] = whites[white][2]; -} -/* int moves[MOVES][4] = */ -/* { {3, 2, 6, 2}, */ -/* {7, 0, 6, 1}, */ -/* {6, 2, 6, 6}, */ -/* {0, 5, 0, 4}, */ -/* {6, 6, 0, 6}, */ -/* {0, 4, 1, 3}, */ -/* {2, 7, 1, 5}, */ -/* {2, 2, 3, 2}, */ -/* {0, 6, 0, 3}, */ -/* {1, 3, 2, 2}, */ -/* {0, 3, 6, 3}, */ -/* {3, 2, 4, 2}, /\* pawn to bishop 5 *\/ */ -/* {1, 5, 0, 3}, /\* check *\/ */ -/* {2, 2, 3, 2}, */ -/* {0, 3, 2, 4}, /\* takes pawn *\/ */ -/* {3, 2, 2, 2}, */ -/* {2, 4, 0, 3}, */ -/* {2, 2, 3, 2}, */ -/* {6, 3, 6, 1}, /\* rook takes bishop *\/ */ -/* {6, 0, 7, 0}, */ -/* {6, 1, 3, 1}, */ -/* {3, 2, 2, 3}, */ -/* {3, 1, 3, 3}, */ -/* {0, 0, 2, 3}, */ -/* }; */ + /* find new white */ + int newwhite = oldwhite; + while(newwhite == oldwhite) + newwhite = random()%WHITES; + oldwhite = newwhite; + + colors[0][0] = whites[oldwhite][0]; + colors[0][1] = whites[oldwhite][1]; + colors[0][2] = whites[oldwhite][2]; +} /* yay its c */ int mpiece = 0, tpiece, steps = 0, done = 1; @@ -192,13 +163,28 @@ Bool chess_handle_event (ModeInfo *mi, XEvent *event) { return False; } -GLfloat position[] = { 3.0, 7.0, 3.0, 1.0 }; +GLfloat position[] = { 0.0, 5.0, 5.0, 1.0 }; +GLfloat position2[] = { 5.0, 5.0, 5.0, 1.0 }; +GLfloat diffuse2[] = {1.0, 1.0, 1.0, 1.0}; +GLfloat ambient2[] = {0.6, 0.6, 0.6, 1.0}; +GLfloat shininess[] = {60.0}; +GLfloat specular[] = {0.4, 0.4, 0.4, 1.0}; /* configure lighting */ void setup_lights(void) { glEnable(GL_LIGHTING); glLightfv(GL_LIGHT0, GL_POSITION, position); + glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse2); glEnable(GL_LIGHT0); + +/* glLightModelfv(GL_LIGHT_MODEL_AMBIENT, ambient2); */ + + glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, shininess); + glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, specular); + + glLightfv(GL_LIGHT1, GL_SPECULAR, diffuse2); + glLightfv(GL_LIGHT1, GL_DIFFUSE, diffuse2); + glEnable(GL_LIGHT1); } /** draw pieces */ @@ -242,9 +228,26 @@ void drawMovingPiece(void) { mpiece = mpiece == PAWN ? QUEEN : BQUEEN; } else if(mpiece % PIECES == KNIGHT) { + GLfloat shine[1]; + GLfloat spec[4]; + GLfloat mult; glTranslatef(steps < 50 ? from[1] : to[1], 0.0, steps < 50 ? from[0] : to[0]); + mult = steps < 10 + ? (1.0 - steps / 10.0) + : 100 - steps < 10 + ? specular[0] * (1.0 - (100 - steps) / 10.0) + : 0.0; + + shine[0] = 0.0;/*mult*shininess[0];*/ + spec[0] = mult*specular[0]; + spec[1] = mult*specular[1]; + spec[2] = mult*specular[2]; + spec[3] = 1.0; + glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, shine); + glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, spec); + glColor4f(colors[mpiece/7][0], colors[mpiece/7][1], colors[mpiece/7][2], fabs(49-steps)/49.0); glScalef(fabs(49-steps)/49.0, fabs(49-steps)/49.0, fabs(49-steps)/49.0); @@ -256,6 +259,10 @@ void drawMovingPiece(void) { glEnable(GL_BLEND); glCallList(piece); + + glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, shininess); + glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, specular); + glPopMatrix(); if(!wire) @@ -377,14 +384,32 @@ void display(Chesscreen *c) { glRotatef(theta*100, 0.0, 1.0, 0.0); glTranslatef(-0.5*BOARDSIZE, 0.0, -0.5*BOARDSIZE); + position[0] = 4.0 + 1.0*-sin(theta*100*M_PI/180.0); + position[2] = 4.0 + 1.0*cos(theta*100*M_PI/180.0); + position[1] = 8.0; + + 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); + /** draw board, pieces */ if(!wire) { glEnable(GL_LIGHTING); glEnable(GL_COLOR_MATERIAL); - draw_reflections(); - glEnable(GL_BLEND); + + if(reflections) { + draw_reflections(); + glEnable(GL_BLEND); + } + drawBoard(); - glDisable(GL_BLEND); + + if(reflections) + glDisable(GL_BLEND); } else drawBoard(); @@ -442,7 +467,7 @@ void init_chess(ModeInfo *mi) { if(!wire) { setup_lights(); glColorMaterial(GL_FRONT, GL_DIFFUSE); - glShadeModel(GL_SMOOTH); + glShadeModel(smooth ? GL_SMOOTH : GL_FLAT); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_DEPTH_TEST); } @@ -450,6 +475,8 @@ void init_chess(ModeInfo *mi) { glPolygonMode(GL_FRONT, GL_LINE); } +int oldgame = -1; + /** does dirty work drawing scene, moving pieces */ void draw_chess(ModeInfo *mi) { Chesscreen *c = &qs[MI_SCREEN(mi)]; @@ -494,8 +521,13 @@ void draw_chess(ModeInfo *mi) { moving = 1; } else if(done == 1) { - /* copy over new game */ - game = games[random()%GAMES]; + int newgame = oldgame; + while(newgame == oldgame) + newgame = random()%GAMES; + + /* same old game */ + oldgame = newgame; + game = games[oldgame]; build_colors(); done = 2; count = 0; @@ -507,9 +539,14 @@ void draw_chess(ModeInfo *mi) { } /* set lighting */ - if(done) + if(done) { glLightf(GL_LIGHT0, GL_CONSTANT_ATTENUATION, done == 1 ? 1.0+0.1*count : 100.0/count); + glLightf(GL_LIGHT1, GL_CONSTANT_ATTENUATION, + done == 1 ? 1.0+0.1*count : 100.0/count); + glLightf(GL_LIGHT1, GL_LINEAR_ATTENUATION, 0.15); + glLightf(GL_LIGHT0, GL_LINEAR_ATTENUATION, 0.15); + } display(c);