0% found this document useful (0 votes)
13 views16 pages

Module 1 CGV

The document provides an overview of computer graphics, defining it as the art of creating images using computers and detailing its various applications, such as data visualization, computer-aided design, and virtual reality. It also explains the operation of CRT monitors, including electron gun functioning, beam control, and phosphor coating, as well as the differences between raster-scan and random-scan displays. Additionally, it discusses the architecture of raster-graphics systems that utilize a display processor for efficient image rendering.

Uploaded by

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

Module 1 CGV

The document provides an overview of computer graphics, defining it as the art of creating images using computers and detailing its various applications, such as data visualization, computer-aided design, and virtual reality. It also explains the operation of CRT monitors, including electron gun functioning, beam control, and phosphor coating, as well as the differences between raster-scan and random-scan displays. Additionally, it discusses the architecture of raster-graphics systems that utilize a display processor for efficient image rendering.

Uploaded by

mukesh2usless
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

Join Whatsapp Channel: https://whatsapp.

com/channel/0029VaA9uVVIiRp0RS5li20r

Module 1
Q1. What is computer graphics? Explain the applications of computer graphics.
Ans : Computer graphics is an art of drawing pictures, lines, charts, etc. using computers with the
help of programming. Computer graphics image is made up of number of pixels. Pixel is the smallest
addressable graphical unit represented on the computer screen.

Applications of Computer Graphics


a. Graphs and Charts
• An early application for computer graphics is the display of simple data graphs usually
plotted on a character printer. Data plotting is still one of the most common graphics
application.

• Graphs & charts are commonly used to summarize functional, statistical, mathematical,
engineering and economic data for research reports, managerial summaries and other types
of publications.

• Typically examples of data plots are line graphs, bar charts, pie charts, surface graphs,
contour plots and other displays showing relationships between multiple parameters in two
dimensions, three dimensions, or higher-dimensional spaces

b. Computer-Aided Design
• A major use of computer graphics is in design processes-particularly for engineering and
architectural systems.

• CAD, computer-aided design or CADD, computer-aided drafting and design methods are
now routinely used in the automobiles, aircraft, spacecraft, computers, home appliances.

• Circuits and networks for communications, water supply or other utilities are constructed
with repeated placement of a few geographical shapes.

• Animations are often used in CAD applications. Real-time, computer animations using wire-
frame shapes are useful for quickly testing the performance of a vehicle or system.

c. Virtual-Reality Environments
• Animations in virtual-reality environments are often used to train heavy-equipment
operators or to analyze the effectiveness of various cabin configurations and control
placements.
• With virtual-reality systems, designers and others can move about and interact with objects
in various ways. Architectural designs can be examined by taking simulated “walk” through
the rooms or around the outsides of buildings to better appreciate the overall effect of a
particular design.

• With a special glove, we can even “grasp” objects in a scene and turn them over or move
them from one place to another.

d. Data Visualizations
• Producing graphical representations for scientific, engineering and medical data sets and
processes is another fairly new application of computer graphics, which is generally referred
to as scientific visualization. And the term business visualization is used in connection with
data sets related to commerce, industry and other nonscientific areas.
Join Whatsapp Channel: https://whatsapp.com/channel/0029VaA9uVVIiRp0RS5li20r

• There are many different kinds of data sets and effective visualization schemes depend on
the characteristics of the data. A collection of data can contain scalar values, vectors or
higher-order tensors.

e. Education and Training


• Computer generated models of physical,financial,political,social,economic & other systems
are often used as educational aids.

• Models of physical processes physiological functions,equipment, such as the color coded


diagram as shown in the figure, can help trainees to understand the operation of a system.

• For some training applications,special hardware systems are designed.Examples of such


specialized systems are the simulators for practice sessions ,aircraft pilots,air traffic-control
personnel.

• Some simulators have no video screens,for eg: flight simulator with only a control panel for
instrument flying

f. Computer Art
• The picture is usually painted electronically on a graphics tablet using a stylus, which can
simulate different brush strokes, brush widths and colors.

• Fine artists use a variety of other computer technologies to produce images. To create
pictures the artist uses a combination of 3D modeling packages, texture mapping, drawing
programs and CAD software etc.

• Commercial art also uses theses “painting” techniques for generating logos & other designs,
page layouts combining text & graphics, TV advertising spots & other applications.

• A common graphics method employed in many television commercials is morphing, where


one object is transformed into another.

