Lab viva guide

Computer graphics viva questions and answers: 62 short answers for the CG lab, from DDA to curves and shading

25 min read Updated English

Computer graphics viva questions start from the program you ran: the examiner asks why your DDA line looks jagged, how Bresenham avoids floating point, or which region code your clipped line got, then moves to transformations, projections and curves. This page gives 62 computer graphics viva questions with short, exam-ready answers, grouped the way a CG lab runs (display basics, line and circle drawing, filling, 2D transformations, clipping, 3D and projections, hidden surfaces, curves, colour and shading, and OpenGL), plus a table of algorithms, the mistakes examiners catch and a plan for the night before.

How the examiner runs a computer graphics lab viva

A computer graphics lab is usually done in C or C++ with the graphics.h library under Turbo C or a WinBGIm port, or with OpenGL and GLUT. Typical experiments draw lines with DDA and Bresenham, circles and ellipses with the midpoint algorithm, fill polygons with boundary fill, flood fill and scan-line methods, apply 2D transformations, clip lines with Cohen-Sutherland and polygons with Sutherland-Hodgman, draw Bezier curves, and animate a simple scene or a 3D cube.

  • First, your output: 'why does your circle need only one octant computed?', 'what is the decision parameter here?'
  • Then a hand trace: three or four steps of Bresenham for given end points, or the region codes of a line.
  • Then the matrix: 'write the homogeneous matrix for rotation about an arbitrary point'.
  • Then a comparison: raster versus random scan, DDA versus Bresenham, parallel versus perspective projection.
  • Then the library: 'what does initgraph do?' or 'what is the role of glutMainLoop?'

Draw while you answer

Ask for paper and sketch the octant, the region code grid or the pixel steps as you speak. A small sketch with three correct numbers proves you understand the algorithm faster than any definition.

Display basics

What is computer graphics?

Computer graphics is the creation, storage and manipulation of pictures and models of objects using a computer. It covers drawing primitives such as lines and polygons, transforming and viewing them, removing hidden parts and rendering them with colour and shading, for uses ranging from CAD and games to medical imaging.

What is a pixel, and what is resolution?

A pixel, or picture element, is the smallest addressable point on a raster display. Resolution is the number of pixels in each direction, such as 1920 by 1080, or in printing, the number of dots per inch. Higher resolution shows finer detail but needs more memory and processing.

What is a frame buffer?

The frame buffer is the memory that stores the colour value of every pixel on the screen. The display controller reads it repeatedly to refresh the screen. Its size is the resolution multiplied by the bits per pixel; for 1024 by 768 at 24 bits per pixel that is about 2.25 megabytes.

What is the difference between raster scan and random scan displays?

A raster scan display sweeps the electron beam, or refreshes pixels, row by row across the whole screen and draws from a frame buffer, so it handles filled areas and realistic images. A random scan, or vector, display moves the beam only along the lines to be drawn from a display list, giving smooth lines but poor filled areas.

What is refresh rate, and what is interlacing?

Refresh rate is how many times per second the whole screen is redrawn, in hertz; below about 50 to 60 Hz the eye sees flicker on a CRT. Interlacing draws odd lines in one pass and even lines in the next, so each pass draws half the lines and flicker is reduced at a lower bandwidth.

How does a CRT work?

An electron gun emits a beam that is focused and deflected by electric or magnetic fields onto a phosphor-coated screen; the phosphor glows where the beam strikes. Because the glow fades quickly, the picture must be refreshed many times a second. Colour CRTs use three guns for red, green and blue phosphor dots with a shadow mask.

What is aspect ratio?

Aspect ratio is the ratio of the width to the height of a display or image, such as 4 to 3 or 16 to 9. In graphics it also refers to the ratio of vertical to horizontal points needed for lines of equal length; if it is not handled, a circle drawn with equal radii looks like an ellipse.

What is the difference between raster images and vector images?

A raster image stores a grid of pixel colours, like a photograph in JPEG or PNG, so enlarging it shows blocky pixels. A vector image stores shapes as geometric descriptions such as lines, curves and fills, like an SVG drawing, so it can be scaled to any size without losing sharpness. Displays finally rasterise vector images to show them.

What is a colour look-up table?

