1. What Computer Graphics Is
Computer Graphics is the discipline of converting numerical data into visual representations that humans can perceive and interpret.
Every image displayed on a screen is fundamentally data—geometry, color, and depth—mapped to pixels at precise spatial locations and refreshed over time.
- Geometric view: Objects are represented using vertices, edges, surfaces, vectors, and matrices.
- Sampling view: Continuous geometry is discretized into pixels using rasterization and stored in the frame buffer.
2. Hardware Basics and the Frame Buffer
Input devices such as mouse, keyboard, and tablets generate events and coordinates. Output devices such as CRT, LCD, LED displays, plotters, and printers present the final visual output.
The frame buffer is a contiguous block of memory that stores color values for every pixel.
If resolution is $W \times H$ and color depth is $b$ bits:
$$\text{Memory} = W \times H \times b \text{ bits}$$
Example: $1024 \times 768$ resolution at 24-bit color requires approximately $18\ \text{MB}$.
3. The Graphics Pipeline — Model to Screen
The graphics pipeline transforms abstract models into displayed pixels through ordered stages.
- Modeling: Define objects using meshes or splines.
- Model, World, View transforms: Position objects and camera.
- Lighting and shading: Compute surface colors.
- Projection: Map 3D geometry to 2D.
- Clipping: Remove geometry outside the view.
- Rasterization: Convert primitives into fragments.
- Visible-surface determination: Select nearest fragment per pixel.
- Fragment shading and blending: Apply textures and transparency.
- Display: Write pixels to frame buffer.
4. Transformations — How Objects Move and Change
Transformations determine how a point changes position, size, or orientation.
Points are vectors and transformations are matrices.
For a point $(x,y)$:
- Translation: $x' = x + T_x,\; y' = y + T_y$
- Scaling: $x' = S_x x,\; y' = S_y y$
- Rotation: $$ x' = x\cos\theta - y\sin\theta,\quad y' = x\sin\theta + y\cos\theta $$
Homogeneous coordinates represent $(x,y)$ as $(x,y,1)$, enabling all affine transformations using a single $3 \times 3$ matrix.
Composite transformations require matrix multiplication in correct order; order is not commutative.
Three-dimensional transformations extend this idea using $4 \times 4$ matrices.
5. Projection — Mapping 3D to 2D
Parallel projection uses parallel projection lines and preserves size regardless of depth.
Perspective projection simulates human vision where distant objects appear smaller:
$$ x' = \frac{fx}{z},\quad y' = \frac{fy}{z} $$
Here, $f$ is focal length and $z$ represents depth.
6. Visible-Surface Algorithms
For each pixel, the visible surface is the one closest to the camera.
- Z-buffer: Stores depth per pixel, replacing color only if new depth is smaller.
- A-buffer: Stores lists of fragments per pixel, enabling correct transparency and anti-aliasing.
7. Rasterization — Drawing Primitives
Rasterization converts geometric primitives into discrete pixels.
- DDA: Uses floating-point increments.
- Bresenham: Uses integer arithmetic and decision parameters.
- Circle rasterization: Computes one octant and mirrors using symmetry.
8. Clipping — Restricting Geometry to the View
Clipping removes parts of geometry outside the viewing region.
Cohen–Sutherland assigns 4-bit region codes and performs trivial accept, reject, or intersection.
Vertical boundary intersection:
$$y = y_1 + m(x_{clip} - x_1)$$
Horizontal boundary intersection:
$$x = x_1 + \frac{y_{clip} - y_1}{m}$$
9. Color, Shading, and Lighting
Lighting models describe how light interacts with surfaces.
- Flat shading: One color per polygon.
- Gouraud shading: Interpolated vertex colors.
- Phong shading: Per-pixel lighting using interpolated normals.
Textures map 2D images onto surfaces using interpolation and mipmapping.
10. Animation — Change Over Time
Animation is defined as controlled change of properties over time.
- Tweening: Interpolation between keyframes.
- Morphing: Shape interpolation.
- Procedural and behavioral animation: Rule-based motion.
- Motion capture and dynamics: Real and physics-based motion.
Panning rotates the camera without translation.
11. Core Algorithms — Pseudocode
DDA Line Algorithm
dx = x2 - x1
dy = y2 - y1
steps = max(|dx|, |dy|)
x_inc = dx / steps
y_inc = dy / steps
for i = 0..steps:
plot(round(x), round(y))
x += x_inc
y += y_inc
Bresenham Line Algorithm (0 ≤ m ≤ 1)
p = 2*dy - dx
for each x:
if p < 0:
p += 2*dy
else:
p += 2*dy - 2*dx
y++
12. Numerical Practice and Intuition
Manual numerical problems reinforce understanding of rasterization, transformations, and clipping.
Practicing step-by-step arithmetic exposes precision issues and edge cases.
13. Pitfalls and Deep Insights
- Transformation order is critical.
- Integer arithmetic improves efficiency.
- Z-buffer precision depends on depth mapping.
- Transparency requires sorting or accumulation.
- Perspective-correct interpolation avoids distortion.
14. Exam-Speed Mental Shortcuts
- Check trivial accept/reject before clipping intersections.
- Choose stepping axis based on slope.
- Memorize common rotation results.
- Use homogeneous matrices for compact computation.