0% found this document useful (0 votes)
15 views6 pages

Computer Graphics Solved Assignment

This document is an assignment for a Computer Graphics course that covers key concepts such as raster systems, video RAM calculations, and the differences between raster and vector graphics. It also discusses the utility of OpenGL for graphics programming, the Cohen-Sutherland line-clipping algorithm, and outlines a mini rendering pipeline that transforms 3D objects into 2D images. The assignment emphasizes the importance of these concepts in modern graphics applications, including games and simulations.

Uploaded by

maanmaankhan0074
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views6 pages

Computer Graphics Solved Assignment

This document is an assignment for a Computer Graphics course that covers key concepts such as raster systems, video RAM calculations, and the differences between raster and vector graphics. It also discusses the utility of OpenGL for graphics programming, the Cohen-Sutherland line-clipping algorithm, and outlines a mini rendering pipeline that transforms 3D objects into 2D images. The assignment emphasizes the importance of these concepts in modern graphics applications, including games and simulations.

Uploaded by

maanmaankhan0074
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

University of Education, Vehari Campus

Department of Computer Science / Information Technology


Course: Computer Graphics (COMP4128)

Assignment #02

Question 1: Raster System – Pixel Access & Timing


A raster system is basically the most common type of display system we use today. Think of your
phone or laptop screen — it is made up of thousands of tiny dots called pixels. These pixels are
arranged in rows and columns, and together they form the full picture you see on screen. The
resolution of a screen tells us how many pixels it has. For example, 640 × 480 means 640 columns
and 480 rows.

Part (a): Pixels Accessed Per Second at 60 Frames Per Second


When a screen refreshes 60 times every second, the display controller has to go through every single
pixel 60 times. So the number of pixels accessed per second depends on total pixels in one frame
multiplied by 60.
System 1 — Resolution 640 × 480
Total pixels per frame = 640 × 480 = 307,200 pixels
Pixels per second = 307,200 × 60 = 18,432,000 pixels/second
System 2 — Resolution 1280 × 1024
Total pixels per frame = 1280 × 1024 = 1,310,720 pixels
Pixels per second = 1,310,720 × 60 = 78,643,200 pixels/second

Part (b): Access Time Per Pixel


Access time per pixel simply means how much time the system gets to spend on each pixel before it
needs to move to the next one. We find it by dividing 1 second by the total pixels accessed per
second.
System 1 (640 × 480):
Access time = 1 / 18,432,000 ≈ 54.25 nanoseconds per pixel
System 2 (1280 × 1024):
Access time = 1 / 78,643,200 ≈ 12.72 nanoseconds per pixel

Question 2: Minimum Video RAM for 1024 × 768 with 65,536 Colors
Video RAM (also called frame buffer memory) is the memory your computer needs just to store the
color information of every pixel on screen. The more pixels you have and the more colors you want
to support, the more memory is needed.
The key question is: how many bits are needed to represent 65,536 different colors?
Step 1 — Find bits per pixel:
65,536 = 2^16 → 16 bits per pixel required
Step 2 — Total pixels:
1024 × 768 = 786,432 pixels
Step 3 — Total bits needed:
786,432 × 16 = 12,582,912 bits
Step 4 — Convert to bytes and MB:
12,582,912 ÷ 8 = 1,572,864 bytes
1,572,864 ÷ 1,048,576 = 1.5 MB → Minimum Video RAM = 1.5 MB

Question 3: Raster and Vector Output Using C/C++


In Computer Graphics, there are two main ways to draw and display images on a screen — raster
graphics and vector graphics. Understanding the difference between them is very important.

What is Raster Graphics?


Raster graphics are made up of pixels. Each pixel has a specific color, and together they form an
image. When you zoom into a raster image too much, it becomes blurry and pixelated because you
are literally making the dots bigger. Common examples are JPEG and PNG images.

What is Vector Graphics?


Vector graphics use mathematical formulas to draw shapes like lines, circles, and curves. No matter
how much you zoom in, the image stays perfectly sharp because it is always being recalculated from
its formula. SVG files and logos are usually vector graphics.

