-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathchessboard.cpp
More file actions
51 lines (46 loc) · 1.21 KB
/
Copy pathchessboard.cpp
File metadata and controls
51 lines (46 loc) · 1.21 KB
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
// implementation of the class chessboard
#include "chessboard.h"
// to draw black square
int ChessBoard::BlackSquare(GLfloat *vertices)
{
//glColor3f(0,0,0);
glColor3f((float)153/255, (float)51/255, (float)0/255);
DrawQuad(vertices);
}
// to draw white square
int ChessBoard::WhiteSquare(GLfloat *vertices)
{
//glColor3f(1,1,1);
glColor3f((float)255/255, (float)230/255, (float)153/255);
DrawQuad(vertices);
}
int ChessBoard::DrawChessBoard(GLfloat x0, GLfloat y0, GLfloat size)
{
int n = 8; // number of the square in one row
GLfloat x = x0;
GLfloat y = y0;
for (int i = 0; i < n; ++i) // row
{
for (int j = 0; j < n; ++j) // coloum
{
GLfloat vertices[] = {x, y, x+size, y, x+size, y+size, x, y+size};
if (i%2==0)
{
if (j%2 == 0)
WhiteSquare(vertices);
else
BlackSquare(vertices);
}
else
{
if (j%2 == 0)
BlackSquare(vertices);
else
WhiteSquare(vertices);
}
x += size;
}
x = x0;
y += size;
}
}