g. Entertainment
• Television production, motion pictures, and music videos routinely a computer graphics
methods.

• Sometimes graphics images are combined a live actors and scenes and sometimes the films
are completely generated a computer rendering and animation techniques.

• Some television programs also use animation techniques to combine computer generated
figures of people, animals, or cartoon characters with the actor in a scene or to transform an
actor’s face into another shape.

h. Image Processing
• The modification or interpretation of existing pictures, such as photographs and TV scans is
called image processing.

• Methods used in computer graphics and image processing overlap, the two areas are
concerned with fundamentally different operations.

• Image processing methods are used to improve picture quality, analyze images, or recognize
visual patterns for robotics applications.
Join Whatsapp Channel: https://whatsapp.com/channel/0029VaA9uVVIiRp0RS5li20r

• Image processing methods are often used in computer graphics, and computer graphics
methods are frequently applied in image processing.

• Medical applications also make extensive use of image processing techniques for picture
enhancements in tomography and in simulations and surgical operations.

• It is also used in computed X-ray tomography(CT), position emission tomography(PET),and


computed axial tomography(CAT)

i. Graphical User Interfaces


• It is common now for applications software to provide graphical user interface (GUI).

• A major component of graphical interface is a window manager that allows a user to display
multiple, rectangular screen areas called display windows.

• Each screen display area can contain a different process, showing graphical or non-graphical
information, and various methods can be used to activate a display window.

• Using an interactive pointing device, such as mouse, we can active a display window on
some systems by positioning the screen cursor within the window display area and pressing
the left mouse button.

Q2. Define Computer Graphics. Explain the basic operation of video monitors based on
standard CRT design. OR With a neat diagram explain the electrostatic deflection of the
electron beam in a CRT.
Ans :

The standard Cathode-Ray Tube (CRT) design has been a fundamental technology in video monitors
for many years.

Basic Operation of CRT Monitors


1. Electron Gun and Acceleration:
◦ Electron Emission: The CRT monitor contains an electron gun at the back of the tube. This
electron gun consists of a heated metal cathode and a control grid. The cathode is heated by a
filament, causing it to emit electrons due to the thermionic emission effect.

◦ Acceleration: These electrons are then accelerated towards the screen by applying a high positive
voltage to the anode. This high voltage causes the electrons to gain kinetic energy as they travel
through the vacuum inside the CRT.
Join Whatsapp Channel: https://whatsapp.com/channel/0029VaA9uVVIiRp0RS5li20r

2. Beam Control and Focusing:


◦ Control Grid: The intensity of the electron beam is regulated by varying the voltage on the control
grid. This grid modulates the number of electrons passing through, thus controlling the brightness of
the spot on the screen.

◦ Focusing: The electron beam is focused to a small, precise point on the screen. This is achieved
using electrostatic or magnetic focusing systems. In electrostatic focusing, the beam passes through
a positively charged metal cylinder that helps concentrate the electrons into a narrow beam.
Magnetic focusing uses magnetic fields generated by coils to achieve the same result.

3. Deflection Systems:
◦ Magnetic Deflection: CRTs commonly use magnetic deflection to direct the electron beam to
different parts of the screen. Two pairs of magnetic deflection coils are used: one pair controls
horizontal deflection (mounted on opposite sides of the CRT neck) and the other controls vertical
deflection (mounted on the top and bottom of the CRT neck). The magnetic fields created by these
coils steer the electron beam across the screen.

◦ Electrostatic Deflection: Alternatively, electrostatic deflection can be employed, where pairs of


parallel plates inside the CRT apply electric fields to steer the beam. One pair of plates controls
horizontal movement, and the other controls vertical movement.

4. Phosphor Coating and Light Emission:


◦ Phosphor Coating: The inside surface of the CRT screen is coated with phosphor material. When
the electron beam strikes the phosphor, the kinetic energy of the electrons is transferred to the
phosphor atoms. This energy excites the electrons in the phosphor, causing them to move to higher
energy levels.

◦ Light Emission: As these excited phosphor electrons return to their ground state, they release
energy in the form of light photons. This emitted light forms the visible image on the screen. The
brightness of the image is dependent on the number of electrons striking the phosphor and the
efficiency of the phosphor material.

5. Refresh Rate and Persistence:


◦ Refresh Rate: To maintain a stable image on the screen, the CRT continually redraws the image.
The frequency at which the image is refreshed is known as the refresh rate. This is crucial because
the phosphor's glow fades quickly, and without frequent refreshing, the image would flicker.

