+#define WHITES 5
+
+/* i prefer silvertip */
+GLfloat whites[WHITES][3] =
+ {
+ {1.0, 0.55, 0.1},
+ {0.8, 0.52, 0.8},
+ {0.43, 0.54, 0.76},
+ {0.8, 0.8, 0.8},
+ {0.35, 0.60, 0.35},
+ };
+
+#include "chessgames.h"
+
+ChessGame game;
+int oldwhite = -1;
+
+void build_colors(void) {
+
+ /* 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];
+}
+
+/* road texture */
+#define checkImageWidth 16
+#define checkImageHeight 16
+GLubyte checkImage[checkImageWidth][checkImageHeight][3];
+GLuint piecetexture, boardtexture;
+
+/* build piece texture */
+void make_piece_texture(void) {
+ int i, j, c;
+
+ for (i = 0; i < checkImageWidth; i++) {
+ for (j = 0; j < checkImageHeight; j++) {
+ c = ((j%2) == 0 || i%2 == 0) ? 240 : 180+random()%16;
+ checkImage[i][j][0] = (GLubyte) c;
+ checkImage[i][j][1] = (GLubyte) c;
+ checkImage[i][j][2] = (GLubyte) c;
+ }
+ }
+
+ glGenTextures(1, &piecetexture);
+ glBindTexture(GL_TEXTURE_2D, piecetexture);
+
+ glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
+ glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
+ glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_REPEAT);
+ glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_REPEAT);
+ glTexImage2D(GL_TEXTURE_2D, 0, 3, checkImageWidth,
+ checkImageHeight, 0, GL_RGB, GL_UNSIGNED_BYTE,
+ &checkImage[0][0]);
+}
+
+/* build board texture (uniform noise in [180,180+50]) */
+void make_board_texture(void) {
+ int i, j, c;
+
+ for (i = 0; i < checkImageWidth; i++) {
+ for (j = 0; j < checkImageHeight; j++) {
+ c = 180 + random()%51;
+ checkImage[i][j][0] = (GLubyte) c;
+ checkImage[i][j][1] = (GLubyte) c;
+ checkImage[i][j][2] = (GLubyte) c;
+ }
+ }
+
+ glGenTextures(1, &boardtexture);
+ glBindTexture(GL_TEXTURE_2D, boardtexture);
+
+ glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
+ glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
+ glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_REPEAT);
+ glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_REPEAT);
+ glTexImage2D(GL_TEXTURE_2D, 0, 3, checkImageWidth,
+ checkImageHeight, 0, GL_RGB, GL_UNSIGNED_BYTE,
+ &checkImage[0][0]);
+}
+