-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSquare (Using Lines).cpp
60 lines (49 loc) · 986 Bytes
/
Square (Using Lines).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
#include <GL/glut.h>
using namespace std;
struct point
{
double x, y, r, g, b;
point(double _x, double _y)
{
x = _x;
y = _y;
r = g = b = 0;
}
point(double _x, double _y, double _r, double _g, double _b)
{
x = _x;
y = _y;
r = _r;
g = _g;
b = _b;
}
};
void drawLine(point a, point b)
{
glColor3f(a.r, a.g, a.b);
glBegin(GL_LINES);
glVertex2f(a.x, a.y);
glVertex2f(b.x, b.y);
glEnd();
}
void display()
{
glClear(GL_COLOR_BUFFER_BIT);
point a(-.4, -.4), b(-.4, .4), c(.4, .4), d(.4, -.4);
drawLine(a, b);
drawLine(b, c);
drawLine(c, d);
drawLine(a, d);
glFlush();
}
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitWindowSize(400, 300);
glutInitWindowPosition(0, 0);
glutCreateWindow("Square");
glClearColor(0.1f, 0.5f, 0.9f, 1.0f);
glutDisplayFunc(display);
glutMainLoop();
return 0;
}