◦ Persistence: Different phosphors have varying persistence levels, which affect how long they
continue to emit light after being struck by the electron beam. Lower persistence phosphors require
higher refresh rates to avoid noticeable flicker.

6. Resolution:
◦ Definition: The resolution of a CRT monitor refers to the maximum number of distinct points (or
pixels) that can be displayed without overlap. This is determined by the type of phosphor used, the
focusing system, and the deflection accuracy.

◦ High-Definition: CRT monitors with high resolutions are often referred to as high-definition
systems, as they can display more detail and clearer images due to their ability to render finer points.

Q3. Shadow Mask CRT


Ans : Shadow-Mask CRT Operation
1. Phosphor Dot Arrangement: The CRT screen is coated with three different color phosphor
dots at each pixel position, forming a pattern known as a "dot triangle." These dots are
colored red, green, and blue.
Join Whatsapp Channel: https://whatsapp.com/channel/0029VaA9uVVIiRp0RS5li20r

2. Electron Guns: The CRT features three separate electron guns, each dedicated to one of the
primary colors: red, green, or blue. These guns emit electrons that are aimed at the
phosphor-coated screen.

3. Shadow Mask Grid: Positioned just behind the phosphor-coated screen is a shadow mask
grid. This grid contains a series of precisely aligned holes that correspond to the arrangement
of the phosphor dots.

4. Beam Focusing and Deflection: bThe electron beams from the three guns are deflected and
focused as a group onto the shadow mask. The purpose of the shadow mask is to ensure
that each electron beam passes through the corresponding hole and activates only its
designated color dot in the dot triangle.

5. Color Activation: When an electron beam passes through a hole in the shadow mask, it
excites the corresponding color phosphor dot in the dot triangle. Each dot emits light of its
specific color (red, green, or blue). The combination of these colors at each pixel position
produces various colors on the screen.

6. Color Mixing: By adjusting the intensity of each of the three electron beams, the CRT can
produce a wide spectrum of colors. The color seen on the screen results from the additive
mixing of the red, green, and blue light emitted by the activated phosphor dots.

Q4 . Raster Scan Displays vs Random Scan Displays ALSO Briefly explain the
characteristics of raster scan displays method.
Ans: Characteristics of Raster-Scan Displays
1. Scanning Method: In raster-scan displays, the electron beam sweeps across the screen one
row at a time from top to bottom. This process is known as scanning or refreshing.

2. Pattern Creation: As the beam moves across each row, its intensity is modulated to create a
pattern of illuminated spots. This pattern forms the displayed image on the screen.

3. Frame Rate: The scanning process is repeated continuously, with each complete scan of the
screen called a frame. The rate at which these frames are refreshed is known as the frame
rate, typically ranging from 60 to 80 frames per second (60 Hz to 80 Hz).
Join Whatsapp Channel: https://whatsapp.com/channel/0029VaA9uVVIiRp0RS5li20r

4. Frame Buffer: Picture definition is stored in a memory area called the frame buffer. This
buffer holds the intensity values for all screen points, with each point referred to as a pixel
(picture element).

5. Aspect Ratio: The aspect ratio of a raster-scan display is defined as the number of pixel
columns divided by the number of scan lines that can be displayed by the system.

6. Bitmap vs. Pixmap:


1. Black and White Systems: The frame buffer is called a bitmap, where each entry is a 1-
bit value indicating the on (1) or off (0) state of each pixel's intensity.
2. Color Systems: The frame buffer is referred to as a pixmap. Each pixel entry in the
pixmap uses multiple bits to represent color. For true color displays, each pixel entry
typically uses 24 bits (8 bits for each of the red, green, and blue color channels).

These characteristics define how raster-scan displays generate and refresh images on the screen,
enabling the visualization of both monochrome and color graphics.

Characteristics of Random-Scan Displays


1. Selective Beam Direction: In a random-scan display, the electron beam is directed only to
specific parts of the screen where the picture is to be displayed. The beam traces out the
lines of the picture rather than sweeping across the entire screen.

2. Line Drawing: Pictures are created as line drawings. The electron beam follows the
component lines of the image one by one, making random-scan displays also known as
vector displays, stroke-writing displays, or calligraphic displays.

3. Order of Drawing: The component lines can be drawn and refreshed in any specified order,
allowing for flexible image rendering.

