1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
|
void initColour()
{
int squareColour = 1;
for (int xValue = 0; xValue < size; xValue++)
{
for (int yValue = 0; yValue < size; yValue++)
{
if (rand() % 5 < 2)
squareColour = 0;
else
squareColour = 1;
saveColour[xValue][yValue] = squareColour;
}
}
}
void OGWindow::drawGrid(GLvoid){
int squareColour = 1;
int size = 7;
//srand();
for (int xValue = 0; xValue < size; xValue++)
{
for (int yValue = 0; yValue < size; yValue++)
{
if (xValue == 0 && yValue == 0)
{
glColor3f(1, 0, 0);
//start square
glBegin(GL_QUADS);
glVertex3f(xValue-0.3, yValue-0.3, 0.0);
glVertex3f(xValue+0.3, yValue-0.3, 0.0);
glVertex3f(xValue+0.3, yValue+0.3, 0.0);
glVertex3f(xValue-0.3, yValue+0.3, 0.0);
glEnd();
glColor3f(0, 0, 0);
//start square outline
glBegin(GL_LINE_LOOP);
glVertex3f(xValue-0.5, yValue-0.5, 0.0);
glVertex3f(xValue+0.5, yValue-0.5, 0.0);
glVertex3f(xValue+0.5, yValue+0.5, 0.0);
glVertex3f(xValue-0.5, yValue+0.5, 0.0);
glEnd();
} else if (xValue == size - 2 && yValue == size - 2){
glColor3f(0, 0, 1);
//an end square
glBegin(GL_QUADS);
glVertex3f(xValue-0.3, yValue-0.3, 0.0);
glVertex3f(xValue+0.3, yValue-0.3, 0.0);
glVertex3f(xValue+0.3, yValue+0.3, 0.0);
glVertex3f(xValue-0.3, yValue+0.3, 0.0);
glEnd();
glColor3f(0, 0, 0);
//end square outline
glBegin(GL_LINE_LOOP);
glVertex3f(xValue-0.5, yValue-0.5, 0.0);
glVertex3f(xValue+0.5, yValue-0.5, 0.0);
glVertex3f(xValue+0.5, yValue+0.5, 0.0);
glVertex3f(xValue-0.5, yValue+0.5, 0.0);
glEnd();
} else {
glColor3f(0, 0, 0);
//square outline
glBegin(GL_LINE_LOOP);
glVertex3f(xValue-0.5, yValue-0.5, 0.0);
glVertex3f(xValue+0.5, yValue-0.5, 0.0);
glVertex3f(xValue+0.5, yValue+0.5, 0.0);
glVertex3f(xValue-0.5, yValue+0.5, 0.0);
glEnd();
squareColour = saveColour[xValue][yValue];
glColor3f(squareColour, squareColour, squareColour);
//making a square
glBegin(GL_QUADS);
glVertex3f(xValue-0.5, yValue-0.5, 0.0);
glVertex3f(xValue+0.5, yValue-0.5, 0.0);
glVertex3f(xValue+0.5, yValue+0.5, 0.0);
glVertex3f(xValue-0.5, yValue+0.5, 0.0);
glEnd();
}
}
}
}
|