Sample C++ Code – Drawing a Circle (Raster Output)


The following C++ code uses the graphics.h library to draw a filled circle on screen, which is a
classic raster output:
#include <graphics.h>
#include <conio.h>
int main() {
int gd = DETECT, gm;
initgraph(&gd, &gm, "");
setcolor(GREEN);
circle(200, 200, 80); // Raster circle
line(100, 300, 300, 300); // Vector-style line
getch();
closegraph();
return 0;
}
Note: Run this code using a compiler that supports graphics.h such as Dev-C++ with WinBGIm library. Take
a screenshot of the output and attach it with your submission.

Question 4: Why is OpenGL Useful for Computer Graphics?


OpenGL stands for Open Graphics Library. It is a tool that helps programmers draw 2D and 3D
graphics on the screen without worrying about what type of hardware or operating system the
computer is running. Think of it like a universal remote that works on any TV brand.
Key Reasons OpenGL is Used
• Cross-Platform Support: OpenGL works on Windows, Linux, and Mac. You write the code
once and it runs everywhere, which saves a lot of development time.
• Hardware Acceleration: OpenGL talks directly to the GPU (Graphics Processing Unit) on
your computer. This makes graphics much faster compared to drawing everything using only
the CPU.
• 2D and 3D Rendering: OpenGL can handle both 2D shapes and fully detailed 3D objects.
This makes it useful for everything from simple games to professional 3D simulations.
• Transformation Support: OpenGL has built-in support for all the transformations we have
studied — translation, rotation, scaling, and reflection — making it easy to move and
manipulate objects.
• Wide Industry Use: OpenGL is used in real games, medical imaging software, flight
simulators, CAD tools, and many other professional applications.
• Open Standard: It is free and open — anyone can use it without paying a license fee, which
makes it very popular in education and the industry.

Question 5: Advantages and Limitations of Cohen-Sutherland


Algorithm
The Cohen-Sutherland Algorithm is a line-clipping algorithm used in Computer Graphics. Clipping
means cutting off the parts of an object or line that fall outside the visible area of the screen (called
the viewport). This algorithm was developed by Danny Cohen and Ivan Sutherland and is still
widely used today.

How It Works (Simple Steps)


1. The visible area of the screen is defined by four boundaries — top, bottom, left, and right.
2. Each endpoint of a line is assigned a 4-bit region code based on where it sits relative to these
boundaries.
3. If both endpoints have a code of 0000, the line is fully inside — it is accepted and drawn.
4. If both endpoints share a common '1' in the same bit position, the line is fully outside — it is
rejected.
5. Otherwise, the line is partially inside and is clipped step by step at each boundary.

Advantages
• Very fast for lines that are completely inside or completely outside the viewport because they
are accepted or rejected without any calculation.
• Simple to understand and implement, making it a great starting point for learning clipping
algorithms.
• Works well when most lines are either fully visible or fully invisible.
• The region code system makes it easy to quickly identify where a line is located.
• It reduces unnecessary computation by quickly eliminating trivial cases first.

Limitations
• It only works for straight lines. It cannot clip curves, polygons, or other shapes directly.
• For lines that cross multiple boundaries, it may take several passes to clip correctly, which
can slow things down.
• It only works with rectangular clipping windows. If your visible area is not a rectangle, this
algorithm cannot be used directly.
• Not efficient when many lines partially cross the boundary — every such line needs extra
computation.
• More advanced algorithms like Cyrus-Beck are better for general polygon clipping situations.

Question 6: Case Study – Mini Rendering Pipeline


A rendering pipeline is the step-by-step process that a computer follows to turn a 3D object into the
2D image you finally see on your screen. Think of it like a factory assembly line — raw materials go
in one end, and a finished product comes out the other. In Computer Graphics, our raw material is a
3D object (made of triangles), and the finished product is the picture on your display.
Our mini pipeline has three main stages:

Stage 1: Object Modeling — Triangles