With a look-up table, each frame buffer entry holds an index rather than a full colour, and the index selects a full colour value from a small table. With 8 bits per pixel, 256 colours can be shown at once, chosen from millions. Changing a table entry recolours every pixel using it instantly, which was used for simple animation.

What is persistence of a phosphor?

Persistence is the time the phosphor keeps glowing after the electron beam has moved on, usually measured as the time for the light to fall to one-tenth of its initial intensity. Low persistence needs a high refresh rate to avoid flicker but suits animation; high persistence suits static, complex pictures.

Line, circle and ellipse drawing

Explain the DDA line drawing algorithm.

The digital differential analyser computes dx and dy, takes steps equal to the larger of their absolute values, and increments x and y by dx divided by steps and dy divided by steps at each step, rounding to the nearest pixel. It is simple but uses floating-point addition and rounding at every step.

What are the drawbacks of DDA?

It uses floating-point arithmetic, which was slow on older hardware, and the rounding at each step takes time. Accumulated round-off error in the increments can make long lines drift away from the true path. Bresenham's algorithm removes both problems by using only integers.

Explain Bresenham's line algorithm.

For a line with slope between 0 and 1, x increases by one each step, and an integer decision parameter decides whether y stays or increases by one. It starts at p0 equals 2dy minus dx. If p is negative, plot the same y and add 2dy; otherwise increase y and add 2dy minus 2dx. Only integer additions and comparisons are used.

Trace Bresenham from 20, 10 to 30, 18.

Here dx is 10 and dy is 8, so p0 is 6, 2dy is 16 and 2dy minus 2dx is minus 4. Since p0 is positive, the next pixel is 21, 11 and p becomes 2. Still positive, so 22, 12 and p becomes minus 2. Now negative, so 23, 12 and p becomes 14. The steps continue the same way to 30, 18.

How do you handle Bresenham for other slopes?

For a slope greater than 1, swap the roles of x and y, so y increases by one each step and the decision chooses x. For negative slopes, one coordinate is decremented instead of incremented. Using the symmetry of the eight octants, one routine covers every line.

What is eight-way symmetry of a circle?

A circle centred at the origin is symmetric about both axes and both diagonals, so a point x, y gives seven more: y, x and the sign combinations of both. We compute points only in one octant, from 90 to 45 degrees, and plot all eight, which cuts the work to one-eighth.

Explain the midpoint circle algorithm.

Starting at 0, r, x increases by one each step in the first octant. The decision parameter tests whether the midpoint between the two candidate pixels lies inside or outside the circle. It starts at 1 minus r. If p is negative, y stays and p increases by 2x plus 1; otherwise y decreases and p increases by 2x plus 1 minus 2y, using the updated x and y. It stops when x reaches y.

How does the midpoint ellipse algorithm differ from the circle algorithm?

An ellipse has only four-way symmetry, so one quadrant is computed. The quadrant is split into two regions at the point where the slope is minus 1. In region 1, x is the unit step; in region 2, y is. Each region has its own decision parameter.

Why are integer algorithms preferred for scan conversion?

Integer addition and comparison are faster and exact, while floating-point arithmetic is slower and accumulates rounding error. Since a frame may need millions of pixels, Bresenham and midpoint methods, which need only incremental integer updates, were essential and are still the basis of hardware rasterisers.

Why does DDA take the number of steps as the larger of the absolute values of dx and dy?

So that the coordinate along the major axis changes by exactly one pixel per step and the other changes by less than one. If the smaller value were used, the major coordinate would jump by more than one pixel each step and the line would show gaps.

Polygon filling

What is the boundary fill algorithm?

Starting from a seed pixel inside a region, boundary fill colours the pixel and recursively visits its neighbours until it meets pixels of the boundary colour. It needs the boundary to be drawn in one colour. It is simple, but the recursion uses a lot of stack for large areas.

How is flood fill different from boundary fill?

Flood fill replaces every connected pixel that has a specified interior colour, regardless of the boundary colour, so it suits regions bounded by several colours. Boundary fill stops at a single boundary colour. Both start from a seed and can use 4-connected or 8-connected neighbours.

What is the difference between 4-connected and 8-connected filling?

4-connected filling visits the left, right, top and bottom neighbours; 8-connected also visits the four diagonal neighbours. 8-connected filling can leak through a boundary drawn with diagonal steps, while 4-connected may fail to fill regions joined only at a corner.

