Skip to content
Tutorials Center
My learning

Topics

Computer Graphics Tutorial

Learn Computer Graphics step by step: 50 lessons in 13 chapters with examples, quizzes, diagrams and projects.

Start learning →

of lessons completed

Getting Started

  1. 1 What Is Computer Graphics? Learn what computer graphics is: raster vs vector images, 2D vs 3D, real-time vs offline rendering, where it is used and how the graphics pipeline works.
  2. 2 Pixels, Resolution and the Framebuffer Understand pixels, resolution, aspect ratio and bit depth, and learn how a framebuffer is just an array you can fill using canvas ImageData.
  3. 3 Coordinate Systems Learn screen vs Cartesian coordinates, the y-axis flip, and how world, view, normalized device and screen spaces fit together, with live demos.

Line and Circle Algorithms

  1. 4 The DDA Line Algorithm Learn how the DDA (digital differential analyzer) algorithm draws a line on a pixel grid with incremental steps, rounding, and its limitations.
  2. 5 Bresenham's Line Algorithm Learn Bresenham's line algorithm: the decision parameter, integer-only arithmetic, how to handle all octants, and how it compares with DDA, with a live step-through.
  3. 6 The Midpoint Circle Algorithm Learn the midpoint circle algorithm: the circle equation, eight-way symmetry and the integer decision parameter, with a live circle plotter and worked example.
  4. 7 The Midpoint Ellipse Algorithm Learn how the midpoint ellipse algorithm plots an ellipse with only additions: two regions, decision parameters, four-way symmetry and a live pixel plot.
  5. 8 Aliasing and Antialiasing See why raster lines show jaggies, learn the sampling idea behind them, and fix them with supersampling, pixel coverage and Wu's line algorithm.
  6. 9 Thick Lines, Dashes and Pen Styles Draw wide lines correctly: pixel replication and its flaws, line caps and joins, miter limits, dash patterns and the Canvas 2D line style properties.

Polygons and Filling

  1. 10 Polygons: Types and Representation Learn convex, concave and self-intersecting polygons, vertex lists, winding order and signed area, plus the even-odd and nonzero winding inside tests.
  2. 11 Scanline Polygon Filling Fill any polygon one row at a time with the scanline algorithm: edge table, active edge list, sorted intersections, vertex rules and a live software filler.
  3. 12 Flood Fill and Boundary Fill Learn flood fill and boundary fill: 4- and 8-connectivity, why recursion overflows, the stack-based version, scanline seed fill and a live paint bucket.
  4. 13 Triangle Rasterization and Barycentric Coordinates Learn how GPUs fill triangles: bounding boxes, edge functions, barycentric weights, the top-left rule and color interpolation, with live demos.

2D Transformations

  1. 14 Translation, Scaling and Rotation Learn the three basic 2D transformations with formulas and code: move, scale and rotate points, fixed-point scaling, and why order matters.
  2. 15 Homogeneous Coordinates and Matrix Transformations Learn why graphics uses homogeneous coordinates, how 3x3 matrices represent translation, scaling and rotation, and how to compose them in order.
  3. 16 Reflection, Shear and Inverse Transforms Learn reflection and shear matrices, how to invert any affine transform, and how Canvas setTransform uses the same math, with live examples.
  4. 17 Window-to-Viewport Mapping Learn the window-to-viewport transformation: the mapping formula, scale factors, aspect ratio distortion, and how zoom and pan work, with live demos.

Clipping

  1. 18 Cohen-Sutherland Line Clipping Learn the Cohen-Sutherland line clipping algorithm: region outcodes, trivial accept and reject, iterative clipping, with a live step-by-step clipper.
  2. 19 Liang-Barsky Line Clipping Learn the Liang-Barsky algorithm: parametric lines, the p and q values, entering and leaving edges, and how it compares to Cohen-Sutherland, with a live clipper.
  3. 20 Polygon Clipping: Sutherland-Hodgman Clip polygons against a window one edge at a time with the Sutherland-Hodgman algorithm: the four cases, concave pitfalls, Weiler-Atherton and a live clipper.

Color

  1. 21 RGB, CMY and CMYK Color Models Understand additive RGB and subtractive CMY/CMYK color, the RGB color cube, gamut and conversion code, with a live color mixer and overlap demos.
  2. 22 HSV, HSL, Gamma and Perceptual Color Learn HSV and HSL color models, conversion code, gamma correction, sRGB versus linear light, luminance and contrast ratios, with a live converter.
  3. 23 Gradients, Palettes and Dithering Interpolate colors for gradients and color maps, understand indexed palettes, and compare threshold, ordered (Bayer) and Floyd-Steinberg dithering live.

3D Transformations and Viewing

  1. 24 3D Points and Transformation Matrices Learn right- and left-handed 3D systems, 4x4 homogeneous matrices, translation, scaling and composition order, with a live matrix calculator.
  2. 25 3D Rotation: Axes, Euler Angles and Quaternions Learn 3D rotation matrices about x, y and z, why Euler angles suffer gimbal lock, and how axis-angle and quaternions with slerp fix it, with live demos.
  3. 26 The Camera and View Transformation Learn how a virtual camera works in 3D graphics: eye, target and up vector, the look-at view matrix, view space and an orbit camera, with live demos.
  4. 27 Orthographic and Perspective Projection Learn how 3D points are projected onto a 2D screen: parallel (orthographic) and perspective projection, the perspective divide, FOV and matrices, with demos.

