-
Notifications
You must be signed in to change notification settings - Fork 0
/
Board and stickman integrated.cpp
134 lines (100 loc) · 2.92 KB
/
Board and stickman integrated.cpp
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#include <windows.h>
#include <gl\glut.h>
#include <iostream>
using namespace std;
int c = 0;
void stickman(void)
{ glMatrixMode(GL_MODELVIEW); // To operate on model-view matrix
glLoadIdentity();
glTranslatef(-33.5f, -33.5f, -60.0f);
glColor3f(0.0, 1.0, 0.0);
glBegin(GL_POLYGON);
glVertex3f((4.0+25.0)*0.5, (6.5+25)*0.5, -1.0);
glVertex3f((6.0+25)*0.5, (6.5+25)*0.5, -1.0);
glVertex3f((6.0+25)*0.5, (8.5+25)*0.5, -1.0);
glVertex3f((4.0+25)*0.5, (8.5+25)*0.5, -1.0);
glEnd();
glFlush();
glColor3f(0.0, 1.0, 0.0);
glBegin(GL_LINES);
glVertex3f((5.0+25)*0.5, (6.5+25)*0.5, -1.0);
glVertex3f((5.0+25)*0.5, (3.0+25)*0.5, -1.0);
glVertex3f((3.5+25)*0.5, (5.1+25)*0.5, -1.0);
glVertex3f((6.5+25)*0.5, (5.1+25)*0.5, -1.0);
glVertex3f((5.0+25)*0.5, (3.0+25)*0.5, -1.0);
glVertex3f((3.5+25)*0.5, (1.0+25)*0.5, -1.0);
glVertex3f((5.0+25)*0.5, (3.0+25)*0.5, -1.0);
glVertex3f((6.5+25)*0.5, (1.0+25)*0.5, -1.0);
glEnd();
glFlush();
}
void drawSquare(GLint x1, GLint y1, GLint x2, GLint y2, GLint x3, GLint y3, GLint x4, GLint y4)
{
// c alternates color of square
if (c == 0)
{
glColor3f(0.6, 0, 0);
c = 1;
}
else
{
glColor3f(0, 0, 0);
c = 0;
}
// Draw Square
glBegin(GL_POLYGON);
glVertex3f(x1*0.08, y1*0.08,-4.0);
glVertex3f(x2*0.08, y2*0.08,-4.0);
glVertex3f(x3*0.08, y3*0.08,-4.0);
glVertex3f(x4*0.08, y4*0.08,-4.0);
glEnd();
}
void board()
{
glMatrixMode(GL_MODELVIEW); // To operate on model-view matrix
glClear(GL_COLOR_BUFFER_BIT);
glLoadIdentity();
glTranslatef(-25.0f, -25.0f, -60.0f);
int x, y;
c = 0; //so that mouse click does not swap colors of squares
for (x = 25; x <= 475; x += 75)
{
for (y = 25; y <= 475; y += 75)
{
drawSquare(x, y + 75, x + 100, y + 75, x + 100, y, x, y);
}
}
// Process all OpenGL routines as quickly as possible
stickman();
}
void reshape(int width, int height) { // GLsizei for non-negative integer
// aspect ratio of the new window:
if (height == 0 || width == 0) return; // To prevent divide by 0
glMatrixMode(GL_PROJECTION); // Projection matrix operated on
glLoadIdentity();
GLfloat aspect = (GLfloat)width / (GLfloat)height;
gluPerspective(45.0f, aspect, 0.1f, 1000.0f);
glMatrixMode(GL_MODELVIEW); // Projection matrix operated on
glViewport(0, 0, width, height);// Set the viewport to cover the new window
// Perspective projection parameters - fovy, aspect, zNear and zFar
}
void TimerFunc(int extra)
{
glutPostRedisplay();
glutTimerFunc(1000 , TimerFunc, 0);
}
int main(int agrc, char ** argv)
{
glutInit(&agrc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowPosition(100, 100);
glutInitWindowSize(800, 600);
glutCreateWindow("War of Stick Men");
// for setting the transformation (here it is 2D)
glClearColor(0.2f, 0.3f, 0.3f, 1.0f);
glutDisplayFunc(board);
glutReshapeFunc(reshape);
glutTimerFunc(2000,TimerFunc,0);
glutMainLoop();
return 0;
}