This assignment has 2 major deliverables Part A – OpenGL Scene Renderer and Part B – Unity Environment. You should complete and submit part A before you begin part B.
Assignment 2 overall is worth 50% towards your grade and has two subassessment items:
Part A – OpenGL Scene Renderer (50%)
Part B – Unity Environment (50%)
2 Part A – OpenGL Scene Renderer Introduction
In this assignment you will implement a scene viewer in OpenGL. The assignment is structured to gradually introduce more advanced OpenGL concepts, beginning with a simple triangle. Each step introduces a new aspect of OpenGL.
For best results complete the steps in the order given.
2.1 Overview of Starting Code
The assignment includes many Java classes. Some of these you will need to
modify when you implement the assignment, and others do things for you.
The starting code is structured into Java packages to make it easier to keep things organised. Four packages are provided:
This package contains the main Assignment class,which starts the program. It also contains the AssignGLListener that you will implement to build your application.
This package contains classes that can be rendered on screen. You will need to modify many of these classes to have them render on screen.
This package contains classes for different lights. You will need to use these classes to implement lighting in your scene viewer.
This package contains the math classes that you will need to use when performing mathematical operations.
This package contains the scene loader and scene specific classes that are not drawables. You will need to use Scene to decide what to render, and Camera to calculate the view and projection matrices.
2.1.2 Classes you will modify
You will also need to write several GLSL shaders. Empty, correctly named,shader files can be found in the shaders directory.
2.2 Starting your implementation
A set of suggested steps is provided below to walk you through the assignment.
There are a number of optional features you may attempt once the basic rendering is working. Please refer to the marking sheet below to help you decide which are optimal for your final grade.
2.2.1 An Empty Window
At the end of this step you will have a black window on screen. This may not sound like much but you’ll have a lot of the groundwork taken care of. Do the following:
- Get the starting code into your IDE of choice and make sure everything compiles
- Modify AssignEventListener’s init method:
- Set the clear colour to black
- Enable back-face culling
- Modify AssignEventListener’s display method:
- Clear the depth and color buffers
2.2.2 A Red Triangle
- Implement the Triangle class:
- The init method should load the positions of the vertices to OpenGL
- The display method should render the triangle
- Create a vertex shader named SimpleShader.vert. This shader should read in the vertex position and pass this through to the next stage.
- Create a fragment shader named SimpleShader.frag that sets the colour of the fragment to red (1.0,0.0,0.0,1.0)
- Load and use your shader to render the scene SimpleTriangle.scene
2.2.3 Vertex Colours
A red triangle is great, but other colours are better. The vertices of the Triangle class have colours associated with them. In this step we’ll make use of them.
- Modify your triangle class by adding a vertex attribute for the colour
- Create new vertex and fragment shaders, named VertexColour.vert and
VertexColour.frag to use these colours.
- Load and use this shader to render the scene ColouredTriangle.scene
2.2.4 View Transformation
At this step we will implement projection and view transformation and start seeing the 3D world.
- Create projection and view matrices from the Camera class loaded in the scene.
- Create a new vertex shader Transform.vert which transforms the incoming vertex using the projection and view matrices.
- Send the projection and view matrices to the shader as uniform variables.
- Render the scene PerspectiveTest.scene using the Transform.vert vertex shader and VertexColour.frag fragment shader.
- Implement reshape in your listener to correctly reset the projection matrix when the window is resized.