4. Pen Plotter Similarity: A pen plotter operates similarly to a random-scan display by drawing
lines on paper, making it a hard-copy example of this display technology.

5. Refresh Rate: The refresh rate in a random-scan system depends on the number of lines to
be displayed. Random-scan displays typically refresh all lines 30 to 60 times per second and
can handle up to 100,000 short lines in the display list.

6. Display List: Picture definition is stored as a set of line-drawing commands in memory,


known as the display list, refresh display file, vector file, or display program. The system
cycles through these commands to draw each line in turn.
Join Whatsapp Channel: https://whatsapp.com/channel/0029VaA9uVVIiRp0RS5li20r

7. Refresh Cycle Management: After processing all line-drawing commands, the system cycles
back to the first command in the list. When a small number of lines is to be displayed,
refresh cycles may be delayed to prevent excessively high refresh rates that could damage
the phosphor.

These characteristics define how random-scan displays render and refresh images, focusing on
drawing and updating lines rather than the entire screen.

Q5. Explain the Architecture of a raster-graphics system with a display processor.


Ans :

• Figure shows one way to organize the components of a raster system that contains a
separate display processor, sometimes referred to as a graphics controller or a display
coprocessor.
• The purpose of the display processor is to free the CPU from the graphics chores.
• In addition to the system memory, a separate display-processor memory area can be
provided.

Scan conversion:
A major task of the display processor is digitizing a picture definition given in an
application program into a set of pixel values for storage in the frame buffer.
This digitization process is called scan conversion.

Example 1: displaying a line


➔ Graphics commands specifying straight lines and other geometric objects are scan
converted into a set of discrete points, corresponding to screen pixel positions.
➔ Scan converting a straight-line segment.

Example 2: displaying a character


➔ Characters can be defined with rectangular pixel grids
➔ The array size for character grids can vary from about 5 by 7 to 9 by 12 or more for
higher-quality displays.
➔ A character grid is displayed by superimposing the rectangular grid pattern into the frame
buffer at a specified coordinate position.
Join Whatsapp Channel: https://whatsapp.com/channel/0029VaA9uVVIiRp0RS5li20r

Using outline:
➔ For characters that are defined as outlines, the shapes are scan-converted into the frame
buffer by locating the pixel positions closest to the outline.

Additional operations of Display processors:


➔ Display processors are also designed to perform a number of additional operations.
➔ These functions include generating various line styles (dashed, dotted, or solid),
displaying color areas, and applying transformations to the objects in a scene.
➔ Display processors are typically designed to interface with interactive input devices, such
as a mouse.

Methods to reduce memory requirements in display processor:


➔ In an effort to reduce memory requirements in raster systems, methods have been
devised for organizing the frame buffer as a linked list and encoding the color information.
➔ One organization scheme is to store each scan line as a set of number pairs.
➔ Encoding methods can be useful in the digital storage and transmission of picture
information

i)Run-length encoding:
• The first number in each pair can be a reference to a color value, and the second
number can specify the number of adjacent pixels on the scan line that are to be
displayed in that color.
• This technique, called run-length encoding, can result in a considerable saving is
storage space if a picture is to be constructed mostly with long runs of a single color
each.
• A similar approach can be taken when pixel colors change linearly.

ii)Cell encoding:
• Another approach is to encode the raster as a set of rectangular areas (cell encoding).

Q6. Explain a) Colour CRT Monitors. b) Flat-Panel Displays.


Ans:
Colour CRT Monitors
❖ A CRT monitor displays color pictures by using a combination of phosphors that emit
different-colored light.
❖ It produces range of colors by combining the light emitted by different phosphors.
❖ There are two basic techniques for color display:
1. Beam-penetration technique
2. Shadow-mask techniqueExplain a) Colour CRT Monitors. b) Flat-Panel Displays.

1) Beam-penetration technique:
• This technique is used with random scan monitors.
• In this technique inside of CRT coated with two phosphor layers usually red and green.
Join Whatsapp Channel: https://whatsapp.com/channel/0029VaA9uVVIiRp0RS5li20r

• The outer layer of red and inner layer of green phosphor.


• The color depends on how far the electron beam penetrates into the phosphor layer.
• A beam of fast electron penetrates more and excites inner green layer while slow
eletronexcites outer red layer.
• At intermediate beam speed we can produce combination of red and green lights which
emit additional two colors orange and yellow.
• The beam acceleration voltage controls the speed of the electrons and hence color of
• pixel.

