-
Notifications
You must be signed in to change notification settings - Fork 0
/
Bresenham' Line Drawing.c
64 lines (64 loc) · 1.14 KB
/
Bresenham' Line Drawing.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
#include<stdlib.h>
#include<stdio.h>
#include <GL/gl.h>
#include <GL/glut.h>
float x1, x2, y1, y2;
void TakeInput()
{
printf("Value of x1 : ");
scanf("%f", & x1);
printf("Value of y1 : ");
scanf("%f", & y1);
printf("Value of x2 : ");
scanf("%f", & x2);
printf("Value of y2 : ");
scanf("%f", & y2);
}
void display(void)
{
float dx = abs(x2 - x1);
float dy = abs(y2 - y1);
float p = 2 * dy - dx;
int itr = (int)dx - 1;
glBegin(GL_POINTS);
glVertex2f(x1, y1);
glEnd();
while (itr--)
{
if (p < 0)
{
p = p + 2.0 * dy;
x1 = x1 + 1;
y1 = y1;
}
else if (p > 0)
{
p = p + 2 * dy - 2 * dx;
x1 = x1 + 1;
y1 = y1 + 1;
}
glBegin(GL_POINTS);
glVertex2f(x1, y1);
glEnd();
}
glFlush();
}
void myInit (void) {
glClear(GL_COLOR_BUFFER_BIT);
glClearColor(0, 0, 0, 0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(-100.0, 100.0, 100.0, -100.0);
}
int main(int argc, char ** argv)
{
TakeInput();
glutInit( & argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(500, 500);
glutInitWindowPosition(100, 100);
glutCreateWindow("");
myInit ();
glutDisplayFunc(display);
glutMainLoop();
}