Every 3D object in a computer graphics system is built from triangles. Why triangles? Because a
triangle is the simplest polygon — it always lies perfectly flat on a plane no matter what. Whether
you are modeling a car, a human face, or a building, the computer breaks it down into thousands of
tiny triangles that together create the shape.
Each triangle is defined by three vertices (corner points) in 3D space:
A(x1, y1, z1), B(x2, y2, z2), C(x3, y3, z3)
Each triangle also lies on a plane, which is described by the equation Ax + By + Cz + D = 0. This
plane equation becomes very important in the later stages for lighting and visibility calculations.

Stage 2: Transformation Stage


Once we have our 3D object built from triangles, we need to position it correctly in the 3D world.
This is done using transformations — the same mathematical operations we studied in our lectures.
The three main transformations applied in this stage are:
• Translation: Moving the object to its correct position in the 3D scene. For example, placing
a car at a specific location on a road. Every triangle vertex is shifted using: x' = x + tx, y' = y
+ ty, z' = z + tz.
• Rotation: Turning the object to face the correct direction. A car on a road should face
forward. We use X, Y, and Z axis rotation formulas (Roll, Pitch, Yaw) to achieve this.
• Scaling: Making the object bigger or smaller. A toy car and a real car use the same model
but with different scale factors. Uniform scaling changes size equally on all axes.
All these transformations can be combined into a single matrix multiplication, which makes the
GPU process them very efficiently.

Stage 3: Clipping Stage


After transforming our objects, many parts of the scene may fall outside the camera's field of view.
Drawing those invisible parts would waste a lot of computing power. The clipping stage removes
everything that the camera cannot see.
This is where algorithms like Cohen-Sutherland come in. Each triangle is tested against the
boundaries of the viewing volume. There are three possible outcomes:
• Fully Inside: The triangle is completely visible. Keep it and move to the next stage.
• Fully Outside: The triangle is completely invisible. Discard it immediately.
• Partially Inside: Part of the triangle is visible. Cut off the invisible part and keep only what
the camera can see.

Stage 4: Projection Stage


The final stage is projection — converting our 3D world into a 2D image that can be shown on a flat
screen. This is exactly what a real camera does when it captures a 3D scene into a 2D photograph. In
Computer Graphics, we use the Pinhole Camera Model to simulate this.
The pinhole camera model works like this: imagine a single tiny hole (the pinhole). Light rays from
every point of the 3D object pass through this hole and land on the image plane behind it. The 3D
point P(X, Y, Z) gets projected onto the 2D image plane as point p(x, y) using these formulas:
x = f × (X / Z)
y = f × (Y / Z)
Here, f is the focal length (distance from pinhole to image plane). Objects farther away from the
camera appear smaller — just like in real life. This is called perspective projection, and it is the
reason 3D games and animations look so realistic.

Pipeline Summary Diagram


[ 3D Triangle Model ]

[ Transformation Stage ] ← Translation, Rotation, Scaling

[ Clipping Stage ] ← Remove invisible geometry

[ Projection Stage ] ← Pinhole camera: 3D → 2D

[ Final 2D Image on Screen ]

Conclusion
This assignment gave us a chance to explore some of the most important and practical ideas in
Computer Graphics. We learned how raster displays work and how the resolution directly affects
how much memory and processing power a system needs. We saw how video RAM is calculated
based on pixels and color depth. We explored why OpenGL is such a powerful and popular tool, and
we understood the Cohen-Sutherland Algorithm — how it quickly decides which lines to draw and
which ones to throw away.
The case study on the mini rendering pipeline was especially interesting because it tied together
almost everything we have learned — triangles from Lecture 12, 3D transformations from Lecture
10, and the pinhole camera model that explains how a 3D scene becomes a flat 2D image on your
screen. Every stage of the pipeline has a purpose, and removing any one of them would break the
final image.
Computer Graphics is not just about drawing pretty pictures — it is the backbone of modern games,
movies, simulations, and user interfaces. Every time you use your phone, watch an animated movie,
or play a video game, all of these concepts are silently working behind the scenes to create the visual
experience you enjoy.

You might also like