Disadvantages:
➢ It is a low cost technique to produce color in random scan monitors.
➢ It can display only four colors.
➢ Quality of picture is not good compared to other techniques.

2)Shadow-mask technique
• It produces wide range of colors as compared to beam-penetration technique.
• This technique is generally used in raster scan displays. Including color TV.
• In this technique CRT has three phosphor color dots at each pixel position.
• One dot for red, one for green and one for blue light. This is commonly known as Dot
triangle.
• Here in CRT there are three electron guns present, one for each color dot. And a shadow
mask grid just behind the phosphor coated screen.
• The shadow mask grid consists of series of holes aligned with the phosphor dot pattern.
• Three electron beams are deflected and focused as a group onto the shadow mask and
when they pass through a hole they excite a dot triangle.
• In dot triangle three phosphor dots are arranged so that each electron beam can activate
only its corresponding color dot when it passes through the shadow mask.
• A dot triangle when activated appears as a small dot on the screen which has color of
combination of three small dots in the dot triangle.
• By changing the intensity of the three electron beams we can obtain different colors in
the shadow mask CRT.

Flat Panel Display


➔ The term flat panel display refers to a class of video device that have reduced volume,
weight & power requirement compared to a CRT.
➔ As flat panel display is thinner than CRTs, we can hang them on walls or wear on our
wrists.
➔ Since we can even write on some flat panel displays they will soon be available as pocket
notepads.
➔ We can separate flat panel display in two categories:

1. Emissive displays: - the emissive display or emitters are devices that convert
electrical energy into light. For Ex. Plasma panel, thin film electroluminescent
displays and light emitting diodes.

2. Non emissive displays: - non emissive display or non emitters use optical
effects to convert sunlight or light from some other source into graphics patterns.
For Ex. LCD (Liquid Crystal Display).

a) Plasma Panels displays


• This is also called gas discharge displays.
• It is constructed by filling the region between two glass plates with a mixture of gases that
usually includes neon.
Join Whatsapp Channel: https://whatsapp.com/channel/0029VaA9uVVIiRp0RS5li20r

• A series of vertical conducting ribbons is placed on one glass panel and a set of horizontal
ribbon is built into the other glass panel.
• Firing voltage is applied to a pair of horizontal and vertical conductors cause the gas at the
intersection of the two conductors to break down into glowing plasma of electrons and ions.
• Picture definition is stored in a refresh buffer and the firing voltages are applied to refresh
the pixel positions, 60 times per second.
• Alternating current methods are used to provide faster application of firing voltages and thus
brighter displays.
• Separation between pixels is provided by the electric field of conductor.
• One disadvantage of plasma panels is they were strictly monochromatic device that means
shows only one color other than black like black and white.

b.Thin Film Electroluminescent Displays


• It is similar to plasma panel display but region between the glass plates is filled with
phosphors such as doped with magnesium instead of gas.
• When sufficient voltage is applied the phosphors becomes a conductor in area of
intersection of the two electrodes.
• Electrical energy is then absorbed by the manganese atoms which then release the energy as
a spot of light similar to the glowing plasma effect in plasma panel.
• It requires more power than plasma panel.
• In this good color and gray scale difficult to achieve.

c. Light Emitting Diode (LED)


• In this display a matrix of multi-color light emitting diode is arranged to form the pixel
position in the display and the picture definition is stored in refresh buffer.
• Similar to scan line refreshing of CRT information is read from the refresh buffer and
converted to voltage levels that are applied to the diodes to produce the light pattern on the
display.

d)Liquid Crystal Display (LCD)


• This non emissive device produce picture by passing polarized light from the surrounding
or from an internal light source through liquid crystal material that can be aligned to either
block or transmit the light.
• The liquid crystal refreshes to fact that these compounds have crystalline arrangement of
molecules then also flows like liquid.
• It consists of two glass plates each with light polarizer at right angles to each other sandwich
the liquid crystal material between the plates.
• Rows of horizontal transparent conductors are built into one glass plate, and column of
vertical conductors are put into the other plates.
• The intersection of two conductors defines a pixel position.
• In the ON state polarized light passing through material is twisted so that it will pass through
the opposite polarizer.
• In the OFF state it will reflect back towards source.

Q7. Define the Following Terms


