SlideShare a Scribd company logo
Unit 11
Graphics
Intro
• There are two modes of the standard output device:
• Text Mode
• Graphics Mode
• The programming for video games, animation and multimedia is
difficult in text mode as they predominantly work with computer
graphics.
• In graphics mode we work with tiny dots on the screen called pixels
(picture elements)
Ashim Lamichhane 2
Intro..
• The pixels are even present in text mode as they are used to form
characters that appear on the screen with only difference that they are
predefined pattern of pixels.
• However, the graphics mode provides the ability to manipulate the
individual pixels.
• To work with graphics, we can use graphics.h header file
Ashim Lamichhane 3
Graphics Characteristics
1. Pixels
• Short for Picture Element, a pixel is a single point (i.e. dot) in graphic image.
• Graphics monitor displays pictures by dividing the display screen into thousands of
pixels arranged in rows and columns.
• The pixels are so close together that they appear connected.
• The computer screen is a two dimensional; each pixel on the screen has some
location, illustrated by x and y values
• x is the horizontal offset from the left side of the screen
• y is the vertical offset from the top of the screen.
• So x=0 and y=0 represent top left corner of computer screen.
Ashim Lamichhane 4
Fig. representation of co-ordinates on computer screen
Ashim Lamichhane 5
(0,0)
(200,0)
y
(0,479)
(639,0)
x
(320,240)
(639,450)
(639,479)
Suppose to plot a pixel on the
Screen at say x=70 and y=100,
We’d put pixel information into
that two dimensional array,
at element array [100][70]
2. Resolution
• The number of pixels used on the screen is called resolution.
• There are fixed number of rows and each rows contains certain numbers of
pixels
• The frequently used resolutions supported by most of adapters are 640*480,
800*600,1024*768, 1152*864, 1220*1024 etc.
• The resolution 640*480 (640 by 480) means that there are 640 pixels in
horizontal direction(i.e. x-axis) and 480 pixels in vertical direction (i.e y-axis).
• In general for higher resolution, the picture is more pleasing.
Ashim Lamichhane 6
3. Colors
• Some graphics modes support more colors than other ranging from 2 to
millions colors.
• A particular mode may support only two colors at a time while other my
support 256 colors.
• These groups of colors are known as color palettes.
Ashim Lamichhane 7
4. Video Adapters
• Video adapters are drivers for display
• Each video adapter handles graphics in different way.
• Once a video adapter is initialized by the program for particular
graphics mode then it can use it to plot various elements as well as to
display text in different fonts.
• Some examples of video adapters are CGA, VGA and EGA
Ashim Lamichhane 8
Initializing Graphics Hardware
• The built in function initgraph() is used to initialize the graphics system
and put the computer screen in specified graphics mode.
• initgraph() initializes the graphics system by loading a graphics driver
from disk then putting the system into graphics mode.
• It also resets all graphics settings(color, palette, current position etc) to
their defaults.
• Ex:
initgraph(&graphics_driver,&graphics_mode,”path_to_driver”);
Ashim Lamichhane 9
initgraph(&graphics_driver,&graphics_mode,”path_to_driver”);
• graphics_driver is a variable of type int initialized to some constants that is
defined in graphics.h header file. It species the graphics driver to be used.
• C offers certain graphics drivers and these are the files with .BGI extension.
• Depending on what adapter is used, one of these drivers gets selected.
• Some constants defined in graphics.h file for this argument are
• DETECT(=0)
• CGA(=1)
• EGA(=3)
• EGA64(=4)
• EGAMONO(=5)
• VGA(=9)
Ashim Lamichhane 10
initgraph(&graphics_driver,&graphics_mode,”path_to_driver”);
• graphics_mode is also a type int that is initialized to the mode for the
particular video adapter to use.
• This variable tells which monitor we are using and its resolution, the
number of video pages it supports and the colors that are available.
• The third argument is path_to_driver is string constant that specifies
the directory containing .bgi files and .chr files.
• Its value may be like “C:TCBGI”
Ashim Lamichhane 11
Auto-Initialization of Graphics Hardware
• In the use of initgraph() function we have explicitly told initgraph()
what graphics driver and mode to use by assigning the values to driver
and mode arguments.
• It is possible to let the program to find out the video adapter installed
in the computer and use the best driver and mode.
• i.e. the combination that gives the highest resolution.
Ashim Lamichhane 12
• There are two approaches for auto initialization of graphics hardware.
• DETECT is used for driver argument. In this method program doesn’t
know in advance what mode will be used and cannot assume anything
about the resolution. Ex.
int gd,gm;
gd=DETECT;
initgraph(gd,&gm,”C:TCBGI”);
• A function called detectgraph() is used that returns value for the
best driver and mode.
int gd,gm;
Detectgraph(&gd,&gm);
initgraph(&gd,&gm,”C:TCBGI”);
Ashim Lamichhane 13
Closing Graphic Mode
• Once the program has finished its job using the graphics facilities, then
it should restore the system to the mode that was previously in use.
• If graphics mode is not closed explicitly by the programmer,
undesirable effects may be felt.
• The closegraph() function is used to restore the screen to the mode it
was in before we called initgraph() and deallocates all memory
allocated by the graphics system.
Ashim Lamichhane 14
Observation of graphics result
• The library function graphresult() is used to determine whether a
certain graphics operation succeeded or not.
• This function returns an error code for the last unsuccessful graphics
operation.
• grOk represents that there is no error. The variable maintained by
graphresult is reset to 0 after graphresult has been called.
• Therefore we should store the value of graphresult into a temporary
variable and then test it.
Ashim Lamichhane 15
Library Functions
• Plotting and getting points
• putpixel()
• Plots a point with a specified color
putpixel(int x, int y, int color);
• getpixel()
• Gets color of specified pixel
integer_variable=getpixel(int x, int y);
• Changing drawing/foreground and background color
• setcolor(): changes current fg color
setcolor(int color);
• stbkcolor(): changes current bg color
Setbkcolor(int color);
Ashim Lamichhane 16
• Drawing Lines
• line()
• Draws line from point having co-ordinate x1, y1 to x2, y2 using current settings for the line
drawing and current drawing color.
line(int x1, int x1, int x2, int y2);
Similarly
setlinestyle(int style, unsigned int pattern, int thickness);
• lineto()
• It draws a line from current position to point (x,y).
• The current position of point can be changed using moveto(x,y) function
lineto(int x, int y);
And
moveto(int x1,y1);
• linerel()
• Draws a line a relative distance from current position
linerel(int dx, int dy);
Ashim Lamichhane 17
• Drawing Shapes
• circle()
• Draws a circle having center point (x,y) and radius r with current color.
circle(int x,int y, int r);
• ellipse()
• Draws an ellipse with current color
ellipse(int x,int y, int startAngle, int endAngle, int xRadius,int yRadius);
• arc()
• Draws a circular arc in a portion of circle
arc(int x, int y, int startAngle, int endAngle, int radius);
• rectangle()
• Draws rectangle from two end points of a diagonal of the rectangle
reactangle(int x1, int y1, int x2, int y2);
Ashim Lamichhane 18
• drawpoly(): draws the outline of a polygon using required points
• fillpoly(): draws and fills polygon
• Draws the outline of a polygon using required points
drawpoly(int numberOfPoints, int points[]);
fillpoly(int numberOfPoints, int points[]);
• To draw a closed polygon with N vertices we must pass N+1 co-ordinates to
drawpoly() or fillpoly() where N+1th co-ordinate must be same as first co-
ordinate.
• Thus to draw hexagon we need seven points where first and seventh point is
same
Ashim Lamichhane 19
• Displaying text in graphics mode
• outtext(): it displays the string at the current position
outtext(string text);
• outtextxy(): it displays the string at point(x,y)
outtextxy(int x, int y, string text);
• settextstyle(): it changes font, size and direction of characters.
settextstyle(int font, int direction, int size);
Ashim Lamichhane 20
• pieslice(): draws a sector with current color and font setting
pieslice(int x,int y,int startAngle,int endAngle, int r);
• bar():
• draws bar diagram using two points left-top corner and bottom corner
bar(int left, int top, int right, int bottom);
• getmaxx()
• Returns max x value for current graphics driver and mode
integer_variable=getmaxx()
• getmaxy()
• Returns max y value for current graphics driver and mode
integer_variable=getmaxy()
Ashim Lamichhane 21
END
Ashim Lamichhane 22

More Related Content

What's hot

Graphics practical lab manual
Graphics practical lab manualGraphics practical lab manual
Graphics practical lab manual
Vivek Kumar Sinha
 
Basics of Computer graphics lab
Basics of Computer graphics labBasics of Computer graphics lab
Basics of Computer graphics lab
Priya Goyal
 
Applications Of Computer Graphics
Applications Of Computer GraphicsApplications Of Computer Graphics
Applications Of Computer Graphics
Muhammad Amjad Rana
 
Bresenham's line drawing algorithm
Bresenham's line drawing algorithmBresenham's line drawing algorithm
Bresenham's line drawing algorithm
nehrurevathy
 
Computer graphics basic transformation
Computer graphics basic transformationComputer graphics basic transformation
Computer graphics basic transformation
Selvakumar Gna
 
Dda algorithm
Dda algorithmDda algorithm
Dda algorithm
Mani Kanth
 
Managing input and output operations in c
Managing input and output operations in cManaging input and output operations in c
Managing input and output operations in c
niyamathShariff
 
C Graphics Functions
C Graphics FunctionsC Graphics Functions
C Graphics Functions
SHAKOOR AB
 
Computer graphics curves and surfaces (1)
Computer graphics curves and surfaces (1)Computer graphics curves and surfaces (1)
Computer graphics curves and surfaces (1)
RohitK71
 
Java I/o streams
Java I/o streamsJava I/o streams
Java I/o streams
Hamid Ghorbani
 
Attributes of output primitive(line attributes)
Attributes of output primitive(line attributes)Attributes of output primitive(line attributes)
Attributes of output primitive(line attributes)
shalinikarunakaran1
 
android menus
android menusandroid menus
android menus
Deepa Rani
 
java programming - applets
java programming - appletsjava programming - applets
java programming - applets
HarshithaAllu
 
Circle drawing algo.
Circle drawing algo.Circle drawing algo.
Circle drawing algo.
Mohd Arif
 
Functions in c language
Functions in c language Functions in c language
Functions in c language
tanmaymodi4
 
Output primitives computer graphics c version
Output primitives   computer graphics c versionOutput primitives   computer graphics c version
Output primitives computer graphics c version
Marwa Al-Rikaby
 
Computer graphics chapter 4
Computer graphics chapter 4Computer graphics chapter 4
Computer graphics chapter 4
PrathimaBaliga
 
Function in c
Function in cFunction in c
Function in c
savitamhaske
 
Polygon filling
Polygon fillingPolygon filling
Algorithm and c language
Algorithm and c languageAlgorithm and c language
Algorithm and c language
kamalbeydoun
 

What's hot (20)

Graphics practical lab manual
Graphics practical lab manualGraphics practical lab manual
Graphics practical lab manual
 
Basics of Computer graphics lab
Basics of Computer graphics labBasics of Computer graphics lab
Basics of Computer graphics lab
 
Applications Of Computer Graphics
Applications Of Computer GraphicsApplications Of Computer Graphics
Applications Of Computer Graphics
 
Bresenham's line drawing algorithm
Bresenham's line drawing algorithmBresenham's line drawing algorithm
Bresenham's line drawing algorithm
 
Computer graphics basic transformation
Computer graphics basic transformationComputer graphics basic transformation
Computer graphics basic transformation
 
Dda algorithm
Dda algorithmDda algorithm
Dda algorithm
 
Managing input and output operations in c
Managing input and output operations in cManaging input and output operations in c
Managing input and output operations in c
 
C Graphics Functions
C Graphics FunctionsC Graphics Functions
C Graphics Functions
 
Computer graphics curves and surfaces (1)
Computer graphics curves and surfaces (1)Computer graphics curves and surfaces (1)
Computer graphics curves and surfaces (1)
 
Java I/o streams
Java I/o streamsJava I/o streams
Java I/o streams
 
Attributes of output primitive(line attributes)
Attributes of output primitive(line attributes)Attributes of output primitive(line attributes)
Attributes of output primitive(line attributes)
 
android menus
android menusandroid menus
android menus
 
java programming - applets
java programming - appletsjava programming - applets
java programming - applets
 
Circle drawing algo.
Circle drawing algo.Circle drawing algo.
Circle drawing algo.
 
Functions in c language
Functions in c language Functions in c language
Functions in c language
 
Output primitives computer graphics c version
Output primitives   computer graphics c versionOutput primitives   computer graphics c version
Output primitives computer graphics c version
 
Computer graphics chapter 4
Computer graphics chapter 4Computer graphics chapter 4
Computer graphics chapter 4
 
Function in c
Function in cFunction in c
Function in c
 
Polygon filling
Polygon fillingPolygon filling
Polygon filling
 
Algorithm and c language
Algorithm and c languageAlgorithm and c language
Algorithm and c language
 

Viewers also liked

UNIT 10. Files and file handling in C
UNIT 10. Files and file handling in CUNIT 10. Files and file handling in C
UNIT 10. Files and file handling in C
Ashim Lamichhane
 
Unit 8. Pointers
Unit 8. PointersUnit 8. Pointers
Unit 8. Pointers
Ashim Lamichhane
 
Unit 7. Functions
Unit 7. FunctionsUnit 7. Functions
Unit 7. Functions
Ashim Lamichhane
 
File handling in c
File handling in c File handling in c
File handling in c
Vikash Dhal
 
File handling in c
File handling in cFile handling in c
File handling in c
David Livingston J
 
Unit 2. Elements of C
Unit 2. Elements of CUnit 2. Elements of C
Unit 2. Elements of C
Ashim Lamichhane
 
File in C Programming
File in C ProgrammingFile in C Programming
File in C Programming
Sonya Akter Rupa
 
File handling in 'C'
File handling in 'C'File handling in 'C'
File handling in 'C'
Gaurav Garg
 
Unit 6. Arrays
Unit 6. ArraysUnit 6. Arrays
Unit 6. Arrays
Ashim Lamichhane
 
File in c
File in cFile in c
File in c
Prabhu Govind
 
Unit 9. Structure and Unions
Unit 9. Structure and UnionsUnit 9. Structure and Unions
Unit 9. Structure and Unions
Ashim Lamichhane
 
Unit 5. Control Statement
Unit 5. Control StatementUnit 5. Control Statement
Unit 5. Control Statement
Ashim Lamichhane
 
Unit 4. Operators and Expression
Unit 4. Operators and Expression  Unit 4. Operators and Expression
Unit 4. Operators and Expression
Ashim Lamichhane
 
Unit 3. Input and Output
Unit 3. Input and OutputUnit 3. Input and Output
Unit 3. Input and Output
Ashim Lamichhane
 
File handling in C
File handling in CFile handling in C
File handling in C
Kamal Acharya
 

Viewers also liked (15)

UNIT 10. Files and file handling in C
UNIT 10. Files and file handling in CUNIT 10. Files and file handling in C
UNIT 10. Files and file handling in C
 
Unit 8. Pointers
Unit 8. PointersUnit 8. Pointers
Unit 8. Pointers
 
Unit 7. Functions
Unit 7. FunctionsUnit 7. Functions
Unit 7. Functions
 
File handling in c
File handling in c File handling in c
File handling in c
 
File handling in c
File handling in cFile handling in c
File handling in c
 
Unit 2. Elements of C
Unit 2. Elements of CUnit 2. Elements of C
Unit 2. Elements of C
 
File in C Programming
File in C ProgrammingFile in C Programming
File in C Programming
 
File handling in 'C'
File handling in 'C'File handling in 'C'
File handling in 'C'
 
Unit 6. Arrays
Unit 6. ArraysUnit 6. Arrays
Unit 6. Arrays
 
File in c
File in cFile in c
File in c
 
Unit 9. Structure and Unions
Unit 9. Structure and UnionsUnit 9. Structure and Unions
Unit 9. Structure and Unions
 
Unit 5. Control Statement
Unit 5. Control StatementUnit 5. Control Statement
Unit 5. Control Statement
 
Unit 4. Operators and Expression
Unit 4. Operators and Expression  Unit 4. Operators and Expression
Unit 4. Operators and Expression
 
Unit 3. Input and Output
Unit 3. Input and OutputUnit 3. Input and Output
Unit 3. Input and Output
 
File handling in C
File handling in CFile handling in C
File handling in C
 

Similar to Unit 11. Graphics

Cg lab cse-v (1) (1)
Cg lab cse-v (1) (1)Cg lab cse-v (1) (1)
Cg lab cse-v (1) (1)
Surya Sukumaran
 
Introduction to Computer graphics
Introduction to Computer graphicsIntroduction to Computer graphics
Introduction to Computer graphics
LOKESH KUMAR
 
Chapter 1
Chapter 1Chapter 1
Chapter 1
kparthjadhav
 
Graphics mod
Graphics modGraphics mod
Graphics mod
Haya Saani
 
Prinsip gambar digital
Prinsip gambar digitalPrinsip gambar digital
Prinsip gambar digital
Ono Trader
 
Chapter-3.pdf
Chapter-3.pdfChapter-3.pdf
Computer Graphics
Computer GraphicsComputer Graphics
Computer Graphics
Adri Jovin
 
Overview of graphics systems
Overview of  graphics systemsOverview of  graphics systems
Overview of graphics systems
Jay Nagar
 
Computer graphics
Computer graphics Computer graphics
Computer graphics
shafiq sangi
 
Computer graphics
Computer graphicsComputer graphics
Computer graphics
amitsarda3
 
3 CG_U1_P2_PPT_3 OpenGL.pptx
3 CG_U1_P2_PPT_3 OpenGL.pptx3 CG_U1_P2_PPT_3 OpenGL.pptx
3 CG_U1_P2_PPT_3 OpenGL.pptx
ssuser255bf1
 
Programming with OpenGL
Programming with OpenGLProgramming with OpenGL
Programming with OpenGL
Syed Zaid Irshad
 
Smedberg niklas bringing_aaa_graphics
Smedberg niklas bringing_aaa_graphicsSmedberg niklas bringing_aaa_graphics
Smedberg niklas bringing_aaa_graphics
changehee lee
 
Overview of graphics systems.ppt
Overview of graphics systems.pptOverview of graphics systems.ppt
Overview of graphics systems.ppt
MalleshBettadapura1
 
Applet in java
Applet in javaApplet in java
Applet in java
Rakesh Mittal
 
Buffers
BuffersBuffers
Presentation.pptx
Presentation.pptxPresentation.pptx
Presentation.pptx
AANUSRIRAMESH1
 
Данило Ульянич “C89 OpenGL for ARM microcontrollers on Cortex-M. Basic functi...
Данило Ульянич “C89 OpenGL for ARM microcontrollers on Cortex-M. Basic functi...Данило Ульянич “C89 OpenGL for ARM microcontrollers on Cortex-M. Basic functi...
Данило Ульянич “C89 OpenGL for ARM microcontrollers on Cortex-M. Basic functi...
Lviv Startup Club
 
2D graphics
2D graphics2D graphics
2D graphics
Muhammad Rashid
 
Game Programming 12 - Shaders
Game Programming 12 - ShadersGame Programming 12 - Shaders
Game Programming 12 - Shaders
Nick Pruehs
 

Similar to Unit 11. Graphics (20)

Cg lab cse-v (1) (1)
Cg lab cse-v (1) (1)Cg lab cse-v (1) (1)
Cg lab cse-v (1) (1)
 
Introduction to Computer graphics
Introduction to Computer graphicsIntroduction to Computer graphics
Introduction to Computer graphics
 
Chapter 1
Chapter 1Chapter 1
Chapter 1
 
Graphics mod
Graphics modGraphics mod
Graphics mod
 
Prinsip gambar digital
Prinsip gambar digitalPrinsip gambar digital
Prinsip gambar digital
 
Chapter-3.pdf
Chapter-3.pdfChapter-3.pdf
Chapter-3.pdf
 
Computer Graphics
Computer GraphicsComputer Graphics
Computer Graphics
 
Overview of graphics systems
Overview of  graphics systemsOverview of  graphics systems
Overview of graphics systems
 
Computer graphics
Computer graphics Computer graphics
Computer graphics
 
Computer graphics
Computer graphicsComputer graphics
Computer graphics
 
3 CG_U1_P2_PPT_3 OpenGL.pptx
3 CG_U1_P2_PPT_3 OpenGL.pptx3 CG_U1_P2_PPT_3 OpenGL.pptx
3 CG_U1_P2_PPT_3 OpenGL.pptx
 
Programming with OpenGL
Programming with OpenGLProgramming with OpenGL
Programming with OpenGL
 
Smedberg niklas bringing_aaa_graphics
Smedberg niklas bringing_aaa_graphicsSmedberg niklas bringing_aaa_graphics
Smedberg niklas bringing_aaa_graphics
 
Overview of graphics systems.ppt
Overview of graphics systems.pptOverview of graphics systems.ppt
Overview of graphics systems.ppt
 
Applet in java
Applet in javaApplet in java
Applet in java
 
Buffers
BuffersBuffers
Buffers
 
Presentation.pptx
Presentation.pptxPresentation.pptx
Presentation.pptx
 
Данило Ульянич “C89 OpenGL for ARM microcontrollers on Cortex-M. Basic functi...
Данило Ульянич “C89 OpenGL for ARM microcontrollers on Cortex-M. Basic functi...Данило Ульянич “C89 OpenGL for ARM microcontrollers on Cortex-M. Basic functi...
Данило Ульянич “C89 OpenGL for ARM microcontrollers on Cortex-M. Basic functi...
 
2D graphics
2D graphics2D graphics
2D graphics
 
Game Programming 12 - Shaders
Game Programming 12 - ShadersGame Programming 12 - Shaders
Game Programming 12 - Shaders
 

More from Ashim Lamichhane

Searching
SearchingSearching
Searching
Ashim Lamichhane
 
Sorting
SortingSorting
Tree - Data Structure
Tree - Data StructureTree - Data Structure
Tree - Data Structure
Ashim Lamichhane
 
Linked List
Linked ListLinked List
Linked List
Ashim Lamichhane
 
Queues
QueuesQueues
The Stack And Recursion
The Stack And RecursionThe Stack And Recursion
The Stack And Recursion
Ashim Lamichhane
 
Algorithm big o
Algorithm big oAlgorithm big o
Algorithm big o
Ashim Lamichhane
 
Algorithm Introduction
Algorithm IntroductionAlgorithm Introduction
Algorithm Introduction
Ashim Lamichhane
 
Introduction to data_structure
Introduction to data_structureIntroduction to data_structure
Introduction to data_structure
Ashim Lamichhane
 
Unit 1. Problem Solving with Computer
Unit 1. Problem Solving with Computer   Unit 1. Problem Solving with Computer
Unit 1. Problem Solving with Computer
Ashim Lamichhane
 

More from Ashim Lamichhane (10)

Searching
SearchingSearching
Searching
 
Sorting
SortingSorting
Sorting
 
Tree - Data Structure
Tree - Data StructureTree - Data Structure
Tree - Data Structure
 
Linked List
Linked ListLinked List
Linked List
 
Queues
QueuesQueues
Queues
 
The Stack And Recursion
The Stack And RecursionThe Stack And Recursion
The Stack And Recursion
 
Algorithm big o
Algorithm big oAlgorithm big o
Algorithm big o
 
Algorithm Introduction
Algorithm IntroductionAlgorithm Introduction
Algorithm Introduction
 
Introduction to data_structure
Introduction to data_structureIntroduction to data_structure
Introduction to data_structure
 
Unit 1. Problem Solving with Computer
Unit 1. Problem Solving with Computer   Unit 1. Problem Solving with Computer
Unit 1. Problem Solving with Computer
 

Recently uploaded

C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptxC1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
mulvey2
 
Cognitive Development Adolescence Psychology
Cognitive Development Adolescence PsychologyCognitive Development Adolescence Psychology
Cognitive Development Adolescence Psychology
paigestewart1632
 
Pride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School DistrictPride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School District
David Douglas School District
 
The History of Stoke Newington Street Names
The History of Stoke Newington Street NamesThe History of Stoke Newington Street Names
The History of Stoke Newington Street Names
History of Stoke Newington
 
Community pharmacy- Social and preventive pharmacy UNIT 5
Community pharmacy- Social and preventive pharmacy UNIT 5Community pharmacy- Social and preventive pharmacy UNIT 5
Community pharmacy- Social and preventive pharmacy UNIT 5
sayalidalavi006
 
writing about opinions about Australia the movie
writing about opinions about Australia the moviewriting about opinions about Australia the movie
writing about opinions about Australia the movie
Nicholas Montgomery
 
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective UpskillingYour Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Excellence Foundation for South Sudan
 
S1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptxS1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptx
tarandeep35
 
Main Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docxMain Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docx
adhitya5119
 
Life upper-Intermediate B2 Workbook for student
Life upper-Intermediate B2 Workbook for studentLife upper-Intermediate B2 Workbook for student
Life upper-Intermediate B2 Workbook for student
NgcHiNguyn25
 
Digital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments UnitDigital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments Unit
chanes7
 
Azure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHatAzure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHat
Scholarhat
 
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdfবাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
eBook.com.bd (প্রয়োজনীয় বাংলা বই)
 
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
GeorgeMilliken2
 
Film vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movieFilm vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movie
Nicholas Montgomery
 
PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.
Dr. Shivangi Singh Parihar
 
Liberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdfLiberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdf
WaniBasim
 
The Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collectionThe Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collection
Israel Genealogy Research Association
 
World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024
ak6969907
 
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama UniversityNatural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Akanksha trivedi rama nursing college kanpur.
 

Recently uploaded (20)

C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptxC1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
 
Cognitive Development Adolescence Psychology
Cognitive Development Adolescence PsychologyCognitive Development Adolescence Psychology
Cognitive Development Adolescence Psychology
 
Pride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School DistrictPride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School District
 
The History of Stoke Newington Street Names
The History of Stoke Newington Street NamesThe History of Stoke Newington Street Names
The History of Stoke Newington Street Names
 
Community pharmacy- Social and preventive pharmacy UNIT 5
Community pharmacy- Social and preventive pharmacy UNIT 5Community pharmacy- Social and preventive pharmacy UNIT 5
Community pharmacy- Social and preventive pharmacy UNIT 5
 
writing about opinions about Australia the movie
writing about opinions about Australia the moviewriting about opinions about Australia the movie
writing about opinions about Australia the movie
 
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective UpskillingYour Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective Upskilling
 
S1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptxS1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptx
 
Main Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docxMain Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docx
 
Life upper-Intermediate B2 Workbook for student
Life upper-Intermediate B2 Workbook for studentLife upper-Intermediate B2 Workbook for student
Life upper-Intermediate B2 Workbook for student
 
Digital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments UnitDigital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments Unit
 
Azure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHatAzure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHat
 
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdfবাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
 
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
 
Film vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movieFilm vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movie
 
PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.
 
Liberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdfLiberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdf
 
The Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collectionThe Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collection
 
World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024
 
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama UniversityNatural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
 

Unit 11. Graphics

  • 2. Intro • There are two modes of the standard output device: • Text Mode • Graphics Mode • The programming for video games, animation and multimedia is difficult in text mode as they predominantly work with computer graphics. • In graphics mode we work with tiny dots on the screen called pixels (picture elements) Ashim Lamichhane 2
  • 3. Intro.. • The pixels are even present in text mode as they are used to form characters that appear on the screen with only difference that they are predefined pattern of pixels. • However, the graphics mode provides the ability to manipulate the individual pixels. • To work with graphics, we can use graphics.h header file Ashim Lamichhane 3
  • 4. Graphics Characteristics 1. Pixels • Short for Picture Element, a pixel is a single point (i.e. dot) in graphic image. • Graphics monitor displays pictures by dividing the display screen into thousands of pixels arranged in rows and columns. • The pixels are so close together that they appear connected. • The computer screen is a two dimensional; each pixel on the screen has some location, illustrated by x and y values • x is the horizontal offset from the left side of the screen • y is the vertical offset from the top of the screen. • So x=0 and y=0 represent top left corner of computer screen. Ashim Lamichhane 4
  • 5. Fig. representation of co-ordinates on computer screen Ashim Lamichhane 5 (0,0) (200,0) y (0,479) (639,0) x (320,240) (639,450) (639,479) Suppose to plot a pixel on the Screen at say x=70 and y=100, We’d put pixel information into that two dimensional array, at element array [100][70]
  • 6. 2. Resolution • The number of pixels used on the screen is called resolution. • There are fixed number of rows and each rows contains certain numbers of pixels • The frequently used resolutions supported by most of adapters are 640*480, 800*600,1024*768, 1152*864, 1220*1024 etc. • The resolution 640*480 (640 by 480) means that there are 640 pixels in horizontal direction(i.e. x-axis) and 480 pixels in vertical direction (i.e y-axis). • In general for higher resolution, the picture is more pleasing. Ashim Lamichhane 6
  • 7. 3. Colors • Some graphics modes support more colors than other ranging from 2 to millions colors. • A particular mode may support only two colors at a time while other my support 256 colors. • These groups of colors are known as color palettes. Ashim Lamichhane 7
  • 8. 4. Video Adapters • Video adapters are drivers for display • Each video adapter handles graphics in different way. • Once a video adapter is initialized by the program for particular graphics mode then it can use it to plot various elements as well as to display text in different fonts. • Some examples of video adapters are CGA, VGA and EGA Ashim Lamichhane 8
  • 9. Initializing Graphics Hardware • The built in function initgraph() is used to initialize the graphics system and put the computer screen in specified graphics mode. • initgraph() initializes the graphics system by loading a graphics driver from disk then putting the system into graphics mode. • It also resets all graphics settings(color, palette, current position etc) to their defaults. • Ex: initgraph(&graphics_driver,&graphics_mode,”path_to_driver”); Ashim Lamichhane 9
  • 10. initgraph(&graphics_driver,&graphics_mode,”path_to_driver”); • graphics_driver is a variable of type int initialized to some constants that is defined in graphics.h header file. It species the graphics driver to be used. • C offers certain graphics drivers and these are the files with .BGI extension. • Depending on what adapter is used, one of these drivers gets selected. • Some constants defined in graphics.h file for this argument are • DETECT(=0) • CGA(=1) • EGA(=3) • EGA64(=4) • EGAMONO(=5) • VGA(=9) Ashim Lamichhane 10
  • 11. initgraph(&graphics_driver,&graphics_mode,”path_to_driver”); • graphics_mode is also a type int that is initialized to the mode for the particular video adapter to use. • This variable tells which monitor we are using and its resolution, the number of video pages it supports and the colors that are available. • The third argument is path_to_driver is string constant that specifies the directory containing .bgi files and .chr files. • Its value may be like “C:TCBGI” Ashim Lamichhane 11
  • 12. Auto-Initialization of Graphics Hardware • In the use of initgraph() function we have explicitly told initgraph() what graphics driver and mode to use by assigning the values to driver and mode arguments. • It is possible to let the program to find out the video adapter installed in the computer and use the best driver and mode. • i.e. the combination that gives the highest resolution. Ashim Lamichhane 12
  • 13. • There are two approaches for auto initialization of graphics hardware. • DETECT is used for driver argument. In this method program doesn’t know in advance what mode will be used and cannot assume anything about the resolution. Ex. int gd,gm; gd=DETECT; initgraph(gd,&gm,”C:TCBGI”); • A function called detectgraph() is used that returns value for the best driver and mode. int gd,gm; Detectgraph(&gd,&gm); initgraph(&gd,&gm,”C:TCBGI”); Ashim Lamichhane 13
  • 14. Closing Graphic Mode • Once the program has finished its job using the graphics facilities, then it should restore the system to the mode that was previously in use. • If graphics mode is not closed explicitly by the programmer, undesirable effects may be felt. • The closegraph() function is used to restore the screen to the mode it was in before we called initgraph() and deallocates all memory allocated by the graphics system. Ashim Lamichhane 14
  • 15. Observation of graphics result • The library function graphresult() is used to determine whether a certain graphics operation succeeded or not. • This function returns an error code for the last unsuccessful graphics operation. • grOk represents that there is no error. The variable maintained by graphresult is reset to 0 after graphresult has been called. • Therefore we should store the value of graphresult into a temporary variable and then test it. Ashim Lamichhane 15
  • 16. Library Functions • Plotting and getting points • putpixel() • Plots a point with a specified color putpixel(int x, int y, int color); • getpixel() • Gets color of specified pixel integer_variable=getpixel(int x, int y); • Changing drawing/foreground and background color • setcolor(): changes current fg color setcolor(int color); • stbkcolor(): changes current bg color Setbkcolor(int color); Ashim Lamichhane 16
  • 17. • Drawing Lines • line() • Draws line from point having co-ordinate x1, y1 to x2, y2 using current settings for the line drawing and current drawing color. line(int x1, int x1, int x2, int y2); Similarly setlinestyle(int style, unsigned int pattern, int thickness); • lineto() • It draws a line from current position to point (x,y). • The current position of point can be changed using moveto(x,y) function lineto(int x, int y); And moveto(int x1,y1); • linerel() • Draws a line a relative distance from current position linerel(int dx, int dy); Ashim Lamichhane 17
  • 18. • Drawing Shapes • circle() • Draws a circle having center point (x,y) and radius r with current color. circle(int x,int y, int r); • ellipse() • Draws an ellipse with current color ellipse(int x,int y, int startAngle, int endAngle, int xRadius,int yRadius); • arc() • Draws a circular arc in a portion of circle arc(int x, int y, int startAngle, int endAngle, int radius); • rectangle() • Draws rectangle from two end points of a diagonal of the rectangle reactangle(int x1, int y1, int x2, int y2); Ashim Lamichhane 18
  • 19. • drawpoly(): draws the outline of a polygon using required points • fillpoly(): draws and fills polygon • Draws the outline of a polygon using required points drawpoly(int numberOfPoints, int points[]); fillpoly(int numberOfPoints, int points[]); • To draw a closed polygon with N vertices we must pass N+1 co-ordinates to drawpoly() or fillpoly() where N+1th co-ordinate must be same as first co- ordinate. • Thus to draw hexagon we need seven points where first and seventh point is same Ashim Lamichhane 19
  • 20. • Displaying text in graphics mode • outtext(): it displays the string at the current position outtext(string text); • outtextxy(): it displays the string at point(x,y) outtextxy(int x, int y, string text); • settextstyle(): it changes font, size and direction of characters. settextstyle(int font, int direction, int size); Ashim Lamichhane 20
  • 21. • pieslice(): draws a sector with current color and font setting pieslice(int x,int y,int startAngle,int endAngle, int r); • bar(): • draws bar diagram using two points left-top corner and bottom corner bar(int left, int top, int right, int bottom); • getmaxx() • Returns max x value for current graphics driver and mode integer_variable=getmaxx() • getmaxy() • Returns max y value for current graphics driver and mode integer_variable=getmaxy() Ashim Lamichhane 21