Lab 1

The purpose of this exercise is to help prepare you for the practical components of this course. More specifically, you will:

  • Setup your computer with the required tools
  • Revise Java
  • Gain an understanding of OpenGL


Part 1: Setting up

Firstly, you'll need to download UNSWgraph. You have two options to do this:

  • You can download the code as a zip file here . Unzip it where you want to keep your graphics work.
  • If you're familiar with git, you can clone the repository and create a branch from the v0.2 tag.
    cd <the directory you want to keep your graphics work>
    git clone https://github.com/robeverest/UNSWgraph.git
    cd UNSWgraph
    git checkout tags/v0.2 -b lab1
        

Once you have the code, you need to import it into eclipse. If you are using your own laptop and don't already have eclipse, you can get it from the eclipse website ( https://www.eclipse.org/downloads/ )

The code is already set up as an eclipse project, so you can just import it directly. To do so, go to 'File -> Import...' . In the list that comes up, under "General" select "Existing Projects into Workspace" and click next. On the subsequent screen, click browse at the top right and select the directory containing the project ("UNSWgraph-v0.2" if you downloaded the zip file, "UNSWgraph" if you cloned the git repo).

The project has the following structure:

  • src – All the Java source
    • unsw.graphics – Classes that form the basis of UNSWgraph. You don't need to understand them for this lab.
    • unsw.graphics.examples – Example applications. Familiarise yourself with the ones we covered in the week 1 lecture to make sure you understand how they work.
    • unsw.graphics.geometry – The basic geometric shapes that were shown in the lecture. Once again, make sure you understand how they work.
  • lib – This contains all the Java OpenGL (JOGL) library jar files.
  • shaders – We'll explain what these are in a later lecture.

If you open MoreInteresting.java in the examples package, you'll see that it draws a bunch of lines and a point. You can run it from the "Run" menu. Click "Run As -> Java Application". If everything is working, you should see a badly drawn aquatic animal appear in a window.

Note: If you're running this on the CSE lab machines, you may see some errors in the console relating to EGL, DRI and drivers. If everything else works, then you can safely ignore those messages.

Try adjusting the some of the points directly in the code. See if you can make it look less badly drawn.


Part 2: Drawing polygons

In this exercise you will create an application for drawing polygons. You can run a sample version on the lab machines with

java -jar /home/cs3421/public_html/PolygonDrawing.jar

or if you're using your laptop, download the sample , and run it locally with

java -jar PolygonDrawing.jar

in the directory with the file.

Left-clicking in the window creates a point. Subsequent left clicking creates a line strip connecting all the points. Right-clicking turns the last created line strip into a polygon.

Step 1 – Create a Polygon2D class

Create a Polygon2D class in the unsw.graphics.geometry package. It should contain:

  • A list of points for the vertices of the polygon
  • A constructor of the form
    public Polygon2D(List<Point2D> points) {
        ...
    }
        
  • A draw method that takes a GL3 object as a parameter and draws the polygon using GL_TRIANGLE_FAN.

Hint: Use the LineStrip2D class for inspiration

Step 2 – Create a PolygonDrawing application

Make a copy of LineDrawing.java and call it PolygonDrawing.java. Modify it so that polygons are drawn instead of line strips. Like in the sample, a line strip should be used while the polygon is still being drawn.

Play around with your program (maybe try to draw something pretty). What sorts of polygons can't you draw? What happens if you try to create a polygon with only 2 points? If it doesn't work, can you fix it?

Resource created Thursday 09 May 2019, 01:37:20 PM, last modified Friday 17 May 2019, 03:56:58 PM.


Back to top

COMP3421/COMP9415 19T2 (Computer Graphics) is powered by WebCMS3
CRICOS Provider No. 00098G