-
Notifications
You must be signed in to change notification settings - Fork 0
/
Window Clipping.cpp
76 lines (61 loc) · 1.24 KB
/
Window Clipping.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
#include <GL/glut.h>
#include<bits/stdc++.h>
using namespace std;
int n;
double xx[100], yy[100];
void display()
{
glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_LINES);
glColor3f(0.0f,0.0f,0.0f);
//square
glVertex2f(0.2f,0.2f);
glVertex2f(0.8f,0.2f);
glVertex2f(0.2,0.8f);
glVertex2f(0.8f,0.8f);
glVertex2f(0.2f,0.2f);
glVertex2f(0.2,0.8f);
glVertex2f(0.8f,0.2f);
glVertex2f(0.8f,0.8f);
//--------------
double x_min = 0.2, y_min = 0.2, x_max = 0.8, y_max = 0.8, x, y;
//lines
for(int i = 0; i < 2*n; ++i)
{
x = xx[i];
x = x < x_min ? x_min : x;
x = x > x_max ? x_max : x;
y = yy[i];
y = y < y_min ? y_min : y;
y = y > y_max ? y_max : y;
glVertex2f(x, y);
}
//----------
glEnd();
glFlush();
}
int main(int argc, char** argv)
{
cin >> n;
for(int i = 0; i < 2*n; ++i)
cin >> xx[i] >> yy[i];
glutInit(&argc, argv);
glutInitWindowSize(400, 300);
glutInitWindowPosition(100, 200);
glutCreateWindow("Square");
glClearColor(1.1f, 1.5f, 0.9f, 1.5f);
glutDisplayFunc(display);
glutMainLoop();
return 0;
}
/*
4
0.7 0.5
1.0 0.5
0.4 0.4
0.4 0.1
0.4 0.6
0.1 0.6
0.6 1.0
0.6 0.6
*/