Program 2 2022: intro to webgl

Due: 11:59pm, Monday Oct 3

Goal: In this assignment you will focus on gaining basic understanding of the WebGL rasterization API, by learning how to render and manage a few triangles.

Submission: Submit your assignment using this Google Form.


GRADING:
This assignment is a forgiving introduction to WebGL, with correspondingly forgiving grading. The main components of this programming assignment are:
  • 25% Part 1: attempt improvement of vertex and index arrays
  • 25% Part 2: render input triangles correctly
  • 25% Part 3: attempt improvement of shader to handle parameters
  • 25% Part 4: triangles in input color
  • Participation: Receive participation credit (outside of this assignment) for posting images of your progress, good or bad, on the class forum! Please tag pretty but wrong imagery with #prettybugs.

General:
You may (optionally) work with one partner on this assignment. You should each turn in the same code. 

You will only render triangles in this assignment, described in the same sorts of JSON input files used in the first. We will test your program using several different input files, so it would be wise to test your program with several such files. The input files describe arrays of triangles using JSON. An example input file resides at https://ncsucgclass.github.io/prog2/triangles.json. When you turn in your program, you should use this URL in hardcode as the location of the input triangles file — it will always be there. While testing, you should use a different URL referencing a file that you can manipulate, so that you can test multiple triangles files. Note that browser security makes loading local files difficult, so we encourage you to access any input files with HTTP GET requests.

We provide a small shell in which you can build your code. You can run the shell here, and see its code and assets here. The shell shows how to draw triangles using WebGL, treating them all the same way. It also shows how to parse the input triangles.json file.

We are using webGL's default view setup, with the eye at the origin, and the window from -1 to 1 horizontally and vertically.

This is an individual or partnered  assignment, no exceptions. That said, we encourage you to help one another. Feel free to suggest how other students might solve problems, and to help them debug their code — just don't write their code for them. The code you turn in should still be your own or your single partner's (except for the shell). This is a simple assignment, and should not need other third party libraries. As always, if you are ever uncertain if the help you want to give or the code you want to use is permissible, simply ask me or the TA. For information about how to correctly submit, see this page on the class website.

Parts 1 & 2: Attempt to improve vertex and index array, and render triangles correctly
For these parts of the assignment, your goal is to display the input triangles in the correct position. The shell only renders the first set of triangles, in solid white. You must change the code to display all the triangles, improving two arrays: one that describes the vertices and their attributes, and another that describes the triangles by listing their vertex indices. If you make a solid attempt at improving these arrays, you will receive full credit for Part 1. If you correctly render all the triangles in white, you will earn full credit for Part 2.

Parts 3 & 4: Attempt to improve the shader, and render the input colors correctly
For these parts of the assignment, your goal is to color the input triangles with their diffuse color. The shell includes basic shader code that renders everything in white. You must change the shader to accept and use a parameter, and the code to send the shader a different value for the parameter for each triangle set. If you make a solid attempt at this, you will receive full credit for Part 3. If you correctly render each triangle set with its unique color, you will earn full credit for Part 4.