-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathvaibhav cgmt.cpp
More file actions
66 lines (61 loc) · 1.13 KB
/
vaibhav cgmt.cpp
File metadata and controls
66 lines (61 loc) · 1.13 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
#include<stdlib.h>
#include<stdio.h>
#include <glut.h>
#include <conio.h>
float x,y,x1,y1,x2,y2;
void display(void)
{
float dx,dy,inc,steps;
int i;
x=x1;
y=y1;
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(0.0, 0.0, 0.0);
glPointSize(4.0);
dx=x2-x1;
dy=y2-y1;
glBegin(GL_POINTS);
glVertex2f(x,y);
if(dx>dy){
steps=dx;
inc=dy/dx;
for(i=0;i<dx;i++){
x=x+1;
y=y+inc;
glVertex2f(x,y);
}
}
else{
steps=dy;
inc=dx/dy;
for(i=0;i<dy;i++){
y++;
x=x+inc;
glVertex2f(x,y);
}
}
glEnd();
glFlush();
}
int main(int argc,char *argv[])
{
system("cls");
printf("Enter value of x1: ");
scanf("%f",&x1);
printf("Enter value of y1: ");
scanf("%f",&y1);
printf("Enter value of x2: ");
scanf("%f",&x2);
printf("Enter value of y2: ");
scanf("%f",&y2);
glutInit(&argc,argv);
glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize (500, 500);
glutInitWindowPosition (100, 100);
glutCreateWindow ("DDA Line");
glClearColor(1.0,1.0,1.0,0.0);
glMatrixMode (GL_PROJECTION);
gluOrtho2D (0.0, 200.0, 0.0, 150.0);
glutDisplayFunc(display);
glutMainLoop();
}