Ans:
1. Bitmap:
Definition: In computer graphics, a bitmap is a type of frame buffer used for black and white
or monochrome images. Each pixel's intensity is represented by a single bit of data (1 for on,
0 for off). This 1-bit data determines whether a pixel is illuminated or not.

2. Pixmap:
Definition: A pixmap is similar to a bitmap but is used for color images. It stores the color
values for each pixel, with each entry using multiple bits to represent color. For true color
Join Whatsapp Channel: https://whatsapp.com/channel/0029VaA9uVVIiRp0RS5li20r

displays, a pixmap typically uses 24 bits per pixel (8 bits for each of the red, green, and blue
color channels).

3. Aspect Ratio:
Definition: The aspect ratio of a display refers to the ratio of the number of pixel columns to
the number of scan lines (rows) that can be displayed. It defines the proportional relationship
between the width and height of the display area.

4. Frame Buffer:
Definition: The frame buffer is a memory area where the image data for display is stored. It
holds the intensity values or color information for each pixel on the screen. This data is used
to refresh and display the image on the monitor.

5. Resolution:
Definition: Resolution refers to the number of distinct pixels displayed on the screen,
typically described as the width by the height (e.g., 1920x1080). It determines the clarity and
detail of the image shown.

6. Pixel:
Definition: A pixel, short for "picture element," is the smallest unit of a digital image or
display. Each pixel represents a single point of color or intensity in the image and is the
fundamental building block of a raster image.

Q8. Explain DDA line drawing algorithm with procedure.


Ans: The Digital Differential Analyzer (DDA) line drawing algorithm is used for rasterizing lines in
computer graphics. It calculates pixel positions along a line by using incremental steps, which makes
it efficient for line rendering.
Procedure
1. Initialization:
• Determine the differences in the x and y coordinates of the line endpoints:
• dx=xEnd−x0
• dy=yEnd−y0
• Calculate the number of steps required to generate the line. This is based on the
greater of the absolute values of dx and dy:
• steps=max(∣dx∣,∣dy∣)
• Compute the increments for each step:
• xIncrement = stepsdx
• yIncrement = stepsdy
2. Drawing the Line:
• Start at the initial point (x0,y0).
• For each step:
• Set the pixel at (round(x),round(y)) to the desired color.
• Update the x and y coordinates:
• x=x+xIncrement
• y=y+yIncrement
3. Handling Different Slopes:
• Case 1: ∣m∣<1 (Steep lines where x changes more rapidly than y):
• Increment x by 1 unit each step.
• Compute the corresponding y value using yk+1=yk+m, where m=dx/dy.
Join Whatsapp Channel: https://whatsapp.com/channel/0029VaA9uVVIiRp0RS5li20r

• Case 2: ∣m∣>1 (Shallow lines where y changes more rapidly than x):
• Increment y by 1 unit each step.
• Compute the corresponding x value using xk+1=xk+m1, where m=dy/dx.
• Case 3: m=1 (Diagonal lines):
• Increment both x and y by 1 unit each step.
4. Implementation Notes:
• If the line's starting point is at the right of the ending point or if the line has a
negative slope, adjust the increments accordingly:
• For ∣m∣<1 with a right-starting endpoint: x decreases and y updates using
yk+1=yk−m.
• For ∣m∣>1 with a right-starting endpoint: y decreases and x updates using
xk+1=xk−m1.
5. Algorithm Efficiency:
• The DDA algorithm is efficient as it avoids multiplication and uses only addition and
rounding operations to determine pixel positions. This makes it faster compared to
algorithms that involve direct multiplication for each pixel calculation.
Sample Code:
#include <stdlib.h>
#include <math.h>

inline int round(const float a) {


return int(a + 0.5);
}

void lineDDA(int x0, int y0, int xEnd, int yEnd) {


int dx = xEnd - x0, dy = yEnd - y0, steps, k;
float xIncrement, yIncrement, x = x0, y = y0;

if (fabs(dx) > fabs(dy))


steps = fabs(dx);
else
steps = fabs(dy);

xIncrement = float(dx) / float(steps);


yIncrement = float(dy) / float(steps);

setPixel(round(x), round(y));
for (k = 0; k < steps; k++) {
x += xIncrement;
y += yIncrement;
setPixel(round(x), round(y));
}
}

In this code, setPixel(x, y) is a placeholder function that would be replaced with actual code to
draw a pixel on the screen.
The DDA algorithm is a fundamental method in computer graphics for drawing lines and is valued
for its simplicity and efficiency.

