Skip to content
Tutorials Center
My learning

Topics

Lesson 1 of 50 ยท Getting Started

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.

Computer graphics is the art and science of making pictures with a computer. Every game frame, every chart on a dashboard, every special effect in a film, every button on your phone and every medical scan you can rotate on a screen is the result of a program turning numbers into colored pixels. This tutorial teaches you how that translation works, from the first principles up to ray tracers and GPU shaders.

You will not just read about it. In almost every lesson you will run small programs that draw pixel by pixel, so the algorithms stop being abstract. All you need is basic JavaScript (see Canvas drawing from JavaScript if you have never used a <canvas>) and some comfort with school-level geometry. We introduce the math as we need it.

Two ways to store a picture

A picture can be stored in two fundamentally different ways.

A raster (or bitmap) image is a grid of pixels. Each pixel holds a color, and the image is simply that table of colors. Photographs, screenshots, PNG, JPEG and WebP files are raster images. The screen of your monitor is a raster device too. A raster image has a fixed resolution: if you enlarge it, the program has to invent new pixels, so edges become blocky or blurry.

A vector image stores instructions: "draw a circle at this position with this radius, stroke it in blue". SVG files, fonts and the shapes in a drawing program are vector data. You can scale them to any size and the computer simply re-runs the instructions, so edges stay sharp. But before anything appears on a screen, the vector description must be converted to pixels. That conversion is called rasterization, and it is one of the main topics of this course.

flowchart LR
  V["Vector description<br/>circle(x, y, r)"] -->|"rasterization"| R["Raster image<br/>grid of pixels"]
  R -->|"display"| S["Screen"]

Even vector graphics end up as pixels. Rasterization is the bridge.

The next demo makes the difference visible. We draw a tiny circle into a 40 by 40 pixel canvas, then show it magnified six times. On the left, the raster copy is just those 40 by 40 pixels made bigger. On the right, the vector copy is drawn again at the large size from the same instruction.

Raster versus vector

Notice the stair-steps on the left. They come from the limited number of pixels, and fighting them (called antialiasing) gets its own lesson later.

2D and 3D graphics

2D graphics works with flat shapes: lines, circles, polygons, text, images. User interfaces, charts, maps and most illustrations are 2D. The math is mostly coordinates and matrices of size 3 by 3.

3D graphics describes a world with depth. Objects are made of triangles in three-dimensional space, and the computer must decide what a virtual camera sees: which surfaces are in front of others, how light falls on them, and how the 3D scene flattens onto a 2D screen. That flattening is projection, and it is why 3D needs 4 by 4 matrices, depth buffers and shading models. You will meet all of these in the chapters ahead.

The two worlds share a lot. Every 3D image is finally a 2D grid of pixels, so the 2D rasterization algorithms you learn first are the foundation for everything else.

Real-time and offline rendering

The process of producing an image from a scene description is called rendering. Two broad styles exist.

  • Real-time rendering must produce a new picture many times per second, typically 30 to 120 frames per second. Games, simulations and interactive apps work this way. Each frame has only a few milliseconds, so the renderer uses fast approximations and relies on graphics hardware (the GPU).
  • Offline rendering may spend seconds, minutes or hours on a single image. Animated films and visual effects work this way. With that much time, the renderer can simulate light physically, bouncing rays around the scene (ray tracing and path tracing).

The line is blurring. Modern GPUs can trace rays in real time, and offline tools borrow tricks from real-time ones. Still, the choice between "fast approximations" and "accurate simulation" explains many design decisions you will see in this course.

Where computer graphics is used

  • Games and interactive media: real-time 3D worlds, effects, user interfaces.
  • Film and animation: modeling, rendering, compositing.
  • Design and engineering (CAD): precise curves and surfaces for machines and buildings.
  • Data visualization: charts, maps and dashboards. See the data visualization tutorials for the charting side.
  • Medicine and science: volume rendering of scans, molecular models, simulations.
  • User interfaces and the web: every browser composes pages from rasterized text, shapes and images.
  • Augmented and virtual reality: low-latency stereo rendering.

The graphics pipeline at a glance

Whether the renderer runs on a GPU or in plain JavaScript, most 3D graphics follows a sequence of stages known as the graphics pipeline. Data enters as geometry (vertices and triangles) and leaves as colored pixels:

flowchart LR
  A["Model<br/>vertices, triangles"] --> B["Transform<br/>move, rotate, scale"]
  B --> C["View and projection<br/>camera, 3D to 2D"]
  C --> D["Clipping<br/>discard what is off screen"]
  D --> E["Rasterization<br/>triangles to pixels"]
  E --> F["Shading and depth<br/>color, who is in front"]
  F --> G["Framebuffer<br/>image on screen"]

A simplified pipeline. The chapters of this tutorial walk through each box, and a later lesson assembles them into a mini renderer.

You do not need to understand every stage yet. Keep this picture in mind: it is the map for the whole course. Chapter by chapter, we will cover pixels and the framebuffer, line and circle drawing, polygon filling, 2D and 3D transformations, clipping, color, hidden-surface removal, lighting, curves, ray tracing and finally WebGL.

A first hello

Here is a tiny version of the pipeline you can run now. A triangle is defined in a model space where coordinates run from -1 to 1 with y pointing up, like in school math. A short "transform" step converts those numbers to canvas pixels (where y points down). Then we draw. The log shows the numbers each vertex went through.

Hello, pipeline

In this hello, the browser's fill() did the rasterization for us. In the lessons that follow you will write that part yourself, starting with the humble question of how to draw a straight line on a grid of pixels.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What is the main difference between a raster image and a vector image?

    Raster data is a table of pixel colors with a fixed resolution. Vector data describes shapes and is converted to pixels (rasterized) when displayed, so it scales cleanly.
  2. 2. Why is a game usually rendered differently from an animated film?

    Real-time rendering has a tiny per-frame time budget, so it uses fast approximations. Offline rendering can afford physically accurate simulation.
  3. 3. What does rasterization do?

    Rasterization decides which pixels of the grid a shape covers, and that is how geometry becomes a picture.
  4. 4. In the hello example, why does the transform compute 1 - p.y?

    Screen coordinates start at the top-left and y increases downward, so an upward model value must be flipped.

Summary

  • Computer graphics turns numeric descriptions of shapes and scenes into pixels.
  • Raster images store a pixel grid; vector images store shape instructions. Vectors must be rasterized to be displayed.
  • 2D graphics deals with flat shapes; 3D adds depth, projection, hidden-surface removal and lighting.
  • Real-time rendering trades accuracy for speed; offline rendering trades time for accuracy.
  • The graphics pipeline (model, transform, view and projection, clipping, rasterization, shading, framebuffer) is the map of this course.

Next, let's look at what a screen really stores: Pixels, Resolution and the Framebuffer.