What is Computer Graphics?
Computer graphics is the creation, manipulation, and display of visual content using computers. It involves representing and rendering geometric data.
Understanding the foundations and applications of CG.
Computer graphics is the creation, manipulation, and display of visual content using computers. It involves representing and rendering geometric data.
How objects map from the mathematical world to the physical screen.
The mathematical coordinate space where the scene is defined.
Shows 2D graphics without making faraway objects look smaller. It keeps everything the same size regardless of depth.
A selected rectangular region of the world space to be displayed.
The sub-region of the screen/display where the window is mapped.
The actual physical pixels on the device monitor.
To convert a point (x, y) in the world window to a point (sx, sy) in the screen viewport, we use proportional mapping:
Where W = Window, V = Viewport, L=Left, R=Right, T=Top, B=Bottom.
In OpenGL, the coordinate system origin (0,0) is natively at the lower-left corner. Setting up the mapping requires three tasks:
gluOrtho2D(left, right, bottom, top); (preceded by glMatrixMode(GL_PROJECTION); glLoadIdentity();)glViewport(left, bottom, width, height);glBegin() and glEnd() calls which are then automatically mapped.Drag the World Window to see how it affects the Viewport.
Digital Differential Analyzer: A step-by-step line drawing technique.
DDA uses floating-point arithmetic to calculate the next pixel on a line by incrementally adding the slope to either x or y. It relies on two key mathematical functions:
dx = x2 - x1 and dy = y2 - y1steps = max(|dx|, |dy|)xInc = dx / steps, yInc = dy / stepsAdvantages:
Disadvantages:
| Step | x | y | Rounded (X,Y) |
|---|
Integer-based, highly efficient line drawing algorithm.
Bresenham's algorithm uses a decision parameter P to choose between the East (E) or North-East (NE) pixel.
2dy - dxP_{k+1} = P_k + 2dyP_{k+1} = P_k + 2dy - 2dxdy = 3, dx = 8, 2dy = 6, 2dx = 16
Initial P₀ = -2
Since P₀ < 0 → P₁ = -2 + 6 = 4. Pixel: (3, 5)
| Metric | DDA | Bresenham |
|---|---|---|
| Speed | Slower | Faster |
| Accuracy | Rounding errors | Exact |
| Arithmetic | Floating-point | Integer only |
| k | Pk | (Xk+1, Yk+1) |
|---|
Efficiently removing lines or parts of lines outside the viewing window.
Every point is assigned a 4-bit binary code (TBRL) indicating its position relative to the clipping window (Top, Bottom, Right, Left).
1001 | 1000 | 1010 ------------------ 0001 | 0000 | 0010 ------------------ 0101 | 0100 | 0110
Drag the line endpoints to see how the outcodes change and whether the line is accepted, rejected, or clipped.
Clipping an entire polygon against each edge of a window.
When traversing from vertex V1 to V2 against a clipping boundary:
The entire polygon is clipped against the Left edge, producing a new polygon. This new polygon is then clipped against the Right edge, then Top, then Bottom.
Modeling realistic appearance using the Phong Reflection Model.
Combines three components to simulate light interacting with a surface:
Wrapping a 2D image around a 3D object to add realistic detail.
Textures use a 2D coordinate system (U, V) ranging from 0.0 to 1.0. These are mapped to the (X, Y, Z) vertices of 3D geometry.
glGenTextures() - Name the textureglBindTexture() - Bind texture to its nameglTexParameteri() - Specify texture parametersglTexEnvf() - Specify application modeglTexImage2D() - Create the texture objectglEnable(GL_TEXTURE_2D) - Enable texture mappingCreating immersive and realistic virtual worlds.
Status: Immersive realism enabled. The scene feels lifelike.
Where computer graphics is heading next.
Photorealistic worlds.
3D MRI and scanning.
CAD and prototyping.
Flight & driving simulators.
Calculating the exact path of light rays in real-time, enabling perfect reflections and soft shadows.
Using Deep Learning to upscale lower resolution images to high resolution in real-time without performance hits.
Creating exact digital 3D replicas of physical factories, cities, or machines for monitoring and testing.
Interconnected virtual 3D spaces meant for social interaction, work, and entertainment.
Consider a software system displaying 3D roads, moving vehicles, traffic signals, and day/night simulations. Here is how CG concepts are applied:
Observe both algorithms drawing the exact same line simultaneously.
DDA uses round() which can pull the pixel selection in slightly different directions compared to Bresenham's exact integer Pk decision, especially on lines with specific fractional slopes. Bresenham is considered the mathematically "truer" representation of the ideal line.
The ultimate 5-minute pre-exam cram guide. Memorize these formulas.
dx = x2 - x1 dy = y2 - y1 steps = max(|dx|, |dy|) xInc = dx / steps yInc = dy / steps x = x + xInc y = y + yInc Plot( round(x), round(y) )
dx = |x2 - x1| dy = |y2 - y1| Initial P₀ = 2dy - dx If Pk < 0: Next P = Pk + 2dy x = x + 1 If Pk ≥ 0: Next P = Pk + 2dy - 2dx x = x + 1 y = y + 1
Outcode Sequence: TBRL (Top, Bottom, Right, Left) TOP = 1000 BOTTOM = 0100 RIGHT = 0010 LEFT = 0001 Accept if: Code1 OR Code2 == 0000 Reject if: Code1 AND Code2 != 0000
I = Ambient + Diffuse + Specular
I = (Ka * Ia) +
(Kd * Id * (N·L)) +
(Ks * Is * (R·V)^n)
Ka, Kd, Ks = Material Constants
Ia, Id, Is = Light Intensities
n = Shininess
N = Normal, L = Light Dir
R = Reflection, V = View Dir
Be prepared for direct examiner questions.
A: DDA uses floating-point arithmetic. Successive additions of fractional numbers (xInc, yInc) cause rounding errors to accumulate, eventually pushing the plotted pixel off the ideal mathematical line. Bresenham uses exact integer mathematics.
A: It relies entirely on integer addition, subtraction, and bit-shifting (multiplying by 2). It avoids expensive floating-point operations and the `round()` function.
A: A 4-bit binary code assigned to a point that describes its position relative to the viewing window (Top, Bottom, Right, Left). It allows for rapid bitwise AND/OR operations to accept or reject lines.
A:
- Flat: Calculates light once per polygon. Very blocky.
- Gouraud: Calculates light at vertices and interpolates colors across the polygon. Smoother, but misses specular highlights in the center of large polygons.
- Phong: Interpolates normal vectors across the polygon and calculates the full lighting equation for every single pixel. Most realistic, most expensive.
A: The resulting image on the screen will be stretched or squashed (distorted). To maintain proportional geometry, `(Window Width / Window Height)` must equal `(Viewport Width / Viewport Height)`.
Test your skills. Generate a problem, solve it visually, and get instant feedback.
A unified sandbox to freely test algorithms.
Test your knowledge and prepare for exams.
Enter values to instantly get the steps for exam verification.
Detailed statistics on your study progress and exam readiness.
Formula: 40% Progress + 40% Challenge Accuracy + 20% Quiz Performance