Q9. Explain Bresenham’s Line drawing algorithm, with an example.


Ans: Bresenham’s Line Drawing Algorithm is an efficient raster scan-line generation method used to
plot lines on a grid or screen. It uses incremental integral calculations to determine which pixels
should be illuminated to approximate a straight line.
Algorithm for Lines with |m| < 1.0
1. Initialization:
Join Whatsapp Channel: https://whatsapp.com/channel/0029VaA9uVVIiRp0RS5li20r

• Input: Two endpoints of the line, (x0,y0) and (xEnd,yEnd).


• Store: The left endpoint as the starting point (x0,y0).
• Plot: Set the pixel at (x0,y0) in the frame buffer.
2. Calculate Constants:
• Compute the differences Δx and Δy:
• Δx=xEnd−x0
• Δy=yEnd−y0
• Determine the initial decision parameter p0:
• p0=2Δy−Δx
• Compute the increments for the decision parameter:
• 2Δy
• 2Δy−2Δx
3. Iterative Plotting:
• Start from (x0,y0) and iterate for each x-coordinate until x reaches xEnd:
• If pk<0: Plot the next point at (xk+1,yk) and update pk+1 as:
• pk+1=pk+2Δy
• Otherwise: Plot the next point at (xk+1,yk+1) and update pk+1 as:
• pk+1=pk+2Δy−2Δx
4. Repeat: Continue this process until the endpoint (xEnd,yEnd) is reached.

Algorithm for Lines with |m| > 1.0


For lines with a slope greater than 1 (i.e., steep lines), the algorithm is adjusted as follows:

1. Calculate Constants:
• Determine the initial decision parameter p0:
• p0=2Δx−Δy
• Compute the increments for the decision parameter:
• 2Δx
• 2Δx−2Δy
2. Iterative Plotting:
• Start from (x0,y0) and iterate for each y-coordinate until y reaches yEnd:
• If pk<0: Plot the next point at (xk,yk+1) and update pk+1 as:
• pk+1=pk+2Δx
• Otherwise: Plot the next point at (xk+1,yk+1) and update pk+1 as:
• pk+1=pk+2Δx−2Δy

Example
Consider drawing a line from (2,2) to (8,5).

1. Initialization:
• Δx=8−2=6
• Δy=5−2=3
• Initial decision parameter: p0=2Δy−Δx=2×3−6=0
2. Plotting Points:
• Start at (2,2)
Join Whatsapp Channel: https://whatsapp.com/channel/0029VaA9uVVIiRp0RS5li20r

• For each x from 2 to 7 (since xEnd=8):


• At x=2:
• p=0, plot (2,2)
• Update: x=3, p=p+2Δy=0+6=6
• At x=3:
• p=6, plot (3,3) (since p≥0)
• Update: x=4, y=4, p=p+2Δy−2Δx=6+6−12=0
• At x=4:
• p=0, plot (4,4)
• Update: x=5, p=p+2Δy=0+6=6
• At x=5:
• p=6, plot (5,5) (since p≥0)
• Update: x=6, p=p+6−12=0
• At x=6:
• p=0, plot (6,5)
• Update: x=7, p=p+6=6
• At x=7:
• p=6, plot (7,5) (since p≥0)
• Update: x=8, y=6, p=p+6−12=0
• At x=8:
• Plot (8,5), endpoint of the line.

The algorithm efficiently determines pixel positions using integer arithmetic and avoids the need for
floating-point calculations, making it both fast and suitable for real-time applications.