Explain the scan-line polygon fill algorithm.

For each scan line, find where it intersects the polygon edges, sort the x intersections, and fill pixels between pairs of intersections: first to second, third to fourth and so on. An edge table and an active edge list keep the work incremental. Vertices need care so that an intersection is counted once or twice correctly.

How do you test whether a point is inside a polygon?

With the odd-even rule, draw a ray from the point in any direction and count edge crossings; an odd count means inside. With the non-zero winding rule, count edges crossing the ray with a direction, plus one for one way and minus one for the other; a non-zero total means inside. They differ for self-intersecting polygons.

Why can recursive flood fill crash, and how is it improved?

Each pixel visited adds a recursive call, so a large region can need hundreds of thousands of nested calls and overflow the stack, especially in Turbo C's small memory model. Using an explicit stack or queue avoids this, and the scan-line seed fill pushes only one seed per horizontal span, filling whole runs at a time.

2D transformations

What are the basic 2D transformations?

Translation moves an object by tx and ty. Rotation turns it by an angle about the origin. Scaling changes its size by sx and sy relative to the origin. Reflection mirrors it about an axis or line, and shear slants it so that one coordinate changes in proportion to the other.

Why are homogeneous coordinates used?

In ordinary 2D coordinates translation is an addition while rotation and scaling are multiplications, so a sequence cannot be combined into one matrix. Writing a point as x, y, 1 makes every transformation a 3 by 3 matrix multiplication, so any sequence becomes a single composite matrix.

Write the rotation matrix for an angle theta about the origin.

In homogeneous form the first row is cos theta, minus sin theta, 0; the second is sin theta, cos theta, 0; and the third is 0, 0, 1, with points as column vectors. So x-prime equals x cos theta minus y sin theta, and y-prime equals x sin theta plus y cos theta. A positive angle rotates anticlockwise.

How do you rotate an object about an arbitrary point?

Translate the object so that the pivot point moves to the origin, rotate about the origin, then translate back. The composite matrix is T of xp, yp multiplied by R of theta multiplied by T of minus xp, minus yp, applied to the points from right to left. Scaling about a fixed point uses the same three steps.

Is matrix multiplication of transformations commutative?

In general no. Rotating and then translating gives a different result from translating and then rotating, so the order of composite matrices matters. Some pairs do commute: two translations, two rotations about the same point, or two scalings, and rotation with uniform scaling.

What are reflection and shear? Give matrices in words.

Reflection about the x-axis keeps x and negates y, a matrix with 1 and minus 1 on the diagonal. Reflection about the line y equals x swaps x and y. An x-direction shear with factor shx gives x-prime equals x plus shx times y, leaving y unchanged, so a square becomes a parallelogram.

What is the window-to-viewport transformation?

The window is the area of the world selected for display, and the viewport is the area of the screen where it appears. The mapping scales by the ratio of viewport size to window size in each direction and translates, so a point keeps the same relative position. Different scale factors in x and y distort the shape.

How do you reflect an object about an arbitrary line y equals mx plus c?

Translate so the line passes through the origin by moving it down by c, rotate by minus theta, where tan theta is m, so the line lies on the x-axis, reflect about the x-axis, then rotate back by theta and translate back by c. The five matrices multiplied in that order give one composite matrix.

What is the inverse of a transformation?

The inverse undoes the transformation. The inverse of translation by tx, ty is translation by minus tx, minus ty; of rotation by theta, rotation by minus theta, which is the transpose of the rotation matrix; and of scaling by sx, sy, scaling by 1 by sx and 1 by sy. For a composite, the inverses are applied in reverse order.

Clipping

What is clipping?

Clipping removes the parts of a picture that lie outside a specified region, usually the rectangular window, so that only the visible part is drawn. Point, line, polygon, curve and text clipping each have their own algorithms.

Explain the Cohen-Sutherland line clipping algorithm.

Each end point gets a 4-bit region code for above, below, right and left of the window. If both codes are 0000, the line is accepted. If the logical AND of the codes is not zero, both points lie on the same outside side and the line is rejected. Otherwise, the line is intersected with a window edge and the test repeats.

How is the region code set in Cohen-Sutherland?

With the usual bit order top, bottom, right, left: the top bit is 1 if y is greater than ymax, the bottom bit if y is less than ymin, the right bit if x is greater than xmax, and the left bit if x is less than xmin. A point above and to the left of the window gets 1001.

