Q:

Write, compile and run a Java program to draw a line using Bresenham’s algorithm and Java OpenGL wrapper library (JOGL)

Bresenham line drawing Algorithm:

Input: point1 = (x1, y1) = (-2, 3) , =  ( x1, y1) = (8, 10)

Step 1: Start the program.

Step 2: Initialize the graphics mode using init graph function.

Step 3: Accept the input at starting and endpoint of the line to be drawn.

Step 4: Load (xi, yi) into the frame buffer to be plotted as a first point.

Step 5: Calculate the constants delta xdelta y, 2delta y - 2delta x and obtain the first decision parameter  p0= 2delta y - 2delta x

Step 6: At each  along the line starting at k = 0 perform the following test:

·       If Pk < 0, then

o      the next point is (Xk+1 ,yk  ),

o     pk+1= pk + 2delta y

·      If pk >= 0 , then

o      the next point to the plotted is (xk+1 , yk+1),

o     pk+1 =pk+   2delta y - 2delta x

Step 7: Repeat the process until the end point of the line to be drawn is encountered.

Step 8: Stop the program.