Code:
#include <stdlib.h>
#include <math.h>
/* Bresenham line-drawing procedure for |m| < 1.0 */
void lineBres(int x0, int y0, int xEnd, int yEnd) {
int dx = abs(xEnd - x0); // Change in x
int dy = abs(yEnd - y0); // Change in y
int p = 2 * dy - dx; // Initial decision parameter
int twoDy = 2 * dy; // 2 * dy
int twoDyMinusDx = 2 * (dy - dx); // 2 * (dy - dx)
int x, y;

// Determine which endpoint to use as start position


if (x0 > xEnd) {
x = xEnd;
y = yEnd;
xEnd = x0;
} else {
x = x0;
y = y0;
}
setPixel(x, y); // Plot the starting point
while (x < xEnd) {
x++;
if (p < 0) {
p += twoDy;
} else {
y++;
p += twoDyMinusDx;
}
setPixel(x, y); // Plot the current point
}
Join Whatsapp Channel: https://whatsapp.com/channel/0029VaA9uVVIiRp0RS5li20r

Q10. Describe the basic structure of an OpenGL graphics program with the necessary
OpenGL functions. OR Explain the operations for displaying a picture using GLUT.
Ans : The basic structure of an OpenGL graphics program using the provided context involves
setting up the OpenGL environment, defining the graphics to be displayed, and managing the display
window. Here’s a step-by-step breakdown of how to structure an OpenGL program using the
OpenGL Utility Toolkit (GLUT) for window management:

1. Include Necessary Header Files


You need to include the appropriate header files for OpenGL and GLUT to use their functions:
#include <GL/glut.h>

2. Initialization Function
Create an initialization function to set up your OpenGL environment. This typically includes setting
the background color and specifying the projection parameters:
void init(void) {
glClearColor(1.0, 1.0, 1.0, 0.0); // Set background color to white.
glMatrixMode(GL_PROJECTION); // Set the projection matrix mode.
gluOrtho2D(0.0, 200.0, 0.0, 150.0); // Set the 2D orthogonal projection.
}

3. Display Function
Define a display function to specify what to draw. This function is called by GLUT to render the
graphics:
void lineSegment(void) {
glClear(GL_COLOR_BUFFER_BIT); // Clear the display window.
glColor3f(0.0, 0.4, 0.2); // Set the drawing color to dark green.

glBegin(GL_LINES); // Start drawing lines.


glVertex2i(180, 15); // Define the first endpoint of the line.
glVertex2i(10, 145); // Define the second endpoint of the line.
glEnd(); // End the line drawing.

glFlush(); // Ensure all OpenGL commands are executed.


}

4. Main Function
The main function initializes GLUT, sets up the display window, and enters the GLUT main loop:
int main(int argc, char** argv) {
glutInit(&argc, argv); // Initialize GLUT.
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); // Set display mode to single buffer
and RGB color.
glutInitWindowPosition(50, 100); // Set the position of the window.
glutInitWindowSize(400, 300); // Set the size of the window.
glutCreateWindow("An Example OpenGL Program"); // Create a window with a title.

init(); // Call the initialization function.


glutDisplayFunc(lineSegment); // Register the display function.
glutMainLoop(); // Enter the GLUT main loop.

return 0; // Program should not reach here.


}
Join Whatsapp Channel: https://whatsapp.com/channel/0029VaA9uVVIiRp0RS5li20r

Summary
1. Include Headers: Use #include <GL/glut.h> to access OpenGL and GLUT functions.
2. Initialization (init Function): Set up background color and projection parameters.
3. Display (lineSegment Function): Clear the screen, set colors, draw graphics, and flush the
drawing commands.
4. Main Function: Initialize GLUT, set display mode, configure window size and position, create
the window, and enter the GLUT event loop.

This basic structure sets up a simple OpenGL program that opens a window, draws a line segment,
and maintains the display.

#include <GL/glut.h> // Include the GLUT header for OpenGL functions

// Initialization function
void init(void) {
glClearColor(1.0, 1.0, 1.0, 0.0); // Set the background color to white
glMatrixMode(GL_PROJECTION); // Set the matrix mode to projection
gluOrtho2D(0.0, 200.0, 0.0, 150.0); // Define the 2D orthographic projection
}

// Display function
void lineSegment(void) {
glClear(GL_COLOR_BUFFER_BIT); // Clear the display window
glColor3f(0.0, 0.4, 0.2); // Set the drawing color to dark green

glBegin(GL_LINES); // Start drawing lines


glVertex2i(180, 15); // Specify the first endpoint of the line
glVertex2i(10, 145); // Specify the second endpoint of the line
glEnd(); // End the line drawing

glFlush(); // Flush the OpenGL commands to the display


}

// Main function
int main(int argc, char** argv) {
glutInit(&argc, argv); // Initialize GLUT
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); // Set the display mode to
single buffer and RGB color
glutInitWindowPosition(50, 100); // Set the window position
on the screen
glutInitWindowSize(400, 300); // Set the window size
glutCreateWindow("An Example OpenGL Program"); // Create a window with a
title

init(); // Call the initialization


function
glutDisplayFunc(lineSegment); // Register the display
function with GLUT
glutMainLoop(); // Enter the GLUT event
processing loop

return 0; // Main function should not return, as GLUT takes over the
program's control flow
}

You might also like