What is the advantage of Liang-Barsky over Cohen-Sutherland?

Liang-Barsky uses the parametric form of the line and computes, from four inequalities, the parameter values where the line enters and leaves the window. It finds the clipped segment directly without repeated intersection calculations, so it usually needs fewer operations than Cohen-Sutherland.

Explain the Sutherland-Hodgman polygon clipping algorithm.

It clips the polygon against each window edge in turn, left, right, bottom and top, passing the output vertex list of one stage to the next. For each polygon edge there are four cases: both vertices inside, output the second; inside to outside, output the intersection; both outside, output nothing; outside to inside, output the intersection and the second vertex.

What is the limitation of Sutherland-Hodgman, and what handles it?

It works correctly for convex clipping windows. With a concave polygon it can produce extra connecting edges along the window boundary where the result should be separate pieces. The Weiler-Atherton algorithm traces around the polygon and window boundaries and handles concave polygons and clipping windows properly.

How is text clipped?

There are three strategies. All-or-none string clipping keeps a whole string only if it lies fully inside the window. All-or-none character clipping keeps each character that is fully inside and drops the rest. Clipping individual character components treats each character's lines or pixels like any other primitive and clips them exactly, which is the most precise and the slowest.

3D transformations, projections and hidden surfaces

How do 3D transformations differ from 2D?

Points become x, y, z, 1 in homogeneous form and matrices become 4 by 4. Translation and scaling extend directly. Rotation is about an axis rather than a point, so there are separate matrices for the x, y and z axes, and rotation about an arbitrary axis needs translating and aligning that axis with a coordinate axis first.

What is the difference between parallel and perspective projection?

In parallel projection the projectors are parallel, so parallel lines stay parallel and sizes are preserved, which suits engineering drawings. In perspective projection the projectors meet at a centre of projection, so distant objects look smaller and parallel lines converge at vanishing points, which looks realistic.

What are orthographic and oblique projections?

Both are parallel projections. In orthographic projection the projectors are perpendicular to the projection plane, giving front, top and side views, or isometric views when the plane is equally inclined to all three axes. In oblique projection the projectors are at an angle to the plane; cavalier and cabinet projections are common types.

What is a vanishing point?

In perspective projection, a set of parallel lines not parallel to the projection plane appears to meet at a point called the vanishing point. One-point, two-point and three-point perspective are named by how many principal axes cross the projection plane and so have vanishing points.

Explain the z-buffer, or depth buffer, algorithm.

Along with the frame buffer, keep a depth value for every pixel, initialised to the farthest depth. For each polygon, compute the depth at each pixel it covers; if it is nearer than the stored depth, write its colour and depth. It is simple, works for any order of polygons and is done in hardware, but needs extra memory.

What is back-face detection?

For a closed solid, faces whose outward normals point away from the viewer cannot be seen, so they are removed before rendering. A face is a back face when the dot product of its normal with the viewing direction shows it facing away. It removes about half the faces of a closed object cheaply but does not handle one object hiding another.

What is the painter's algorithm?

It sorts the surfaces by depth and draws them from the farthest to the nearest, so nearer surfaces paint over farther ones, like an artist painting a background first. Overlapping cyclic surfaces cannot be sorted directly and must be split. It is also called the depth-sort algorithm.

What is the 3D viewing pipeline?

Object coordinates are transformed by modelling transformations into world coordinates, then by the viewing transformation into viewing, or camera, coordinates. A projection maps them onto the view plane, they are normalised and clipped against the view volume, and finally the workstation transformation maps them to device, or screen, coordinates.

Curves, colour models, shading and OpenGL

What is a Bezier curve, and what are its properties?

A Bezier curve is a parametric curve defined by control points and the Bernstein polynomials. With n plus 1 control points the curve has degree n. It passes through the first and last control points, is tangent there to the first and last control polygon edges, and lies inside the convex hull of the control points. Moving one control point changes the whole curve.

How does a B-spline differ from a Bezier curve?

A B-spline is built from polynomial pieces joined smoothly, and its degree is set independently of the number of control points. Each control point affects only a few nearby pieces, giving local control, so long curves can be edited locally. A Bezier curve's degree rises with the number of control points and every point affects the whole curve.

