1 of 11

Introduction to C++/Graphics

Nathan Reed, Stephanie Hurlburt, Sophia Baldonado, Jorge Rodriguez, Cody Burrow, Jacob Liechty

2 of 11

Set up your project!

CMake is a tool that lets us easily make projects for different platforms and IDEs.

So, grab the project from https://github.com/Reedbeta/gfx-workshops. Downloading a .zip file is fine—unzip it to any directory.

Install CMake!

Open the CMake GUI, and set the build and source code directories to the project directory.

Click Generate! It’s quite magical—your project is now made and you can open it in your IDE of choice.

3 of 11

Introductions

Hello!

We come from a variety of backgrounds—game design, art, VR, graphics programming, and more. We all share a passion for making tools for artists using low-level programming.

C++ and graphics API knowledge allows us to make our own tools and understand how tools other people make work.

This is powerful!

4 of 11

What do graphics programmers do?

  • Teach computers how to make pretty pictures!
  • Make tools for artists!
  • Write shaders
  • Optimize rendering code
  • Procrastinate on ShaderToy

These days, graphics programming is useful in almost every industry!

5 of 11

What’s a GPU?

  • Special purpose hardware for drawing triangles!
  • Very fast at drawing! (Not so fast at other stuff.)
  • Batch everything! Processes large chunks of data in parallel (triangles, pixels)

6 of 11

What tools are we using today?

  • C++, written in a hackable style
  • Libraries written by other people:
    • GLAD, auto-generated C++ headers to expose the OpenGL functions of your GPU
    • GLFW, a cross-platform API for creating windows, GL contexts, and processing input
    • stb_image, a one-header C library for easy loading of many image formats
  • And CMake/Make, to build the source.

7 of 11

What’s a Graphics API?

  • Common interface for apps to talk to many different GPUs
  • Send data to the GPU for it to work on
  • Send commands to the GPU to tell it what to do

Lots of APIs! Direct3D, OpenGL, Vulkan, Metal, special APIs for game consoles

Like programming languages...similar concepts, different execution

Today we’re using OpenGL, which runs across almost all OSes and GPUs!

8 of 11

What are Rasterization and Raytracing?

Rasterization

Raytracing

List of Triangles�Rasterize Pixels�

List of Rays�Raycast Geometry�

Image Sources: www.scratchapixel.com

9 of 11

Particle Demo Ideas

  1. Play with RGB colors! Edit the fragment shader (fragment_shader.glsl) to change the color of the particles.
  2. Write an equation in the fragment shader to generate colors on the particles! Use the vertex position (or some of the other data) to change the color.
  3. Change how the particles move! Edit the simulate_particles() function to make them bounce, or do zigzags or something.
  4. Add a texture! Get an image from the internet and apply it to your particles. (Advanced! Hint: use the included stb_image library to load the image.)

10 of 11

Raytracing Demo Ideas

  1. Add more spheres! Animate them so they move around in an interesting way.
  2. Add more lights!
  3. Make it shiny, by adding specular lighting to the shader.
  4. Add shadows, by casting additional rays toward the light source.

11 of 11

Now go build things!

Most of this workshop will be about all of you coding!

We’ll float around and help you edit and extend the particle system and raytracing samples.

Have fun!