Professional Documents
Culture Documents
1
Lab Session Problem – 01
➢ Required Tools :
❖ Code Blocks
❖ OpenGL and GLUT using CodeBlocks.
❖ Tdm-gcc-10.3.0
➢ Expected Outcome :
❖ We will be introduced to OpenGL.We will be able
to use OpenGL with CodeBlocks.
2
➢ Session Details :
1) Input the line Start and End-points, Starting Point (𝑋0 , 𝑌0 ) Ending point(𝑋𝑛 , 𝑌𝑛 )
𝑃 = 2∆Y − ∆X
𝑃𝐾+1 = 𝑃𝑘 + 2∆Y
3
Source Code :
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
int main()
{
int x,y,x1,y1,x2,y2,dx,dy,p,i;
int gd=DETECT,gm;
4
putpixel(x,y,WHITE);
if(p<0)
{
x=x+1;
p=p+2*dy;
}
else
{
x=x+1;
y=y+1;
p=p+2*dy-2*dx;
}
i++;
}
getch();
closegraph();
return 0;
5
➢ Output :
6
Here, Our expected outcome is our Starting point (50,80) and Ending Point
(200,300) and output will show one street line.
➢ Conclusion :
Mainly Bresenham's Line Algorithm use fixed point, i.e Integer Arithmetic.
Bresenham's Line Algorithm uses only subtraction and addition its
operation. Bresenham's Algorithm is faster than DDA Algorithm in line
because it involves only addition & subtraction in its calculation and uses
only integer arithmetic. Bresenham's Line Algorithm is more accurate and
efficient at DDA Algorithm.That’s why we learn and implement
Bresenham’s Line Drawing Algorithm.