Bresenham


/*
* main.c
*
* Created on: Apr 29, 2014
* Author: akshaythakare
*/

#include<stdio.h>
#include<stdlib.h>
#include<openGL/gl.h>
#include<openGL/glu.h>
#include<GLUT/glut.h>

float x1,x2,y1,y2;

void Bresenham()
{
float xn,yn,dx,dy,g;
dx = x2-x1; dy=y2-y1;
xn=x1; yn=y1;
g = 2*dy-dx;

glBegin(GL_POINTS);
glVertex2f(xn,yn);
while(xn<x2&&yn<y2)
{
if(g<0)
{
xn = xn+1;
glVertex2f(xn,yn);
}
else
{
xn = xn+1;
yn = yn+1;
glVertex2f(xn,yn);
}
g = 2*dy-dx;
}
}

void disp()
{
glClearColor(0,0,0,0);
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1,1,1);

Bresenham();
glFlush();
}

int main(int argv, char ** argc)
{
printf("\nEnter x1 = ");
scanf("%f",&x1);
printf("\nEnter y1 = ");
scanf("%f",&y1);
printf("\nEnter x2 = ");
scanf("%f",&x2);
printf("\nEnter y2 = ");
scanf("%f",&y2);

glutInit(&argv,argc);
glutInitWindowSize(300,300);
glutCreateWindow("Bresenham");
glutDisplayFunc(disp);
glutMainLoop();
return 0;
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s