/* * CS 453 - Final project : An OpenGL version of the pegboard game IQ * Due : June 5, 1997 * Author : Kiri Wagstaff * * File : board.c * Description : Contains the board readin and selection functions. * * */ #include "gliq.h" /* functions */ void selectboard(void); void readboards(void); void drawboard(void); void drawpegs(void); /* Draw all the pegs */ void drawpeg(void); /* Draw one peg */ void displaybuttons(void); /* globals */ int numboards, curboard; int*** boards; int filled[BOARDSIZE][BOARDSIZE]; /* Current state of the pegs */ /* Define the board */ GLfloat vertices[8*3] = { -5.0,0.0,5.0, 5.0,0.0,5.0, 5.0,0.5,5.0, -5.0,0.5,5.0, -5.0,0.0,-5.0, 5.0,0.0,-5.0, 5.0,0.5,-5.0, -5.0,0.5,-5.0 }; GLuint faces[6*4] = { 0,1,2,3, /*front*/ 0,3,7,4, /*left*/ 0,4,5,1, /*bottom*/ 1,5,6,2, /*right*/ 3,2,6,7, /*top*/ 4,7,6,5 /*back*/ }; GLfloat normals[6*3] = { 0.0, 0.0, 1.0, -1.0, 0.0, 0.0, 0.0, -1.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, -1.0, }; void selectboard(void) { int height=glutGet(GLUT_WINDOW_HEIGHT); int width=glutGet(GLUT_WINDOW_WIDTH); static float spin=0.0; /* Eventually make it spin */ /* Display the buttons */ displaybuttons(); /* Draw the quit button */ drawquit(7.0, 9.0, 0.4, 1.0); /* Quit */ glColor3f(1.0, 1.0, 1.0); /* white */ /* text(0.78*width, 0.89*height, 0.1*height, "Quit"); */ /* Select message */ glColor3f(0.0, 1.0, 0.0); text(0.3*width, 0.9*height, 0.07*height, "Select a board"); /* Draw the total # of pegs */ glPushMatrix(); glColor3f(1.0, 1.0, 0.0); /* yellow */ glTranslatef(-7.8, 8.8, 0.0); drawpeg(); text(0.1*width, 0.9*height, 0.07*height, ": %02d", totalpegs); glPopMatrix(); /* do the trackball rotation. */ glPushMatrix(); /* tbMatrix(); */ glRotatef(45.0, 1.0, 0.0, 0.0); glRotatef(spin, 0.0, 1.0, 0.0); drawboard(); drawpegs(); glPopMatrix(); spin++; } void readboards(void) { int i, j, hole; FILE* fp; /* Read in the boards */ fp = fopen("boards.txt", "r"); if (!fp) { printf("Could not open boards.txt, exiting.\n"); exit(1); } fscanf(fp, "%d", &numboards); boards = (int***)malloc(numboards*sizeof(int**)); for (i=0; i