What is the difference between interpolation and approximation curves?

An interpolating curve passes through all its control points, like a cubic spline through given data points. An approximating curve is only guided by the control points and need not pass through them, as Bezier curves do for interior points and B-splines generally do.

Explain the RGB and CMY colour models.

RGB is additive: red, green and blue light combine, with all three at full giving white, and it is used for displays. CMY is subtractive: cyan, magenta and yellow inks absorb light from white paper, with all three giving black in theory, so printers use it, adding black ink as CMYK. C equals 1 minus R, and similarly for M and Y.

What is the HSV colour model?

HSV describes colour as hue, the colour type measured as an angle around a hexcone; saturation, the purity of the colour; and value, the brightness. It matches how artists and users think about choosing colours, so colour pickers often use it and convert to RGB for display.

Compare flat, Gouraud and Phong shading.

Flat shading uses one intensity per polygon, so curved surfaces look faceted. Gouraud shading computes intensity at the vertices and interpolates it across the polygon, giving smooth shading but poorly shaped highlights. Phong shading interpolates the normals and computes lighting at every pixel, giving accurate specular highlights at more cost.

What is aliasing, and how is it reduced?

Aliasing is the distortion from sampling a continuous image at discrete pixels, seen as jagged staircase edges, called jaggies, on lines and moire patterns on fine detail. Antialiasing reduces it by supersampling, computing several samples per pixel and averaging, or by area sampling, which sets a pixel's intensity by how much of it the line covers.

What is OpenGL, and what does GLUT add?

OpenGL is a cross-platform API for 2D and 3D rendering that sends primitives, transformations and state to the graphics hardware; it does not handle windows or input. GLUT, the OpenGL Utility Toolkit, creates windows, handles keyboard and mouse callbacks and runs the event loop with glutMainLoop.

What do glBegin and glEnd do in your OpenGL program?

In the older fixed-function OpenGL that most labs use, glBegin with a mode such as GL_LINES, GL_POLYGON or GL_TRIANGLES starts a primitive, the glVertex calls between them give its vertices, and glEnd closes it. Modern core-profile OpenGL removed them in favour of vertex buffers and shaders.

What are the ambient, diffuse and specular terms in a basic illumination model?

Ambient light is a constant term that stands in for light scattered by the surroundings, so unlit sides are not black. Diffuse reflection follows Lambert's cosine law: intensity is proportional to the cosine of the angle between the surface normal and the light direction. Specular reflection gives shiny highlights; in the Phong model it falls off as a power of the cosine of the angle between the view direction and the reflection direction.

What is double buffering?

With double buffering the program draws the next frame into a back buffer while the front buffer is being displayed, then swaps the two. The viewer never sees a half-drawn frame, so animation does not flicker. In GLUT this means choosing GLUT_DOUBLE in the display mode and calling glutSwapBuffers after drawing.

What does initgraph do in a graphics.h program?

initgraph initialises the graphics system: it detects or sets the graphics driver and mode, loads the driver from the given path and switches the screen to graphics mode. After drawing with functions like putpixel, line and circle, closegraph frees the memory and returns to text mode.

Algorithms at a glance

AlgorithmTaskKey ideaViva hook
DDALine drawingFloating-point increments along the major axisRounding error on long lines
BresenhamLine drawingInteger decision parameterp0 equals 2dy minus dx
Midpoint circleCircle drawingMidpoint inside or outside test, one octantStarts at 1 minus r, eight-way symmetry
Midpoint ellipseEllipse drawingTwo regions split at slope minus 1Four-way symmetry only
Boundary fill and flood fillRegion fillingSeed pixel and neighbours4- versus 8-connected
Scan-line fillPolygon fillingPairs of edge intersections per scan lineActive edge list
Cohen-SutherlandLine clipping4-bit region codesTrivial accept and reject
Liang-BarskyLine clippingParametric entry and exit valuesFewer calculations
Sutherland-HodgmanPolygon clippingClip against one edge at a timeConvex windows
Z-bufferHidden surface removalPer-pixel depth comparisonExtra memory, any order
Painter's algorithmHidden surface removalDraw far to nearCyclic overlaps need splitting
BezierCurve designControl points and Bernstein polynomialsGlobal control, convex hull

