You are on page 1of 2

#include<windows.

h>
#include<GL/glut.h>
#include<stdlib.h>
#include<stdio.h>
float x,x0,y,y0,x1,y1;
void display(void)
{
int m;
m=abs(y1-y0)/abs(x1-x0);
if(abs(m)<=1)
{
for(x=x0; x<=x1; x++)
{
y=y+m;
glBegin(GL_POINTS);
glVertex2f(x,y);
glEnd();
}
}
else if(abs(m)>1)
{
for(y=y0; y<=y1; y++)
{ x=x+(1/m);
glBegin(GL_POINTS);
glVertex2f(x,y);
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", &x0,&y0,&x1,&y1);
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