Question: Write a Java program which uses the LWJGL library to draw a window of 640x480 (with a black background). The coordinate system should be centered

Write a Java program which uses the LWJGL library to draw a window of 640x480 (with a black background). The coordinate system should be centered in this window. Your program will read a file titled coordinates.txt and draw the corresponding filled polygon in this window using a scanline polygon fill algorithm. NO use of fill functions/algorithms provided by openGL, the scan line should be hand coded. Each specified polygon should be filled in the color specified in the text file and then undergo the transformations specified in the input file before being drawn on the screen. Hence you will need to calculate the composition of the transformation matrices and then calculate the position of the polygon vertices and then apply the scan line fill algorithm. Use the glVertex2f() command to plot the pixel and glColor3f() to specify the color. Finally, your program should also use the input.Keyboard class to have the escape key quit your application. You may also add extra functional keys that would allow the user to change the colors of the polygon fills. These added functions should be clearly stated in your comments.

The given coordinates.txt file will be in the following format:

////////////////////////////////////////////////////////////////////////////////////////////////////////

P 0.5 0.6 0.3 // New Polygon - RGB values

30 300 // Vertices/Coordinates

80 150

160 400

200 150

250 300

T // Transormations below for polygon above

r 45 0 0 // rotate

s 0.5 1.5 0 0 // scale

t 200 150 // translate

r 90 0 0 // rotate

P 0.2 0.4 0.7 // Begin new polygon - RGB values

-350 350 // Vertices/Coordinates

-350 350

350 350

350 350

T // transformations below for new polygon

r 90 0 0

t 100 100

s 0.5 0.5 0 0

//////////////////////////////////////////////////////////////////////////////////////////////////////// The file coordinates.txt will contain an ordered set of vertices for the polygon. The polygon can be drawn by joining the first vertex to the second, the second to the third and so on, until the final vertex is joined to the first to close the polygon.

It denotes the polygon vertices by using the symbol P and the transformations for that polygon by using the symbol T.

The symbol P is followed by three-float numbers that signify the R, G and B values specifying the fill color of the polygon.

The symbols r, s and t stand for rotation, scaling and translation respectively.

The symbol r is followed by the rotation angle, and the coordinate for the pivot point.

Similarly the symbol s is followed by the scaling factors in the x and y direction and the pivot point coordinates.

The symbol t is followed by the translation coordinates in the x and y direction.

.

.

The output should show two transformed polygons.

Here's the coordinates.txt file used for testing:

////////////////////////////////////////////////////////////////////////////////////////////////////////

P 1.0 0.0 0.0 80 10 80 30 230 37 280 30 280 10 T t 100 -75 r 30 0 0 s 0.5 1.5 0 0 P 0.1 0.8 0.3 10 10 10 80 80 60 210 10 210 80 150 10 T r 90 0 0 s 2.0 0.2 0 0 t 30 30 r -45 0 0 ////////////////////////////////////////////////////////////////////////////////////////////////////////

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!