Hidden Surfaces and Drawing 3D Objects

  1. 28 Polygon Meshes and Wireframe Rendering Learn how 3D objects are stored as polygon meshes: vertices, edges, faces, indexed triangles, winding and normals, plus a live wireframe renderer.
  2. 29 Back-Face Culling and the Painter's Algorithm Learn two classic hidden-surface techniques: back-face culling with the face-normal test, and the painter's algorithm with depth sorting and its limits.
  3. 30 The Z-Buffer Algorithm Learn how the z-buffer solves hidden surfaces per pixel: the depth buffer, the depth test, depth interpolation, precision and z-fighting, with live demos.

Lighting and Shading

  1. 31 Light and Reflection Models Learn how renderers fake light: ambient, Lambert diffuse, Phong and Blinn-Phong specular, and attenuation, with a live sphere and sliders.
  2. 32 Flat, Gouraud and Phong Shading Compare flat, Gouraud and Phong shading: per-face, per-vertex and per-pixel lighting, normal interpolation and Mach bands, with a live renderer.
  3. 33 Texture Mapping Learn texture mapping: UV coordinates, nearest and bilinear filtering, mipmaps, perspective-correct interpolation and procedural textures, with live demos.

Curves and Surfaces

  1. 34 Parametric Curves and Interpolation Learn parametric curves: Hermite and Catmull-Rom splines, tangents, and C0, C1 and G1 continuity, with a live curve editor you can drag around.
  2. 35 Bezier Curves Understand Bezier curves: Bernstein polynomials, the de Casteljau algorithm, cubic curves, subdivision and Canvas bezierCurveTo, with live editors.
  3. 36 B-Splines and NURBS Learn B-splines and NURBS: knot vectors, Cox-de Boor basis functions, local control, clamped curves and weights that draw exact circles, with live editors.
  4. 37 Bezier Surfaces and Fractals Extend curves to surfaces with bicubic Bezier patches and surfaces of revolution, then explore fractals: the Koch curve, L-systems, Mandelbrot and Julia sets.

Ray Tracing and Rasterization Pipeline

  1. 38 Ray Tracing: Rays, Spheres and Planes Build your first ray tracer: camera rays, the ray equation, ray-sphere and ray-plane intersection math, surface normals and simple shading, with live demos.
  2. 39 Shadows, Reflections and Refraction Add shadow rays, recursive mirror reflection and glass refraction with Snell's law and the Fresnel effect to your ray tracer, with a live recursive renderer.
  3. 40 The Rasterization Pipeline Follow a triangle through the graphics pipeline: vertex shader, clipping, perspective divide, viewport, rasterization, fragment shader and depth test, with a live mini-GPU.

WebGL and Real-Time Graphics

  1. 41 WebGL Overview Understand how WebGL draws with the GPU: contexts, buffers, shaders, programs, attributes, draw calls and the state machine, ending with a live triangle.
  2. 42 Shaders and GLSL Basics Learn GLSL for WebGL: vertex and fragment shaders, attributes, uniforms, varyings, vector types, swizzling and built-in functions, with live editable shaders.
  3. 43 A Rotating 3D Cube in WebGL Build a lit, rotating 3D cube in WebGL: model, view and projection matrices as uniforms, indexed drawing, the depth test, and Lambert lighting in the shader.

Projects, Practice and Review

  1. 44 Project: A Software 3D Engine Build a tiny 3D engine without a GPU: mesh, rotation, perspective projection, z-buffer and Lambert shading, drawn pixel by pixel in plain JavaScript.
  2. 45 Project: A Mini Paint Program Build a pixel paint program from scratch: Bresenham pencil, line, rectangle and circle tools, flood-fill bucket, color picker and undo, all in plain JavaScript.
  3. 46 Project: A Ray-Traced Scene Build a complete ray tracer in JavaScript: spheres, a checkered floor, a point light, hard shadows, recursive reflections and antialiasing, rendered live.
  4. 47 Project: A Fractal Explorer Build a Mandelbrot and Julia set explorer in JavaScript: escape-time rendering, smooth coloring, cosine palettes, click-to-zoom and speed-ups, rendered live.
  5. 48 Practice: Exercises with Solutions Twenty graded computer graphics exercises with runnable JavaScript solutions: line and circle algorithms, transforms, clipping, shading, projection and curves.
  6. 49 Computer Graphics Interview Questions 36 common computer graphics interview questions with concise answers on algorithms, transforms, projection, depth, shading, the pipeline and ray tracing, plus live checks.
  7. 50 Computer Graphics Cheat Sheet A one-page computer graphics cheat sheet: key formulas, matrices, line and circle algorithms, clipping, shading, ray tracing and pipeline stages, with live checks.