Lecture 4 - Finishing Rasterizer, Moving to OpenGL

Review

For the rasterizer due tonight:

One fun thing is that the bugs you get are really cool looking!!!

Depth Buffer

In general, ultimately we just want to render the triangles on the front of the object. For the file, when you read in the triangles and rendering them, they may be in a crazy order (which shouldn't matter). The Zbuf should tell you which ones are closer to the viewer, so in our case anything that has the higher z-value should be the value we write. We allocate:

float Zbuf[width][height];
// init default values of -infty
z_coord = alpha*v1z + beta*v2z + gamma*v3z
if(z_coord > Zbuff[x][y])
{
	// write the pixel
	Zbuf[x][y] = z_coord;
}

OpenGL

Our goal today is to get OpenGL to work! OpenGL is good for using the GPU to utilize graphics processes, such as rasterization. Lab 3 will pretty much be setting up OpenGL working on your machine, and beginning to get the mental model of the hardware and what's going on under the hood of each library call we need.

At this point, we have a mental model of what we need a graphic pipeline to do:

  1. Get a list of vertices from some file stream
  2. Get a list of faces for said vertices
  3. Draw triangles for each face, using a zbuffer

We now need to consider the different between CPU work (in C++) vs. GPU work (work running in parallel with each other, using OpenGL library calls):

Pasted image 20240123135637.png

The power of this is that you can set per-pixel colors to do per pixel coloring.

GPU

A GPU is just multiple SIMD (Single Instruction, Multiple Data) units, all of them can access some global memory.

Pasted image 20240123135844.png

Each compute will have some shared memory to, between similar cores.

But the main job is to use the programming view prior, but keep in mind how the hardware works so we have a reason to use it.

Why OpenGL?

Graphics Library as a Renderer

We consider how the library uses itself to store/use:

There's also lots of states you can set as well for colors/lighting/styles/etc. Consider the 'state' that you set prior to rendering Assignment 1.

We'll use glfw will handle the inputs between the windowing system of your OS and our inputs to it. However, all the gl starting calls are for OpenGL.

Render and Handle Data

All drawing data is stored in arrays, passed to the GPU and create a buffer object. You must indicate how the data is packed into the array.

GLSL

This is the OpenGL shading language. It is, in runtime, assembled and linked on the GPU.

Modern Graphics Challenges (Summary)

We must do more work as the programmer:

In general:

The Code

This is an overview of files seen in Lab 3. Some notes on important points are as follows.

Folders

You'll start by editing main.cpp. In general main will: