Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 66

COMPUTER GRAPHICS

 OVERVIEW OF GRAPHICS SYSTEMS


 GRAPHICS OUTPUT PRIMITIVES
 GEOMETRICAL TRANSFORMATIONS
 TWO DIMENSIONAL VIEWING
 THREE DIMENSIONAL VIEWING
 PARAMETRIC CURVES
 VISIBLE SURFACE DETECTION METHODS
 ILLUMINATION MODELS
 COMPUTER ANIMATION
07/11/24 09:48 AM Narendra V G CSE MIT 1
Text Book:
1. Donald Hearn, Pauline Baker M., “Computer Graphics with
OpenGL”, Pearson Education, 3rd Edition, (2010)
References:
1.Edward Angel, “Interactive Computer Graphics- A top down
approach using OpenGL”, Pearson Education, 5th Edition.
2.Foley J. D., VanDam A., Feiner S. K., Hughes J. F., “Computer
Graphics, Principles and Practice” , Addision-Wesley, 2nd Edition.
3.Malay Pakhira K., “Computer Graphics Multimedia and
Animation”, PHI Learning, . 2nd Edition.
4.Amarendra Sinha N., Arun Udai D., “Computer Graphics”, Tata
McGraw Hill publishing.
5.Er. Rajiv Chopra “Computer Graphics”, S. Chand &
Company Ltd. 2nd Edition.
07/11/24 09:48 AM Narendra V G CSE MIT 2
Computer Graphics Applications

07/11/24 09:48 AM Narendra V G CSE MIT 3


Computer Graphics is about animation (films)

Major driving force now

07/11/24 09:48 AM Narendra V G CSE MIT 4


Games are very important in Computer Graphics

07/11/24 09:48 AM Narendra V G CSE MIT 5


Medical Imaging is another driving force

Much financial support


Promotes linking of graphics with video, scans, etc.

07/11/24 09:48 AM Narendra V G CSE MIT 6


Computer Aided Design too

07/11/24 09:48 AM Narendra V G CSE MIT 7


Scientific Visualisation
To view below and
above our visual range

07/11/24 09:48 AM Narendra V G CSE MIT 8


Graphics Pipelines
• Graphics processes generally execute sequentially
• Typical ‘pipeline’ model
• There are two ‘graphics’ pipelines
– The Geometry or 3D pipeline
– The Imaging or 2D pipeline

07/11/24 09:48 AM Narendra V G CSE MIT 9


Computer Graphics ?

07/11/24 09:48 AM Narendra V G CSE MIT 10


Computer Graphics
• Computer graphics deals with all aspects of
creating images with a computer
– Hardware
– Software
– Applications

07/11/24 09:48 AM Narendra V G CSE MIT 11


Example
• Where did this image come from?

• What hardware/software did we need to


produce it?
07/11/24 09:48 AM Narendra V G CSE MIT 12
Preliminary Answer
• Application: The object is an artist’s
rendition of the sun for an animation to be
shown in a domed environment
(planetarium)
• Software: Maya for modeling and rendering
but Maya is built on top of OpenGL
• Hardware: PC with graphics card for
modeling and rendering

07/11/24 09:48 AM Narendra V G CSE MIT 13


Hardware
• Primitive Output Devices
• Primitive Input Devices

07/11/24 09:48 AM Narendra V G CSE MIT 14


Basic Graphics System

Output device

Input devices
Image formed in FB

07/11/24 09:48 AM Narendra V G CSE MIT 15


Hardware
Primitive Output Devices

07/11/24 09:48 AM Narendra V G CSE MIT 16


Cathode Ray Tube(CRT)

There are two ways (Random scan and Raster scan)


by which we can display an object on the screen.
Srinu CSE VITS
17
Raster scan Display

The electron beam is swept across the screen, one row at a time from
top to bottom. As the electron beam moves across each row, the
beam intensity is turned on and off to create a pattern of illuminated
spots.

Srinu CSE VITS


18
Raster scan Display(cont..)
• Picture definition is stored in memory area called
the Refresh Buffer or Frame Buffer.
• This memory area holds the set of intensity values for all
the screen points.
• Stored intensity values are then retrieved from the
refresh buffer and “painted” on the screen one row (scan
line) at a time as shown in the figure.
• Each screen point is referred to as a pixel (picture
element) or pel.

Srinu CSE VITS


19
Random Scan (Vector Scan)
• The electron beam is directed only to the part of the screen where
the picture is to be drawn rather than scanning from left to right and
top to bottom as in raster scan.
• It is also called vector display, stroke-writing display, or calligraphic
display.
• Picture definition is stored as a set of line-drawing commands in an
area of memory referred to as the refresh display file.
• To display a specified picture, the system cycles through the set of
commands in the display file, drawing each component line in turn.
• Random-scan displays are designed to draw all the component lines
of a picture 30 to 60 times each second.

Srinu CSE VITS


20
Random Scan (Vector Scan)

Srinu CSE VITS


21
Color CRT Monitors
A CRT monitor displays color pictures by using a combination
of phosphors that emit different-colored light.

By combining the emitted light from the different phosphors, a


range of colors can be generated

The two basic techniques for producing color displays with a


CRT are:

•Beam-penetration method and


•The shadow-mask method.

Srinu CSE VITS


22
Color CRT Monitors(cont..)
Beam-penetration method:
• Two layers of phosphor, usually red and green, are
coated onto the inside of the CRT screen, and
• The displayed color depends on how far the electron
beam penetrates into the phosphor layers.
• A beam of slow electrons excites only the outer red
layer.
• A beam of very fast electrons penetrates through the
red layer and excites the inner green layer.
Srinu CSE VITS
23
Color CRT Monitors(cont..)
Beam-penetration method:

• At intermediate beam speeds, combinations of


red and green light are emitted to show two
additional colors, orange and yellow

Advantages:
Inexpensive way to produce color in Random
Scan Monitors
disadvantages:
 only four colors are possible
 quality of picture is not as good as other methods
Srinu CSE VITS
24
Color CRT Monitors(cont..)
Shadow Mask method:
• Shadow-mask methods are commonly used in raster scan
systems (including color TV) because they produce a much
wider range of colors than the beam penetration method
• A shadow-mask CRT has three phosphor color dots at
each pixel position.
• One phosphor dot emits a red light, another emits a green
light, and the third emits a blue light.
• This type of CRT has three electron guns, one for each
color dot, and a shadow-mask grid just behind the
phosphor-coated screen.

Srinu CSE VITS


25
Computer Graphics: 1950-1960

• Computer graphics goes back to the earliest


days of computing
– Strip charts
– Pen plotters
– Simple displays using A/D converters to go from
computer to calligraphic CRT
• Cost of refresh for CRT too high
– Computers slow, expensive, unreliable

07/11/24 09:48 AM Narendra V G CSE MIT 26


Computer Graphics: 1960-1970
• Wireframe graphics
– Draw only lines
• Sketchpad
• Display Processors
• Storage tube

wireframe representation
of sun object

07/11/24 09:48 AM Narendra V G CSE MIT 27


Sketchpad
• Ivan Sutherland’s PhD thesis at MIT
– Recognized the potential of man-machine
interaction
– Loop
• Display something
• User moves light pen
• Computer generates new display
– Sutherland also created many of the now
common algorithms for computer graphics

07/11/24 09:48 AM Narendra V G CSE MIT 28


Display Processor
• Rather than have the host computer try to refresh
display use a special purpose computer called a display
processor (DPU)

• Graphics stored in display list (display file) on display


processor
• Host compiles display list and sends to DPU

07/11/24 09:48 AM Narendra V G CSE MIT 29


Direct View Storage Tube
• Created by Tektronix
– Did not require constant refresh
– Standard interface to computers
• Allowed for standard software
• Plot3D in Fortran
– Relatively inexpensive
• Opened door to use of computer graphics for CAD
community

07/11/24 09:48 AM Narendra V G CSE MIT 30


Computer Graphics: 1970-1980
• Raster Graphics
• Beginning of graphics standards
– IFIPS
• GKS: European effort
– Becomes ISO 2D standard
• Core: North American effort
– 3D but fails to become ISO standard

• Workstations and PCs

07/11/24 09:48 AM Narendra V G CSE MIT 31


Raster Graphics
• Image produced as an array (the raster) of
picture elements (pixels) in the frame buffer

07/11/24 09:48 AM Narendra V G CSE MIT 32


Raster Graphics
• Allows us to go from lines and wire frame
images to filled polygons

07/11/24 09:48 AM Narendra V G CSE MIT 33


PCs and Workstations
• Although we no longer make the distinction
between workstations and PCs, historically
they evolved from different roots
– Early workstations characterized by
• Networked connection: client-server model
• High-level of interactivity
– Early PCs included frame buffer as part of user
memory
• Easy to change contents and create images

07/11/24 09:48 AM Narendra V G CSE MIT 34


Computer Graphics: 1980-1990
Realism comes to computer graphics

smooth shading environment bump mapping


mapping

07/11/24 09:48 AM Narendra V G CSE MIT 35


Computer Graphics: 1980-1990

• Special purpose hardware


– Silicon Graphics geometry engine
• VLSI implementation of graphics pipeline
• Industry-based standards
– PHIGS
– RenderMan
• Networked graphics: X Window System
• Human-Computer Interface (HCI)

07/11/24 09:48 AM Narendra V G CSE MIT 36


Computer Graphics: 1990-2000
• OpenGL API
• Completely computer-generated feature-
length movies (Toy Story) are successful
• New hardware capabilities
– Texture mapping
– Blending
– Accumulation, stencil buffers

07/11/24 09:48 AM Narendra V G CSE MIT 37


Computer Graphics: 2000-
• Photorealism
• Graphics cards for PCs dominate market
– Nvidia, ATI
• Game boxes and game players determine
direction of market
• Computer graphics routine in movie industry:
Maya, Lightwave
• Programmable pipelines
07/11/24 09:48 AM Narendra V G CSE MIT 38
Graphics Definitions
• Point
– a location in space, 2D or 3D
– sometimes denotes one pixel
• Line
– straight path connecting two points
– infinitesimal width, consistent density
– beginning and end on points

07/11/24 09:48 AM Narendra V G CSE MIT 39


Graphics Definitions
• Vertex
– point in 3D
• Edge
– line in 3D connecting two vertices
• Polygon/Face/Facet
– arbitrary shape formed by connected vertices
– fundamental unit of 3D computer graphics

07/11/24 09:48 AM Narendra V G CSE MIT 40


Graphics Definitions
• Raster
– derived from TV systems for a row of pixels
– commonly referred to as a scanline
– does influence algorithms – reducing memory
requirements, parallelism, etc.
– is the derivation of rasterization, scan-line
algorithms

07/11/24 09:48 AM Narendra V G CSE MIT 41


Summary
• The course is about algorithms, not applications

• Graphics execution is a pipelined approach

• Basic definitions presented

07/11/24 09:48 AM Narendra V G CSE MIT 42


Programming with OpenGL

Basics
Objectives
• Development of the OpenGL API
• OpenGL Architecture
– OpenGL as a state machine
• Functions
– Types
– Formats
• Simple program

07/11/24 09:48 AM Narendra V G CSE MIT 44


Early History of APIs
• IFIPS (1973) formed two committees to come up
with a standard graphics API
– Graphical Kernel System (GKS)
• 2D but contained good workstation model
– Core
• Both 2D and 3D
– GKS adopted as IS0 and later ANSI standard (1980s)
• GKS not easily extended to 3D (GKS-3D)
– Far behind hardware development

07/11/24 09:48 AM Narendra V G CSE MIT 45


PHIGS and X
• Programmers Hierarchical Graphics System
(PHIGS)
– Arose from CAD community
– Database model with retained graphics
(structures)
• X Window System
– DEC/MIT effort
– Client-server architecture with graphics
• PEX combined the two
– Not easy to use (all the defects of each)

07/11/24 09:48 AM Narendra V G CSE MIT 46


SGI and GL
• Silicon Graphics (SGI) revolutionized the
graphics workstation by implementing the
pipeline in hardware (1982)
• To access the system, application
programmers used a library called GL
• With GL, it was relatively simple to program
three dimensional interactive applications

07/11/24 09:48 AM Narendra V G CSE MIT 47


OpenGL
The success of GL lead to OpenGL (1992), a
platform-independent API that was
– Easy to use
– Close enough to the hardware to get excellent
performance
– Focus on rendering
– Omitted windowing and input to avoid window
system dependencies

07/11/24 09:48 AM Narendra V G CSE MIT 48


OpenGL Evolution
• Originally controlled by an Architectural Review
Board (ARB)
– Members included SGI, Microsoft, Nvidia, HP, 3DLabs,
IBM,…….
– Relatively stable (present version 2.1)
• Evolution reflects new hardware capabilities
– 3D texture mapping and texture objects
– Vertex programs
– Allows for platform specific features through
extensions
– ARB replaced by Kronos

07/11/24 09:48 AM Narendra V G CSE MIT 49


OpenGL Libraries
• OpenGL core library
– OpenGL32 on Windows
– GL on most unix/linux systems (libGL.a)
• OpenGL Utility Library (GLU)
– Provides functionality in OpenGL core but avoids
having to rewrite code
• Links with window system
– GLX for X window systems
– WGL for Windows
– AGL for Macintosh

07/11/24 09:48 AM Narendra V G CSE MIT 50


GLUT
• OpenGL Utility Toolkit (GLUT)
– Provides functionality common to all window
systems
• Open a window
• Get input from mouse and keyboard
• Menus
• Event-driven
– Code is portable but GLUT lacks the functionality
of a good toolkit for a specific platform
• No slide bars
07/11/24 09:48 AM Narendra V G CSE MIT 51
Software Organization

application program

OpenGL Motif
widget or similar GLUT
GLX, AGL
or WGL GLU

X, Win32, Mac O/S GL

software and/or hardware

07/11/24 09:48 AM Narendra V G CSE MIT 52


OpenGL Architecture
Immediate Mode geometry
pipeline
Per Vertex
Polynomial Operations &
Evaluator Primitive
Assembly

Display Per Fragment Frame


CPU List
Rasterization
Operations Buffer

Texture
Memory
Pixel
Operations
07/11/24 09:48 AM Narendra V G CSE MIT 53
OpenGL Functions
• Primitives
– Points
– Line Segments
– Polygons
• Attributes
• Transformations
– Viewing
– Modeling
• Control (GLUT)
• Input (GLUT)
• Query
07/11/24 09:48 AM Narendra V G CSE MIT 54
OpenGL State
• OpenGL is a state machine
• OpenGL functions are of two types
– Primitive generating
• Can cause output if primitive is visible
• How vertices are processed and appearance of
primitive are controlled by the state
– State changing
• Transformation functions
• Attribute functions

07/11/24 09:48 AM Narendra V G CSE MIT 55


Lack of Object Orientation
• OpenGL is not object oriented so that there are
multiple functions for a given logical function
– glVertex3f
– glVertex2i
– glVertex3dv
• Underlying storage mode is the same
• Easy to create overloaded functions in C++ but
issue is efficiency

07/11/24 09:48 AM Narendra V G CSE MIT 56


OpenGL function format
function name
dimensions

glVertex3f(x,y,z)

belongs to GL library x,y,z are floats

glVertex3fv(p)

p is a pointer to an array

07/11/24 09:48 AM Narendra V G CSE MIT 57


OpenGL #defines
• Most constants are defined in the include files
gl.h, glu.h and glut.h
– Note #include <GL/glut.h> should
automatically include the others
– Examples
– glBegin(GL_POLYGON)
– glClear(GL_COLOR_BUFFER_BIT)
• include files also define OpenGL data types:
GLfloat, GLdouble,….
07/11/24 09:48 AM Narendra V G CSE MIT 58
A Simple Program
Generate a square on a solid background

07/11/24 09:48 AM Narendra V G CSE MIT 59


simple.c
#include <GL/glut.h>
void mydisplay(){
glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_POLYGON);
glVertex2f(-0.5, -0.5);
glVertex2f(-0.5, 0.5);
glVertex2f(0.5, 0.5);
glVertex2f(0.5, -0.5);
glEnd();
glFlush();
}
int main(int argc, char** argv){
glutCreateWindow("simple");
glutDisplayFunc(mydisplay);
glutMainLoop();
}
07/11/24 09:48 AM Narendra V G CSE MIT 60
Event Loop
• Note that the program defines a display
callback function named mydisplay
– Every glut program must have a display callback
– The display callback is executed whenever
OpenGL decides the display must be refreshed, for
example when the window is opened
– The main function ends with the program
entering an event loop

07/11/24 09:48 AM Narendra V G CSE MIT 61


Defaults
• simple.c is too simple
• Makes heavy use of state variable default
values for
– Viewing
– Colors
– Window parameters
• Next version will make the defaults more
explicit

07/11/24 09:48 AM Narendra V G CSE MIT 62


Notes on compilation
• See website and ftp for examples
• Unix/linux
– Include files usually in …/include/GL
– Compile with –lglut –lGLU –lGL loader flags
– May have to add –L flag for X libraries
– Mesa implementation included with most linux
distributions
– Check web for latest versions of Mesa and glut

07/11/24 09:48 AM Narendra V G CSE MIT 63


Compilation on Windows
• Visual C++
– Get glut.h, glut32.lib and glut32.dll from web
– Create a console application
– Add opengl32.lib, glut32.lib, glut32.lib to project
settings (under link tab)
• Borland C similar
• Cygwin (linux under Windows)
– Can use gcc and similar makefile to linux
– Use –lopengl32 –lglu32 –lglut32 flags
07/11/24 09:48 AM Narendra V G CSE MIT 64
To display window and line segment
#include<GL/gl.h>
#include<GL/glu.h>
#include<GL/glut.h>
void init (void)
{ glClearColor(1.0,1.0,1.0,0.0) ;//set display-window color to white
glMatrixMode(GL_PROJECTION); //set projection parameter
gluOrtho2D(0.0,200.0,0.0,150.0); }
void lineSegment(void)
{ glClear(GL_COLOR_BUFFER_BIT); //clear display window
glColor3f(1.0,0.0,0.0); //set line segment color to red
glBegin(GL_LINES);
glVertex2i(180,15); //specify line-segment geometry
glVertex2i(10,145);
glEnd();
glFlush(); }

07/11/24 09:48 AM Narendra V G CSE MIT 65


To display window and line segment
void main(int argc, char** argv)
{
glutInit(&argc, argv); // Initialize GLUT
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB); //set display mode
glutInitWindowPosition(50,100); //set top-left display window position
glutInitWindowSize(400,300); //set display window width and height
glutCreateWindow(“An Example OpenGL Program”); //create dis-win
init( ); //Execute initialization procedure
glutDisplayFunc(lineSegment); //send graphics to display window
glutMainLoop( );//Display everything and wait
}

07/11/24 09:48 AM Narendra V G CSE MIT 66

You might also like