-
Notifications
You must be signed in to change notification settings - Fork 0
/
2. Graph(+x,-x), (+y,-y)
96 lines (74 loc) · 1.63 KB
/
2. Graph(+x,-x), (+y,-y)
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
#include <windows.h>
#include <GL/glut.h>
#include <stdlib.h>
#include <stdio.h>
float Color1=0, Color2=1, Color3=0;
int r,p,q;
void keyboard(unsigned char key, int x, int y)
{
switch (key)
{
case 27: // ESCAPE key
exit (0);
break;
case 'r':
Color1=1.0, Color2=0.0, Color3=0.0;
break;
case 'g':
Color1=0.0, Color2=1.0, Color3=0.0;
break;
case 'b':
Color1=0.0, Color2=0.0, Color3=1.0;
break;
}
glutPostRedisplay();
}
void Init(int w, int h)
{
glClearColor(1.0, 1.0, 1.0, 1.0);
glViewport(0,0, (GLsizei)w,(GLsizei)h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D( (GLdouble)w/-2,(GLdouble)w/2, (GLdouble)h/-2, (GLdouble)h/2);
}
static void display(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
int i=0;
glPointSize(1);
glLineWidth(2);
glColor3f(Color1,Color2, Color3);
glBegin(GL_LINES);
glVertex2f(0, -340);
glVertex2f(0, 340);
glVertex2f(-660, 0);
glVertex2f(660, 0);
glEnd();
int j=-340,k=-660,l=0;
glBegin(GL_POINTS);
while(j<=340){
for( i=-660;i<=660;i++)
glVertex2f(i,j);
j+=20;
}
while(k<=660){
for( l=-340;l<=340;l++)
glVertex2f(k,l);
k+=20;
}
glEnd();
glFlush();
}
int main(int argc, char *argv[])
{
glutInit(&argc, argv);
glutInitWindowSize(1320,680);
glutInitWindowPosition(20,80);
glutInitDisplayMode(GLUT_RGB);
glutCreateWindow("Polygon drawing");
Init(1320, 680);
glutKeyboardFunc(keyboard);
glutDisplayFunc(display);
glutMainLoop();
return 0;
}