-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPolygon.cpp
More file actions
78 lines (65 loc) · 1.6 KB
/
Copy pathPolygon.cpp
File metadata and controls
78 lines (65 loc) · 1.6 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
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
#include <GL/glut.h>
#include<bits/stdc++.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 drawPolygon(vector<point*> points)
{
glBegin(GL_POLYGON);
for(int i = 0; i < points.size(); ++i)
{
glColor3f(points[i]->r, points[i]->g, points[i]->b);
glVertex2f(points[i]->x, points[i]->y);
}
glEnd();
}
void drawPolygon(vector<point> points)
{
glBegin(GL_POLYGON);
for(int i = 0; i < points.size(); ++i)
{
glColor3f(points[i].r, points[i].g, points[i].b);
glVertex2f(points[i].x, points[i].y);
}
glEnd();
}
void display()
{
glClear(GL_COLOR_BUFFER_BIT);
vector<point*> points;
points.push_back( new point(-0.4, 0.2, 0.2f, 0.2f, 1.0f) );
points.push_back( new point(0.0, 0.6, 0.2f, 0.2f, 1.0f) );
points.push_back( new point(0.4, 0.2, 0.2f, 0.2f, 1.0f) );
points.push_back( new point(0.4, -0.2, 0.2f, 0.2f, 1.0f) );
points.push_back( new point(0.0, -0.6, 0.2f, 0.2f, 1.0f) );
points.push_back( new point(-0.4, -0.2, 0.2f, 0.2f, 1.0f) );
drawPolygon(points);
glFlush();
}
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitWindowSize(400, 300);
glutInitWindowPosition(0, 0);
glutCreateWindow("Polygon");
glClearColor(0.1f, 0.5f, 0.9f, 1.0f);
glutDisplayFunc(display);
glutMainLoop();
return 0;
}