Common mistakes in a computer graphics viva

  • Giving the wrong initial decision parameter: Bresenham line starts at 2dy minus dx, the midpoint circle at 1 minus r, often rounded from 5 by 4 minus r.
  • Saying a circle has four-way symmetry or an ellipse eight-way. It is the other way round.
  • Forgetting to translate back after rotating about an arbitrary point, or multiplying the matrices in the wrong order.
  • Saying a line with codes 1000 and 0010 can be trivially rejected. Their AND is 0000, so it needs clipping.
  • Mixing up boundary fill and flood fill conditions.
  • Saying Bezier curves pass through every control point.
  • Calling Gouraud shading per-pixel lighting. Gouraud interpolates intensities; Phong interpolates normals.

What the ExamPilot AI examiner checks when you practise

In a CS/IT lab viva session on ExamPilot you name your CG experiment, for example Bresenham's line, midpoint circle or Cohen-Sutherland clipping, and an AI examiner questions you by voice for about twelve minutes: the idea behind your program, a hand trace said aloud, a transformation matrix and a comparison. It follows up whenever an answer is vague, and you can answer in English or Hindi.

  • Initial values and update rules of decision parameters, said exactly.
  • Hand traces step by step: pixels chosen, region codes, clipped end points.
  • Matrix order in composite transformations, with the reason.
  • Comparisons with the deciding difference first: DDA versus Bresenham, parallel versus perspective, Gouraud versus Phong.
  • Brevity and honesty: two or three sentences, and a clean 'I am not sure' rather than a guess.

Start with the CS/IT lab viva mock. You get a transcript, the questions you fumbled and a tighter answer to say again.

The night before the computer graphics lab exam

  1. 1

    Run each program and change one input

    Draw a steep line, a line with negative slope and a circle with a different radius, and predict where each goes before running it.

  2. 2

    Trace three algorithms by hand

    Five steps of Bresenham, the first octant of a midpoint circle of radius 8, and Cohen-Sutherland for one line crossing two window edges.

  3. 3

    Write two composite matrices

    Rotation about a point and scaling about a fixed point, in homogeneous form, with the order of multiplication.

  4. 4

    Run one mock viva

    Twelve minutes with the AI examiner on your own experiment shows which answers come out clearly and which need work.

Most CG lab programs are written in C or C++, so revise C programming viva questions. Algorithm analysis questions overlap with DAA viva questions, and for how every lab viva works, see the engineering viva hub.

Frequently asked questions

What are the most important computer graphics viva questions?
Raster versus random scan, frame buffer and resolution, DDA versus Bresenham with the decision parameter, midpoint circle and eight-way symmetry, boundary fill versus flood fill, homogeneous coordinates and composite transformations, Cohen-Sutherland region codes, Sutherland-Hodgman, parallel versus perspective projection, z-buffer, Bezier curve properties, RGB versus CMY and the shading methods.
Is graphics.h or OpenGL used in the CG lab?
It depends on the university. Many older syllabi use graphics.h with Turbo C or a WinBGIm port, while newer ones use OpenGL with GLUT in C or C++. The algorithms are the same; be ready to explain the library calls you actually used, such as initgraph and putpixel, or glBegin, glVertex and glutMainLoop.
How do I explain Bresenham's algorithm quickly?
Say that for a gentle slope x always increases by one, and an integer decision parameter decides whether y also increases. Give the start value, 2dy minus dx, and the two updates, add 2dy if it is negative, otherwise add 2dy minus 2dx and step y. Then point out that only integer additions are used.
Are computer graphics questions asked in placement interviews?
Rarely for general software roles, but they come up for game development, visualisation, AR and VR, and graphics driver roles, where transformations, projections, the rendering pipeline and shading are core topics. For other roles, a CG project can still be a strong talking point if you can explain its algorithms clearly.
How can I practise computer graphics viva questions out loud?
On ExamPilot you can run a CS/IT lab viva by voice. Name your CG experiment and the AI examiner asks about the algorithm, makes you trace a few steps or build a composite matrix aloud and follows up like an external examiner, then gives you a transcript to review. It is free to start.

Practise out loud

Practise your CG lab viva out loud

The AI examiner asks about your CG program, makes you trace Bresenham or region codes aloud and builds up to matrices and projections, like an external examiner.

Engineering Viva · CS / IT lab viva

Read how this interview works

Official sources