You are on page 1of 2

#include<windows.

h>

#include<GL/glut.h>

#include<stdlib.h>

#include<stdio.h>

float x,x2,y,y2,x1,y1,p,i;

void display(void)

{ glBegin(GL_POINTS);

int dy= y2-y1;

int dx= x2-x1;

glVertex2f(x1,y1);

p=2*dy-dx;

for (i=0; i<abs(dx); i++)

{if(p<0)

{ x=x1+1;

y=y1;

glBegin(GL_POINTS);

glVertex2f(x,y);

p=p+(2*dy);

else

x=x1+1;

y=y1+1;

glBegin(GL_POINTS);

glVertex2f(x,y);

p=p+(2*dy)-(2*dx);

x1=x;

y1=y;

glVertex2f(x2,y2);
glEnd();

glFlush();

void init(void)

glClear(GL_COLOR_BUFFER_BIT);

glClearColor(0,0,0,0);

glMatrixMode(GL_PROJECTION);

glLoadIdentity();

gluOrtho2D(-100,100,-100,100);

}int main(int argc, char** argv)

printf("Enter the value of the points");

scanf("%f %f %f %f", &x1,&y1,&x2,&y2);

glutInit(&argc, argv);

glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);

glutInitWindowSize(500,500);

glutInitWindowPosition(100,100);

glutCreateWindow("___");

init();

glutDisplayFunc(display);

glutMainLoop();

return 0;

You might also like