-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.c
118 lines (83 loc) · 2.07 KB
/
main.c
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
#include <GL/gl.h>
#include <GL/glut.h>
#include <stdio.h>
int x1, y1, x2, y2, dx, dy, x, y;
float m;
void display(void) {
/* clear all pixels */
glClear(GL_COLOR_BUFFER_BIT);
glColor3ub(255, 0, 0);
/* draw white polygon (rectangle) with corners at
* (0.25, 0.25, 0.0) and (0.75, 0.75, 0.0)
*/
int i = 1;
glColor3ub(255, 0, 0);
glBegin(GL_POINTS);
glVertex2d(x, y);
glEnd();
if (m <= 1) {
while (i <= dx) {
x = x + 1;
y = y + m;
glBegin(GL_POINTS);
glVertex2d(x, y);
glEnd();
i++;
}
} else {
while (i <= dy) {
x = x + 1 / m;
y = y + 1;
glBegin(GL_POINTS);
glVertex2d(x, y);
glEnd();
i++;
}
}
/* don't wait!
* start processing buffered OpenGL routines
*/
glFlush();
}
void init(void) {
/* select clearing (background) color */
glClearColor(0, 0, 0.0, 0.0);
/* initialize viewing values */
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0, 800, 0, 800);
}
/*
* Declare initial window size, position, and display mode
* (single buffer and RGBA). Open window with "hello"
* in its title bar. Call initialization routines.
* Register callback function to display graphics.
* Enter main loop and process events.
*/
int main(int argc, char** argv) {
printf("x1: ");
scanf("%d", &x1);
printf("y1: ");
scanf("%d", &y1);
printf("x2: ");
scanf("%d", &x2);
printf("y2: ");
scanf("%d", &y2);
x = x1;
y = y1;
dx = x2 - x1;
dy = y2 - y1;
m = (float) dy / (float) dx;
printf("%d %d\n", x1, y1);
printf("%d %d\n", x2, y2);
printf("%d %d %f\n", dx, dy, m);
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(600, 600);
glutInitWindowPosition(0, 0);
glutCreateWindow("Line");
init();
glutDisplayFunc(display);
glutMainLoop();
return 0; /* ISO C requires main to return int. */
}