Computer Graphics
COMP3421/9415
2021 Term 3 Lecture 4
What did we cover last lecture?
Starting to look at 2D Rendering
What are we covering today
Making games in 2D (not quite, but close!)
Textures
Textures Recap
What we've seen about Textures
Images credit: id Software
Why are Textures useful?
Textures vs Coloured Vertices
Simple Geometry, Complex Colours
Image credit: Gearbox Software
Texturing in the OpenGL Pipeline
We're starting with using 2D Textures
Image credit: learnopengl.com
Texture Wrapping
How do textures deal with sampling outside 0-1
Image credit: learnopengl.com
Texture Wrapping Options
Why might we go outside the 0-1 range for texture sampling?
Texture Filtering
It's not a one to one match between fragments and Texture Pixels
Image credit: learnopengl.com
Mipmaps
Do both of those filtering options look bad?
Image credit: learnopengl.com
Mipmaps
Matrix Transforms
Transforming Objects
Our vertices have been set in stone up to this point
Image credit: Hasbro
Vectors and Matrices
How well do you remember your Linear Algebra?
Vector Math in a visual sense
If we're going to use vectors in a visual system . . .
Visual Vector Arithmetic
Images credit: learnopengl.com
Adding
Subtracting
Cross Product
Applying Matrices to Vertices (by multiplying)
We can multiply a vector by a matrix
Vectors in OpenGL
x,y,z,w
Scale
Changing the size of an object
Scale x | 0 | 0 |
0 | Scale y | 0 |
0 | 0 | 1 |
Translate
Moving an object
1 | 0 | Tx |
0 | 1 | Ty |
0 | 0 | 1 |
Rotate
Spinning an object
cosθ | -sinθ | 0 |
sinθ | cosθ | 0 |
0 | 0 | 1 |
Combining Transforms
Matrices can be multiplied with each other
Image credit: Hasbro
Two different orders
Translate then Rotate
Rotate then Translate
Transforms in OpenGL
Now that we've reviewed all that maths
A small Case Study
With Textures and Transforms . . .
Is it possible to replicate Mario?
Image credit: Nintendo (but totally an artwork by Marc Chee)
Sprites (Textures)
We could use this image as a texture for Mario
Sprites of Mario
Image credit: Nintendo
Transforms for Mario
How do controls affect the character?
Environment
Sprites/Textures for the Environment
What did we learn today?
Textures and Transforms