SlideShare a Scribd company logo
1 of 13
Download to read offline
Graphics Under C/IITM/Shakoor Ab-2012 Page 1
Graphics under C
Graphics modes
Graphics mode is a way of displaying images on a computer screen or other
graphics device such that the basic unit is the pixel. Lines and characters
on the screen are drawn pixel by pixel. The resolution and complexity of the
image depends on how many pixels there are in total, and how many bits are
assigned to each pixel. The more bits per pixel, the more different colors
or shades of gray. A single graphics device can operate in a number of
different graphics modes with different resolutions and color selections. A
common mode for a desktop PC would be 1024 by 768 pixels with 256 different
colors – chosen from a much larger number – available for each pixel.
Many video adapters support several different modes of resolution, all of
which are divided into two general categories: character mode and graphics
mode.
Of the two modes, graphics mode is the more sophisticated. Programs that
run in graphics mode can display an unlimited variety of shapes and fonts,
whereas programs running in character mode are severely limited. Programs
that run entirely in graphics mode are called graphics-based programs.
In character mode, the display screen is treated as an array of blocks, each
of which can hold one ASCII character. In graphics mode, the display screen
is treated as an array of pixels. Characters and other shapes are formed by
turning on combinations of pixels.
Graphics Under C/IITM/Shakoor Ab-2012 Page 2
 initgraph():Initialize the Graphics System
#include <graphics.h>
void far initgraph(gdriver,gmode,dpath);
int far *gdriver; /* graphics driver */
int far *gmode; /* graphics mode */
char far *dpath; /* directory path of driver*/
initgraph() is a graphics system control function. It is used to
initialize the graphics system. It should be the first graphics
function called. initgraph() loads the graphics driver, after
allocating memory for it, then puts the system in graphics mode.
initgraph() can be used in either of two ways: 'gdriver' must be set
to one of the constants:
CONSTANT NUMERIC VALUE
DETECT 0
CGA 1
MCGA 2
EGA 3
EGA64 4
EGAMONO 5
IBM8514 6
HERCMONO 7
ATT400 8
VGA 9
PC3270 10
If 'gdriver' is set to DETECT (autodetection), it calls detectgraph()
and automatically selects the highest resolution graphics mode for
'gmode'. To override this selection, 'gdriver' can be set to one of
the other 10 constants in the above chart. 'gmode' can then be set
to one of the following constants (defined in <graphics.h>):
GRAPHICS
DRIVER GRAPHICS_MODES VALUE RES PALETTE PAGES
CGA CGAC0 0 320x200 C0 1
CGAC1 1 320x200 C1 1
CGAC2 2 320x200 C2 1
CGAC3 3 320x200 C3 1
CGAHI 4 640x200 2 color 1
MCGA MCGAC0 0 320x200 C0 1
MCGAC1 1 320x200 C1 1
MCGAC2 2 320x200 C2 1
MCGAC3 3 320x200 C3 1
MCGAMED 4 640x200 2 color 1
MCGAHI 5 640x480 2 color 1
EGA EGALO 0 640x200 16 color 4
EGAHI 1 640x350 16 color 2
EGA64 EGA64LO 0 640x200 16 color 1
EGA64HI 1 640x350 4 color 1
Graphics Under C/IITM/Shakoor Ab-2012 Page 3
EGAMONO EGAMONOHI 3 640x350 2 color 1*
EGAMONOHI 3 640x350 2 color 4**
HERCMONO HERCMONOHI 0 720x348 2 color 2
ATT400 ATT400C0 0 320x200 C0 1
ATT400C1 1 320x200 C1 1
ATT400C2 2 320x200 C2 1
ATT400C3 3 320x200 C3 1
ATT400MED 4 640x200 2 color 1
ATT400HI 5 640x400 2 color 1
VGA VGALO 0 640x200 16 color 4
VGAMED 1 640x350 16 color 2
VGAHI 2 640x480 16 color 1
PC3270 PC3270HI 0 720x350 2 color 1
IBM8514 IBM8514HI 0 640x480 256 colors
IBM8514LO 1 1024x768 256 colors
*64K EGAMONO card
**256K EGAMONO card
'dpath' names the directory path where the graphic driver files are
located. If they are not found in 'dpath' or 'dpath' is NULL, the
current directory is searched.
When initgraph() is called, all graphic settings (current position,
palette, color, etc) are reset to their defaults. graphresult()
(which returns graphic error code) is reset to 0.
Returns: Nothing. initgraph() always sets the internal error code.
On success, graphresult() returns 0. On error,
graphresult() (and 'gdriver') returns:
-2 Cannot find a graphics card
-3 Cannot find a driver file
-4 Invalid driver
-5 Insufficient memory to load driver
Notes: closegraph() should be called to shut down the graphics
system. A call to closegraph() restores the screen to
the mode it was in before initgraph() was called.
 Overview of Graphics System
There are many new graphics functions in C. They are all in the
library, GRAPHICS.LIB. These functions allow you to control the
graphics system, manipulate screens and viewports, output text to the
graphics screen, draw and fill shapes, control the background and
foreground color, handle graphics errors and inquire into the state of
the graphics system.
In order to use these graphics functions, you must
Graphics Under C/IITM/Shakoor Ab-2012 Page 4
(1) include <graphics.h> in your program,
(2) initialize the graphics system and put it in the
graphics mode,
(3) shut down the graphics system.
Therefore, programs using graphics functions should have the
following as a basic framework:
#include <graphics.h>
main()
{
int graphdriver = DETECT, graphmode;
initgraph();
/* graphics functions */
closegraph();
}
 arc():Draw a Circular Arc
#include <graphics.h>
void far arc(x,y,start,end,rad);
int x;
int y;
int start, end;
int rad;
arc() draws the outline of an arc in the current drawing color. The
circular arc is centered at 'x','y' with a radius of 'rad'. The arc
travels from 'start' to 'end.
 bar():Draw and Fills a Bar
#include <graphics.h>
void far bar(l,t,r,b);
int l;
int t;
int r;
int b;
bar() draws and fills in a rectangular bar. The bar is drawn using
the upper left coordinates ('l','t') and the lower right coordinates
('r','b'). The current fill pattern and fill color is used to fill
in the bar. The bar is not outlined.
 bar3d():Draw and Fills a 3-Dimensional Bar
#include <graphics.h>
Graphics Under C/IITM/Shakoor Ab-2012 Page 5
void far bar3d(l,t,r,b,depth,tflag);
int l;
int t;
int r;
int b;
int depth;
int tflag;
bar3d() draws and fills in a three-dimensional rectangular bar. The
bar is drawn using the upper left coordinates ('l','t') and the lower
right coordinates ('r','b'). The current fill pattern and fill color
is used to fill in the bar. The bar is outlined using the current
line style and color. 'depth' determines the bar's depth. 'tflag'
not equal to zero signals that a three-dimensional top is to be put
on the bar.
 circle():Draw a Circle
#include <graphics.h>
voidfar circle(x,y,rad);
int x;
int y;
int rad;
circle() draws a circle. Its center is at coordinates ('x','y') and
its radius is 'rad'.
 cleardevice():Clear the Graphics Screen
#include <graphics.h>
void far cleardevice(void);
cleardevice() erases the entire graphics screen and moves the current
position (CP) to home position which is the upper left hand corner of
the screen with coordinates (0,0). All other graphics system
settings, such as the viewport settings, the line settings, the style
settings, etc., remain the same.
 clearviewport():Erase the Current Viewport
#include <graphics.h>
void far clearviewport(void);
clearviewport() clears the current viewport. The current position
(CP) is returned to home position (0,0).
 closegraph():Shut Down the Graphics System
#include <graphics.h>
Graphics Under C/IITM/Shakoor Ab-2012 Page 6
void far closegraph(void);
closegraph() shuts down the graphics system by deallocating all the
memory that was allocated by initgraph(). The screen is restored to
the mode it was in before initgraph() was called. closegraph() is a
graphics system control function and should be the last graphics
function called.
drawpoly():Draw a Polygon
#include <graphics.h>
void far drawpoly(npoint,ppoints);
int npoint;
int far *ppoints;
drawpoly() draws a polygon with 'npoint' points. 'ppoints' points to
a sequence of pairs of integers. Each pair of integers represents the
('x','y') coordinates of 'npoint'.
There should be twice as many 'ppoints' as 'npoint'. You must always
'close' the polygon you are drawing, by repeating the first
coordinates given. (A triangle, with three points, should have four
sets of coordinates, the fourth being the same as the first.) The
polygon is drawn using the current line style and color.
 ellipse():Draw an Elliptical Arc
#include <graphics.h>
void far ellipse(x,y,start,end,xrad,yrad);
int x, y;
int start, end;
int xrad, yrad;
ellipse() draws an elliptical arc. ('x','y') are the coordinates of
its center. 'xrad' is the horizontal axis and 'yrad' is the vertical
axis. The ellipse is drawn from 'start' to 'end'. (To draw a
complete ellipse, 'start' = 0 and 'end' = 360.)
 fillellipse():Draw and Fill and Ellipse
#include <graphics.h>
void far fillellipse(x, y, xrad, yrad);
int x, y; Center point
int xrad; Horizontal radius
int yrad; Vertical radius
This function draws and fills an ellipse with center point at
(x, y), horizontal radius xrad, and vertical radius yrad. The
current fill color is used.
Graphics Under C/IITM/Shakoor Ab-2012 Page 7
 floodfill():Fill a Bounded Region
#include <graphics.h>
void far floodfill(x,y,border);
int x;
int y;
int border;
floodfill() fills figures drawn using arc(), circle(), ellipse(),
drawpoly(), line(), lineto(), linerel() and rectangle(). The bounded
area is filled with the current fill pattern and fill color. The
coordinates ('x','y') represent a point within the area to be
flooded. If the point is within an enclosed area, the area inside
the border will be filled. If the point is outside an enclosed area,
the area outside the border will be filled.
 getbkcolor():Get the Current Background Color
#include <graphics.h>
int far getbkcolor(void);
getbkcolor() returns the current background color which can be one of
the following values defined in <graphics.h>
 getcolor():Get the Current Drawing Color
#include <graphics.h>
int far getcolor(void);
getcolor() returns the current drawing color. The value returned is
actually an index into the palette which contains the exact color
information. Pixels on the screen are set to this value when lines
or figures are drawn.
 getgraphmode():Get the Current Graphics Mode
#include <graphics.h>
int far getgraphmode(void);
getgraphmode() returns the current graphics mode set by a previously
successful call to initgraph() or setgraphmode(). With the current
graphics mode stored in a temporary variable, the system can be set
to various graphics modes supported by the driver, or to text mode,
and then restored via setgraphmode().
 getmaxcolor():Get the Maximum Color Value for Current
Mode
#include <graphics.h>
Graphics Under C/IITM/Shakoor Ab-2012 Page 8
int far getmaxcolor(void);
getmaxcolor() returns the highest valid pixel value for the current
graphics driver and mode. A pixel value is an index into a color
table called a 'palette'. The range of pixel values (0 - (size-1))
is determined by the size of the palette.
 getmaxx():Get the Current x Resolution
#include <graphics.h>
int far getmaxx(void);
getmaxx() returns the maximum x screen coordinate for the current
graphics mode. This function is very useful for positioning text and
graphics on the screen.
 getmaxy():Get the Current y Resolution
#include <graphics.h>
int far getmaxy(void);
getmaxy() returns the maximum y screen coordinate for the current
graphics mode. This function is very useful for positioning text and
graphics on the screen.
 getdrivername():Get Current Graphics Driver Name
#include <graphics.h>
char *far getdrivername(void);
The getdrivername() function returns a pointer to a string
holding the name of the current graphics driver.
Returns: A far pointer to a string which identifies the
current driver.
 getmodename():Return Mode Name for Specified Driver
#include <graphics.h>
char * far getmodename(mode_num);
int mode_num; Mode you want information about
The getmodename() function returns a pointer to a string which
contains the name of the indicated graphics mode, as specified
by mode_num.
 getpixel():Get the Color of the Given Pixel
Graphics Under C/IITM/Shakoor Ab-2012 Page 9
#include <graphics.h>
unsigned far getpixel(x,y);
int x;
int y;
getpixel() gets the color of the pixel specified by coordinates
('x','y').
Returns: The color of the specified pixel.
 line():Draw a Line
#include <graphics.h>
void far line(x1,y1,x2,y2);
int x1,y1;
int x2,y2;
line() draws a line between two specified points, ('x1','y1'), and
('x2','y2'). The line is drawn in the current color, line style and
thickness. The current position (CP) in not affected by a call to
this function.
 outtextxy():Output a String to Screen at Specified
Position
#include <graphics.h>
void far outtextxy(x,y,tstring);
int x;
int y;
char far *tstring;
outtextxy() outputs graphics text at the specified position ('x','y')
relative to the current viewport. The text is output using the
current text font, text direction, character size and text
justification settings. (See settextstyle() and settextjustify() for
more information regarding these text attributes.)
 pieslice():Draw a Pieslice
#include <graphics.h>
void far pieslice(x,y,stangle,endangle,radius);
int x;
int y;
int stangle, endangle;
int radius;
pieslice() draws a pieslice shape with the center at ('x','y') and
with a radius 'radius'. The slice starts at 'stangle' and goes
counterclockwise toward 'endangle'. 0 degrees is at 3 o'clock and 90
degrees is at 12 o'clock.
Graphics Under C/IITM/Shakoor Ab-2012 Page 10
 putpixel():Plot a Pixel at Specified Coordinates
#include <graphics.h>
void putpixel(x,y,pcolor);
int x;
int y;
int pcolor;
putpixel() draws a pixel at the specified coordinates ('x','y'). The
pixel is displayed in the color 'pcolor'.
 rectangle():Draw a Rectangle
#include <graphics.h>
void far rectangle(l,t,r,b);
int l;
int t;
int r;
int b;
rectangle() draws a rectangle at the given coordinates, 'l' left, 't'
top, 'r' right, and 'b' bottom. The rectangle is drawn using the
current color, line style and thickness.
 sector():Draw an Elliptical Sector
#include <graphics.h>
void far sector(x, y, stangle, endangle, xradius, yradius);
int x, y; Center point
int stangle, Starting angle
int endangle; Ending angle
int xradius; Horizontal radius
int yradius; Vertical radius
This function is the same as pieslice, except that it draws an
elliptical pie slice. The center point is at (x, y), stangle
and endangle are the starting and ending angles, the
horizontal radius is xradius, and the vertical radius is
yradius.
 setbkcolor():Set the Background Color
#include <graphics.h>
void far setbkcolor(color);
int color;
setbkcolor() sets the current background color which can be one of
the following values defined in <graphics.h>:
Value Name
Graphics Under C/IITM/Shakoor Ab-2012 Page 11
0 BLACK
1 BLUE
2 GREEN
3 CYAN
4 RED
5 MAGENTA
6 BROWN
7 LIGHTGRAY
8 DARKGRAY
9 LIGHTBLUE
10 LIGHTGREEN
11 LIGHTCYAN
12 LIGHTRED
13 LIGHTMAGENTA
14 YELLOW
15 WHITE
 setcolor():Set the Current Drawing Color
#include <graphics.h>
void far setcolor(color);
int color;
setcolor() sets the current drawing color to 'color', which
represents an index into the palette. The range of values 'color'
can have is determined by the size of the palette. getmaxcolor() will
return the highest possible color value, which is (size-1).
Therefore, the range of possible color values is 0 to (size-1).
 setfillstyle():Set the Fill Pattern and Fill Color
#include <graphics.h>
void far setfillstyle(pattern,color);
int pattern;
int color;
setfillstyle() sets the current fill pattern and fill color used by
bar(), bar3d(), fillpoly(), floodfill() and pieslice(). There are 11
predefined fill patterns. In addition you can fill a shape in with
the background color or a user-defined pattern. The names for the
predefined patterns are found in 'fill_patterns' in <graphics.h>:
Name Value Description
EMPTY_FILL 0 Fill with background color
SOLID_FILL 1 Solid fill
LINE_FILL 2 Fill with horizontal lines
LTSLASH_FILL 3 Fill with ///, regular lines
SLASH_FILL 4 Fill with ///, thick lines
BKSLASH_FILL 5 Fill with , thick lines
LTBKSLASH_FILL 6 Fill with , regular lines
HATCH_FILL 7 Fill with hatch fill
XHATCH_FILL 8 Fill with heavy hatch fill
INTERLEAVE_FILL 9 Interleaving line fill
WIDE_DOT_FILL 10 Widely spaced dot fill
CLOSE_DOT_FILL 11 Closely spaced dot fill
Graphics Under C/IITM/Shakoor Ab-2012 Page 12
USER_FILL 12 User-defined fill pattern
All patterns except EMPTY_FILL use the current fill color.
 settextstyle():Set Current Text Font, Direction and
Size
#include <graphics.h>
void far settextstyle(font,dir,charsize);
int font;
int dir;
int charsize;
settextstyle() sets the current text font, direction and character
size. All calls to outtext() and outtextxy() are affected by the new
settings.
The graphics library includes an 8x8 bit-mapped font, in which each
character is defined by a matrix of pixels, and several stroked
fonts, in which each character is defined by a series of vectors
which determine how that character is drawn.
'font' can be an 8x8 bit-mapped font or one of several "stroked"
fonts available. The different types of fonts available are defined
in the enumeration 'font_names', defined in <graphics.h> as:
Name Value Description
DEFAULT_FONT 0 8x8 bit_mapped font
TRIPLEX_FONT 1 Stroked triplex font
SMALL_FONT 2 Stroked small font
SANS_SERIF_FONT 3 Stroked sans-serif font
GOTHIC_FONT 4 Stroked gothic font
The 8x8 bit-mapped font is the default font and is always available.
The stroked fonts are kept in separate .CHR files on disk and can be
loaded at run time or converted to .OBJ files (with the BGIOBJ
utility) and linked to your .EXE files. (See registerbgifont().)
'dir' can be either horizontal text (left to right) or vertical text
(rotated 90 degrees counterclockwise). The values for 'dir' are
defined in <graphics.h> as:
Name Value Description
HORIZ_DIR 0 Left to right
VERT_DIR 1 Bottom to top
The default direction is HORIZ_DIR.
'charsize' allows each character to be magnified by a specific
factor. If 'charsize' has a value of 0, the stroked font is magnified
using the default character magnification factor of 4, or the user-
defined character size set using setusercharsize(). If 'charsize'
has a value greater than 0, the 8x8 bit-mapped or stroked font is
Graphics Under C/IITM/Shakoor Ab-2012 Page 13
magnified by that factor. (For example, if 'charsize' is 1, an 8x8
bit-mapped font is displayed in an 8x8 pixel rectangle. If
'charsize' is 2, an 8x8 bit-mapped font is displayed in a 16x16 pixel
rectangle, etc.)
settextstyle() affects all subsequent calls to outtext() and
outtextxy().
 setviewport():Set the Current Graphics Viewport
#include <graphics.h>
void far setviewport(left,top,right,bottom,clflag);
int left;
int top;
int right;
int bottom;
int clflag;
setviewport() defines a rectangular viewport, a "virtual screen", on
the screen. The viewport's position is defined in terms of absolute
screen coordinates, ('left','top'), ('right','bottom'). All
subsequent graphics output is written to this viewport. If 'clflag'
is set to a non-zero value, all drawings will be clipped or truncated
at its boundaries. initgraph() and setgraphmode() can be used to
reset the viewport to the entire screen.

More Related Content

What's hot

3D Graphics & Rendering in Computer Graphics
3D Graphics & Rendering in Computer Graphics3D Graphics & Rendering in Computer Graphics
3D Graphics & Rendering in Computer GraphicsFaraz Akhtar
 
Chapter02 graphics-programming
Chapter02 graphics-programmingChapter02 graphics-programming
Chapter02 graphics-programmingMohammed Romi
 
Introduction to computer graphics
Introduction to computer graphics Introduction to computer graphics
Introduction to computer graphics Priyodarshini Dhar
 
Line drawing algo.
Line drawing algo.Line drawing algo.
Line drawing algo.Mohd Arif
 
Unit-1 basics of computer graphics
Unit-1 basics of computer graphicsUnit-1 basics of computer graphics
Unit-1 basics of computer graphicsAmol Gaikwad
 
Mid point line Algorithm - Computer Graphics
Mid point line Algorithm - Computer GraphicsMid point line Algorithm - Computer Graphics
Mid point line Algorithm - Computer GraphicsDrishti Bhalla
 
Raster scan system & random scan system
Raster scan system & random scan systemRaster scan system & random scan system
Raster scan system & random scan systemshalinikarunakaran1
 
Monitors & workstation,Donald ch-2
Monitors & workstation,Donald ch-2Monitors & workstation,Donald ch-2
Monitors & workstation,Donald ch-2Iftikhar Ahmad
 
Lab report for Prolog program in artificial intelligence.
Lab report for Prolog program in artificial intelligence.Lab report for Prolog program in artificial intelligence.
Lab report for Prolog program in artificial intelligence.Alamgir Hossain
 
Definition of automation,finite automata,transition system
Definition of automation,finite automata,transition systemDefinition of automation,finite automata,transition system
Definition of automation,finite automata,transition systemDr. ABHISHEK K PANDEY
 
Bca sem 6 php practicals 1to12
Bca sem 6 php practicals 1to12Bca sem 6 php practicals 1to12
Bca sem 6 php practicals 1to12Hitesh Patel
 
Computer graphics lab assignment
Computer graphics lab assignmentComputer graphics lab assignment
Computer graphics lab assignmentAbdullah Al Shiam
 
Unit 3
Unit 3Unit 3
Unit 3ypnrao
 
computer graphics
computer graphicscomputer graphics
computer graphicsMegabi Mamo
 
Devices that output Hardcopy
Devices that output HardcopyDevices that output Hardcopy
Devices that output HardcopyMaryam Fida
 
JavaScript - Chapter 13 - Browser Object Model(BOM)
JavaScript - Chapter 13 - Browser Object Model(BOM)JavaScript - Chapter 13 - Browser Object Model(BOM)
JavaScript - Chapter 13 - Browser Object Model(BOM)WebStackAcademy
 

What's hot (20)

3D Graphics & Rendering in Computer Graphics
3D Graphics & Rendering in Computer Graphics3D Graphics & Rendering in Computer Graphics
3D Graphics & Rendering in Computer Graphics
 
Chapter02 graphics-programming
Chapter02 graphics-programmingChapter02 graphics-programming
Chapter02 graphics-programming
 
Introduction to computer graphics
Introduction to computer graphics Introduction to computer graphics
Introduction to computer graphics
 
Line drawing algo.
Line drawing algo.Line drawing algo.
Line drawing algo.
 
Unit-1 basics of computer graphics
Unit-1 basics of computer graphicsUnit-1 basics of computer graphics
Unit-1 basics of computer graphics
 
Introduction to graphics programming in c
Introduction to graphics programming in cIntroduction to graphics programming in c
Introduction to graphics programming in c
 
Mid point line Algorithm - Computer Graphics
Mid point line Algorithm - Computer GraphicsMid point line Algorithm - Computer Graphics
Mid point line Algorithm - Computer Graphics
 
UNIT-IV
UNIT-IVUNIT-IV
UNIT-IV
 
Raster scan system & random scan system
Raster scan system & random scan systemRaster scan system & random scan system
Raster scan system & random scan system
 
Monitors & workstation,Donald ch-2
Monitors & workstation,Donald ch-2Monitors & workstation,Donald ch-2
Monitors & workstation,Donald ch-2
 
Lab report for Prolog program in artificial intelligence.
Lab report for Prolog program in artificial intelligence.Lab report for Prolog program in artificial intelligence.
Lab report for Prolog program in artificial intelligence.
 
Definition of automation,finite automata,transition system
Definition of automation,finite automata,transition systemDefinition of automation,finite automata,transition system
Definition of automation,finite automata,transition system
 
Unit 11. Graphics
Unit 11. GraphicsUnit 11. Graphics
Unit 11. Graphics
 
Bca sem 6 php practicals 1to12
Bca sem 6 php practicals 1to12Bca sem 6 php practicals 1to12
Bca sem 6 php practicals 1to12
 
Computer graphics lab assignment
Computer graphics lab assignmentComputer graphics lab assignment
Computer graphics lab assignment
 
Unit 3
Unit 3Unit 3
Unit 3
 
computer graphics
computer graphicscomputer graphics
computer graphics
 
Computer Graphics
Computer GraphicsComputer Graphics
Computer Graphics
 
Devices that output Hardcopy
Devices that output HardcopyDevices that output Hardcopy
Devices that output Hardcopy
 
JavaScript - Chapter 13 - Browser Object Model(BOM)
JavaScript - Chapter 13 - Browser Object Model(BOM)JavaScript - Chapter 13 - Browser Object Model(BOM)
JavaScript - Chapter 13 - Browser Object Model(BOM)
 

Viewers also liked

Computer Graphics Practical
Computer Graphics PracticalComputer Graphics Practical
Computer Graphics PracticalNeha Sharma
 
Computer Graphics Applications
Computer Graphics ApplicationsComputer Graphics Applications
Computer Graphics ApplicationsSaravana Priya
 
SAMPLING AND SAMPLING ERRORS
SAMPLING AND SAMPLING ERRORSSAMPLING AND SAMPLING ERRORS
SAMPLING AND SAMPLING ERRORSrambhu21
 
C graphics programs file
C graphics programs fileC graphics programs file
C graphics programs fileshubham kanojia
 
Computer Graphics Concepts
Computer Graphics ConceptsComputer Graphics Concepts
Computer Graphics ConceptsSHAKOOR AB
 
1 c – graphic designs
1 c – graphic designs1 c – graphic designs
1 c – graphic designsHaseeb Patel
 
Computer graphics
Computer graphicsComputer graphics
Computer graphicsamitsarda3
 
C standard library functions
C standard library functionsC standard library functions
C standard library functionsVaishnavee Sharma
 
Programming with c language practical manual
Programming with c language practical manualProgramming with c language practical manual
Programming with c language practical manualAnil Bishnoi
 
Visual Communication Design Principles
Visual Communication Design PrinciplesVisual Communication Design Principles
Visual Communication Design Principlesstoryviz
 
Presentation on C++ Programming Language
Presentation on C++ Programming LanguagePresentation on C++ Programming Language
Presentation on C++ Programming Languagesatvirsandhu9
 
Macromedia flash presentation2
Macromedia flash presentation2Macromedia flash presentation2
Macromedia flash presentation2Zeeshan Ahmed
 
COMPUTER GRAPHICS LAB MANUAL
COMPUTER GRAPHICS LAB MANUALCOMPUTER GRAPHICS LAB MANUAL
COMPUTER GRAPHICS LAB MANUALVivek Kumar Sinha
 
Intro to Adobe Flash
Intro to Adobe FlashIntro to Adobe Flash
Intro to Adobe FlashStaci Trekles
 
Factory cost reduction strategies
Factory cost reduction strategiesFactory cost reduction strategies
Factory cost reduction strategiesBakeryBazar .com
 
Waste Management in Garment Industries
Waste Management in Garment IndustriesWaste Management in Garment Industries
Waste Management in Garment IndustriesShubha Brota Raha
 
Lecture on graphics
Lecture on graphicsLecture on graphics
Lecture on graphicsRafi_Dar
 

Viewers also liked (20)

Computer Graphics Practical
Computer Graphics PracticalComputer Graphics Practical
Computer Graphics Practical
 
Graphics in C++
Graphics in C++Graphics in C++
Graphics in C++
 
Computer Graphics Applications
Computer Graphics ApplicationsComputer Graphics Applications
Computer Graphics Applications
 
Computer Graphics
Computer GraphicsComputer Graphics
Computer Graphics
 
SAMPLING AND SAMPLING ERRORS
SAMPLING AND SAMPLING ERRORSSAMPLING AND SAMPLING ERRORS
SAMPLING AND SAMPLING ERRORS
 
C graphics programs file
C graphics programs fileC graphics programs file
C graphics programs file
 
Computer Graphics Concepts
Computer Graphics ConceptsComputer Graphics Concepts
Computer Graphics Concepts
 
1 c – graphic designs
1 c – graphic designs1 c – graphic designs
1 c – graphic designs
 
Computer graphics
Computer graphicsComputer graphics
Computer graphics
 
C standard library functions
C standard library functionsC standard library functions
C standard library functions
 
Programming with c language practical manual
Programming with c language practical manualProgramming with c language practical manual
Programming with c language practical manual
 
Mini Scratch Unit
Mini Scratch UnitMini Scratch Unit
Mini Scratch Unit
 
Visual Communication Design Principles
Visual Communication Design PrinciplesVisual Communication Design Principles
Visual Communication Design Principles
 
Presentation on C++ Programming Language
Presentation on C++ Programming LanguagePresentation on C++ Programming Language
Presentation on C++ Programming Language
 
Macromedia flash presentation2
Macromedia flash presentation2Macromedia flash presentation2
Macromedia flash presentation2
 
COMPUTER GRAPHICS LAB MANUAL
COMPUTER GRAPHICS LAB MANUALCOMPUTER GRAPHICS LAB MANUAL
COMPUTER GRAPHICS LAB MANUAL
 
Intro to Adobe Flash
Intro to Adobe FlashIntro to Adobe Flash
Intro to Adobe Flash
 
Factory cost reduction strategies
Factory cost reduction strategiesFactory cost reduction strategies
Factory cost reduction strategies
 
Waste Management in Garment Industries
Waste Management in Garment IndustriesWaste Management in Garment Industries
Waste Management in Garment Industries
 
Lecture on graphics
Lecture on graphicsLecture on graphics
Lecture on graphics
 

Similar to C Graphics Functions

Computer graphics
Computer graphics Computer graphics
Computer graphics shafiq sangi
 
Computer graphics practical(jainam)
Computer graphics practical(jainam)Computer graphics practical(jainam)
Computer graphics practical(jainam)JAINAM KAPADIYA
 
Circles graphic
Circles graphicCircles graphic
Circles graphicalldesign
 
Computer graphics
Computer graphicsComputer graphics
Computer graphicssnelkoli
 
Introduction to Computer graphics
Introduction to Computer graphicsIntroduction to Computer graphics
Introduction to Computer graphicsLOKESH KUMAR
 
Introduction to Coding
Introduction to CodingIntroduction to Coding
Introduction to CodingFabio506452
 
Skia & Freetype - Android 2D Graphics Essentials
Skia & Freetype - Android 2D Graphics EssentialsSkia & Freetype - Android 2D Graphics Essentials
Skia & Freetype - Android 2D Graphics EssentialsKyungmin Lee
 
Creating an Uber Clone - Part IV - Transcript.pdf
Creating an Uber Clone - Part IV - Transcript.pdfCreating an Uber Clone - Part IV - Transcript.pdf
Creating an Uber Clone - Part IV - Transcript.pdfShaiAlmog1
 
bfd23fd7-0d89-45c0-8b82-c991b30ed375.pdf
bfd23fd7-0d89-45c0-8b82-c991b30ed375.pdfbfd23fd7-0d89-45c0-8b82-c991b30ed375.pdf
bfd23fd7-0d89-45c0-8b82-c991b30ed375.pdfshehabhamad_90
 
Java Graphics
Java GraphicsJava Graphics
Java GraphicsShraddha
 
Graphic Design Lab File.docx
Graphic Design Lab File.docxGraphic Design Lab File.docx
Graphic Design Lab File.docxPayalJindal19
 
computer graphics-C/C++-dancingdollcode
computer graphics-C/C++-dancingdollcodecomputer graphics-C/C++-dancingdollcode
computer graphics-C/C++-dancingdollcodeBhavya Chawla
 
unit1_updated.pptx
unit1_updated.pptxunit1_updated.pptx
unit1_updated.pptxRYZEN14
 
Snake Game on FPGA in Verilog
Snake Game on FPGA in VerilogSnake Game on FPGA in Verilog
Snake Game on FPGA in VerilogKrishnajith S S
 
426 lecture 4: AR Developer Tools
426 lecture 4: AR Developer Tools426 lecture 4: AR Developer Tools
426 lecture 4: AR Developer ToolsMark Billinghurst
 
Trident International Graphics Workshop 2014 1/5
Trident International Graphics Workshop 2014 1/5Trident International Graphics Workshop 2014 1/5
Trident International Graphics Workshop 2014 1/5Takao Wada
 

Similar to C Graphics Functions (20)

Computer graphics
Computer graphics Computer graphics
Computer graphics
 
Computer graphics practical(jainam)
Computer graphics practical(jainam)Computer graphics practical(jainam)
Computer graphics practical(jainam)
 
Circles graphic
Circles graphicCircles graphic
Circles graphic
 
Chapter 1
Chapter 1Chapter 1
Chapter 1
 
Computer graphics
Computer graphicsComputer graphics
Computer graphics
 
Introduction to Computer graphics
Introduction to Computer graphicsIntroduction to Computer graphics
Introduction to Computer graphics
 
Introduction to Coding
Introduction to CodingIntroduction to Coding
Introduction to Coding
 
Cg lab cse-v (1) (1)
Cg lab cse-v (1) (1)Cg lab cse-v (1) (1)
Cg lab cse-v (1) (1)
 
Skia & Freetype - Android 2D Graphics Essentials
Skia & Freetype - Android 2D Graphics EssentialsSkia & Freetype - Android 2D Graphics Essentials
Skia & Freetype - Android 2D Graphics Essentials
 
Graphics mod
Graphics modGraphics mod
Graphics mod
 
Creating an Uber Clone - Part IV - Transcript.pdf
Creating an Uber Clone - Part IV - Transcript.pdfCreating an Uber Clone - Part IV - Transcript.pdf
Creating an Uber Clone - Part IV - Transcript.pdf
 
bfd23fd7-0d89-45c0-8b82-c991b30ed375.pdf
bfd23fd7-0d89-45c0-8b82-c991b30ed375.pdfbfd23fd7-0d89-45c0-8b82-c991b30ed375.pdf
bfd23fd7-0d89-45c0-8b82-c991b30ed375.pdf
 
Java Graphics
Java GraphicsJava Graphics
Java Graphics
 
Graphic Design Lab File.docx
Graphic Design Lab File.docxGraphic Design Lab File.docx
Graphic Design Lab File.docx
 
computer graphics-C/C++-dancingdollcode
computer graphics-C/C++-dancingdollcodecomputer graphics-C/C++-dancingdollcode
computer graphics-C/C++-dancingdollcode
 
unit1_updated.pptx
unit1_updated.pptxunit1_updated.pptx
unit1_updated.pptx
 
Snake Game on FPGA in Verilog
Snake Game on FPGA in VerilogSnake Game on FPGA in Verilog
Snake Game on FPGA in Verilog
 
426 lecture 4: AR Developer Tools
426 lecture 4: AR Developer Tools426 lecture 4: AR Developer Tools
426 lecture 4: AR Developer Tools
 
Applet life cycle
Applet life cycleApplet life cycle
Applet life cycle
 
Trident International Graphics Workshop 2014 1/5
Trident International Graphics Workshop 2014 1/5Trident International Graphics Workshop 2014 1/5
Trident International Graphics Workshop 2014 1/5
 

Recently uploaded

The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxGenerative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxfnnc6jmgwh
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesThousandEyes
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsNathaniel Shimoni
 
React Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkReact Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkPixlogix Infotech
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...itnewsafrica
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPathCommunity
 
Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...itnewsafrica
 
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security ObservabilityGlenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security Observabilityitnewsafrica
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Alkin Tezuysal
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality AssuranceInflectra
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterMydbops
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationKnoldus Inc.
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityIES VE
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsRavi Sanghani
 

Recently uploaded (20)

The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxGenerative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directions
 
React Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkReact Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App Framework
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to Hero
 
Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...
 
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security ObservabilityGlenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL Router
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog Presentation
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a reality
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and Insights
 

C Graphics Functions

  • 1. Graphics Under C/IITM/Shakoor Ab-2012 Page 1 Graphics under C Graphics modes Graphics mode is a way of displaying images on a computer screen or other graphics device such that the basic unit is the pixel. Lines and characters on the screen are drawn pixel by pixel. The resolution and complexity of the image depends on how many pixels there are in total, and how many bits are assigned to each pixel. The more bits per pixel, the more different colors or shades of gray. A single graphics device can operate in a number of different graphics modes with different resolutions and color selections. A common mode for a desktop PC would be 1024 by 768 pixels with 256 different colors – chosen from a much larger number – available for each pixel. Many video adapters support several different modes of resolution, all of which are divided into two general categories: character mode and graphics mode. Of the two modes, graphics mode is the more sophisticated. Programs that run in graphics mode can display an unlimited variety of shapes and fonts, whereas programs running in character mode are severely limited. Programs that run entirely in graphics mode are called graphics-based programs. In character mode, the display screen is treated as an array of blocks, each of which can hold one ASCII character. In graphics mode, the display screen is treated as an array of pixels. Characters and other shapes are formed by turning on combinations of pixels.
  • 2. Graphics Under C/IITM/Shakoor Ab-2012 Page 2  initgraph():Initialize the Graphics System #include <graphics.h> void far initgraph(gdriver,gmode,dpath); int far *gdriver; /* graphics driver */ int far *gmode; /* graphics mode */ char far *dpath; /* directory path of driver*/ initgraph() is a graphics system control function. It is used to initialize the graphics system. It should be the first graphics function called. initgraph() loads the graphics driver, after allocating memory for it, then puts the system in graphics mode. initgraph() can be used in either of two ways: 'gdriver' must be set to one of the constants: CONSTANT NUMERIC VALUE DETECT 0 CGA 1 MCGA 2 EGA 3 EGA64 4 EGAMONO 5 IBM8514 6 HERCMONO 7 ATT400 8 VGA 9 PC3270 10 If 'gdriver' is set to DETECT (autodetection), it calls detectgraph() and automatically selects the highest resolution graphics mode for 'gmode'. To override this selection, 'gdriver' can be set to one of the other 10 constants in the above chart. 'gmode' can then be set to one of the following constants (defined in <graphics.h>): GRAPHICS DRIVER GRAPHICS_MODES VALUE RES PALETTE PAGES CGA CGAC0 0 320x200 C0 1 CGAC1 1 320x200 C1 1 CGAC2 2 320x200 C2 1 CGAC3 3 320x200 C3 1 CGAHI 4 640x200 2 color 1 MCGA MCGAC0 0 320x200 C0 1 MCGAC1 1 320x200 C1 1 MCGAC2 2 320x200 C2 1 MCGAC3 3 320x200 C3 1 MCGAMED 4 640x200 2 color 1 MCGAHI 5 640x480 2 color 1 EGA EGALO 0 640x200 16 color 4 EGAHI 1 640x350 16 color 2 EGA64 EGA64LO 0 640x200 16 color 1 EGA64HI 1 640x350 4 color 1
  • 3. Graphics Under C/IITM/Shakoor Ab-2012 Page 3 EGAMONO EGAMONOHI 3 640x350 2 color 1* EGAMONOHI 3 640x350 2 color 4** HERCMONO HERCMONOHI 0 720x348 2 color 2 ATT400 ATT400C0 0 320x200 C0 1 ATT400C1 1 320x200 C1 1 ATT400C2 2 320x200 C2 1 ATT400C3 3 320x200 C3 1 ATT400MED 4 640x200 2 color 1 ATT400HI 5 640x400 2 color 1 VGA VGALO 0 640x200 16 color 4 VGAMED 1 640x350 16 color 2 VGAHI 2 640x480 16 color 1 PC3270 PC3270HI 0 720x350 2 color 1 IBM8514 IBM8514HI 0 640x480 256 colors IBM8514LO 1 1024x768 256 colors *64K EGAMONO card **256K EGAMONO card 'dpath' names the directory path where the graphic driver files are located. If they are not found in 'dpath' or 'dpath' is NULL, the current directory is searched. When initgraph() is called, all graphic settings (current position, palette, color, etc) are reset to their defaults. graphresult() (which returns graphic error code) is reset to 0. Returns: Nothing. initgraph() always sets the internal error code. On success, graphresult() returns 0. On error, graphresult() (and 'gdriver') returns: -2 Cannot find a graphics card -3 Cannot find a driver file -4 Invalid driver -5 Insufficient memory to load driver Notes: closegraph() should be called to shut down the graphics system. A call to closegraph() restores the screen to the mode it was in before initgraph() was called.  Overview of Graphics System There are many new graphics functions in C. They are all in the library, GRAPHICS.LIB. These functions allow you to control the graphics system, manipulate screens and viewports, output text to the graphics screen, draw and fill shapes, control the background and foreground color, handle graphics errors and inquire into the state of the graphics system. In order to use these graphics functions, you must
  • 4. Graphics Under C/IITM/Shakoor Ab-2012 Page 4 (1) include <graphics.h> in your program, (2) initialize the graphics system and put it in the graphics mode, (3) shut down the graphics system. Therefore, programs using graphics functions should have the following as a basic framework: #include <graphics.h> main() { int graphdriver = DETECT, graphmode; initgraph(); /* graphics functions */ closegraph(); }  arc():Draw a Circular Arc #include <graphics.h> void far arc(x,y,start,end,rad); int x; int y; int start, end; int rad; arc() draws the outline of an arc in the current drawing color. The circular arc is centered at 'x','y' with a radius of 'rad'. The arc travels from 'start' to 'end.  bar():Draw and Fills a Bar #include <graphics.h> void far bar(l,t,r,b); int l; int t; int r; int b; bar() draws and fills in a rectangular bar. The bar is drawn using the upper left coordinates ('l','t') and the lower right coordinates ('r','b'). The current fill pattern and fill color is used to fill in the bar. The bar is not outlined.  bar3d():Draw and Fills a 3-Dimensional Bar #include <graphics.h>
  • 5. Graphics Under C/IITM/Shakoor Ab-2012 Page 5 void far bar3d(l,t,r,b,depth,tflag); int l; int t; int r; int b; int depth; int tflag; bar3d() draws and fills in a three-dimensional rectangular bar. The bar is drawn using the upper left coordinates ('l','t') and the lower right coordinates ('r','b'). The current fill pattern and fill color is used to fill in the bar. The bar is outlined using the current line style and color. 'depth' determines the bar's depth. 'tflag' not equal to zero signals that a three-dimensional top is to be put on the bar.  circle():Draw a Circle #include <graphics.h> voidfar circle(x,y,rad); int x; int y; int rad; circle() draws a circle. Its center is at coordinates ('x','y') and its radius is 'rad'.  cleardevice():Clear the Graphics Screen #include <graphics.h> void far cleardevice(void); cleardevice() erases the entire graphics screen and moves the current position (CP) to home position which is the upper left hand corner of the screen with coordinates (0,0). All other graphics system settings, such as the viewport settings, the line settings, the style settings, etc., remain the same.  clearviewport():Erase the Current Viewport #include <graphics.h> void far clearviewport(void); clearviewport() clears the current viewport. The current position (CP) is returned to home position (0,0).  closegraph():Shut Down the Graphics System #include <graphics.h>
  • 6. Graphics Under C/IITM/Shakoor Ab-2012 Page 6 void far closegraph(void); closegraph() shuts down the graphics system by deallocating all the memory that was allocated by initgraph(). The screen is restored to the mode it was in before initgraph() was called. closegraph() is a graphics system control function and should be the last graphics function called. drawpoly():Draw a Polygon #include <graphics.h> void far drawpoly(npoint,ppoints); int npoint; int far *ppoints; drawpoly() draws a polygon with 'npoint' points. 'ppoints' points to a sequence of pairs of integers. Each pair of integers represents the ('x','y') coordinates of 'npoint'. There should be twice as many 'ppoints' as 'npoint'. You must always 'close' the polygon you are drawing, by repeating the first coordinates given. (A triangle, with three points, should have four sets of coordinates, the fourth being the same as the first.) The polygon is drawn using the current line style and color.  ellipse():Draw an Elliptical Arc #include <graphics.h> void far ellipse(x,y,start,end,xrad,yrad); int x, y; int start, end; int xrad, yrad; ellipse() draws an elliptical arc. ('x','y') are the coordinates of its center. 'xrad' is the horizontal axis and 'yrad' is the vertical axis. The ellipse is drawn from 'start' to 'end'. (To draw a complete ellipse, 'start' = 0 and 'end' = 360.)  fillellipse():Draw and Fill and Ellipse #include <graphics.h> void far fillellipse(x, y, xrad, yrad); int x, y; Center point int xrad; Horizontal radius int yrad; Vertical radius This function draws and fills an ellipse with center point at (x, y), horizontal radius xrad, and vertical radius yrad. The current fill color is used.
  • 7. Graphics Under C/IITM/Shakoor Ab-2012 Page 7  floodfill():Fill a Bounded Region #include <graphics.h> void far floodfill(x,y,border); int x; int y; int border; floodfill() fills figures drawn using arc(), circle(), ellipse(), drawpoly(), line(), lineto(), linerel() and rectangle(). The bounded area is filled with the current fill pattern and fill color. The coordinates ('x','y') represent a point within the area to be flooded. If the point is within an enclosed area, the area inside the border will be filled. If the point is outside an enclosed area, the area outside the border will be filled.  getbkcolor():Get the Current Background Color #include <graphics.h> int far getbkcolor(void); getbkcolor() returns the current background color which can be one of the following values defined in <graphics.h>  getcolor():Get the Current Drawing Color #include <graphics.h> int far getcolor(void); getcolor() returns the current drawing color. The value returned is actually an index into the palette which contains the exact color information. Pixels on the screen are set to this value when lines or figures are drawn.  getgraphmode():Get the Current Graphics Mode #include <graphics.h> int far getgraphmode(void); getgraphmode() returns the current graphics mode set by a previously successful call to initgraph() or setgraphmode(). With the current graphics mode stored in a temporary variable, the system can be set to various graphics modes supported by the driver, or to text mode, and then restored via setgraphmode().  getmaxcolor():Get the Maximum Color Value for Current Mode #include <graphics.h>
  • 8. Graphics Under C/IITM/Shakoor Ab-2012 Page 8 int far getmaxcolor(void); getmaxcolor() returns the highest valid pixel value for the current graphics driver and mode. A pixel value is an index into a color table called a 'palette'. The range of pixel values (0 - (size-1)) is determined by the size of the palette.  getmaxx():Get the Current x Resolution #include <graphics.h> int far getmaxx(void); getmaxx() returns the maximum x screen coordinate for the current graphics mode. This function is very useful for positioning text and graphics on the screen.  getmaxy():Get the Current y Resolution #include <graphics.h> int far getmaxy(void); getmaxy() returns the maximum y screen coordinate for the current graphics mode. This function is very useful for positioning text and graphics on the screen.  getdrivername():Get Current Graphics Driver Name #include <graphics.h> char *far getdrivername(void); The getdrivername() function returns a pointer to a string holding the name of the current graphics driver. Returns: A far pointer to a string which identifies the current driver.  getmodename():Return Mode Name for Specified Driver #include <graphics.h> char * far getmodename(mode_num); int mode_num; Mode you want information about The getmodename() function returns a pointer to a string which contains the name of the indicated graphics mode, as specified by mode_num.  getpixel():Get the Color of the Given Pixel
  • 9. Graphics Under C/IITM/Shakoor Ab-2012 Page 9 #include <graphics.h> unsigned far getpixel(x,y); int x; int y; getpixel() gets the color of the pixel specified by coordinates ('x','y'). Returns: The color of the specified pixel.  line():Draw a Line #include <graphics.h> void far line(x1,y1,x2,y2); int x1,y1; int x2,y2; line() draws a line between two specified points, ('x1','y1'), and ('x2','y2'). The line is drawn in the current color, line style and thickness. The current position (CP) in not affected by a call to this function.  outtextxy():Output a String to Screen at Specified Position #include <graphics.h> void far outtextxy(x,y,tstring); int x; int y; char far *tstring; outtextxy() outputs graphics text at the specified position ('x','y') relative to the current viewport. The text is output using the current text font, text direction, character size and text justification settings. (See settextstyle() and settextjustify() for more information regarding these text attributes.)  pieslice():Draw a Pieslice #include <graphics.h> void far pieslice(x,y,stangle,endangle,radius); int x; int y; int stangle, endangle; int radius; pieslice() draws a pieslice shape with the center at ('x','y') and with a radius 'radius'. The slice starts at 'stangle' and goes counterclockwise toward 'endangle'. 0 degrees is at 3 o'clock and 90 degrees is at 12 o'clock.
  • 10. Graphics Under C/IITM/Shakoor Ab-2012 Page 10  putpixel():Plot a Pixel at Specified Coordinates #include <graphics.h> void putpixel(x,y,pcolor); int x; int y; int pcolor; putpixel() draws a pixel at the specified coordinates ('x','y'). The pixel is displayed in the color 'pcolor'.  rectangle():Draw a Rectangle #include <graphics.h> void far rectangle(l,t,r,b); int l; int t; int r; int b; rectangle() draws a rectangle at the given coordinates, 'l' left, 't' top, 'r' right, and 'b' bottom. The rectangle is drawn using the current color, line style and thickness.  sector():Draw an Elliptical Sector #include <graphics.h> void far sector(x, y, stangle, endangle, xradius, yradius); int x, y; Center point int stangle, Starting angle int endangle; Ending angle int xradius; Horizontal radius int yradius; Vertical radius This function is the same as pieslice, except that it draws an elliptical pie slice. The center point is at (x, y), stangle and endangle are the starting and ending angles, the horizontal radius is xradius, and the vertical radius is yradius.  setbkcolor():Set the Background Color #include <graphics.h> void far setbkcolor(color); int color; setbkcolor() sets the current background color which can be one of the following values defined in <graphics.h>: Value Name
  • 11. Graphics Under C/IITM/Shakoor Ab-2012 Page 11 0 BLACK 1 BLUE 2 GREEN 3 CYAN 4 RED 5 MAGENTA 6 BROWN 7 LIGHTGRAY 8 DARKGRAY 9 LIGHTBLUE 10 LIGHTGREEN 11 LIGHTCYAN 12 LIGHTRED 13 LIGHTMAGENTA 14 YELLOW 15 WHITE  setcolor():Set the Current Drawing Color #include <graphics.h> void far setcolor(color); int color; setcolor() sets the current drawing color to 'color', which represents an index into the palette. The range of values 'color' can have is determined by the size of the palette. getmaxcolor() will return the highest possible color value, which is (size-1). Therefore, the range of possible color values is 0 to (size-1).  setfillstyle():Set the Fill Pattern and Fill Color #include <graphics.h> void far setfillstyle(pattern,color); int pattern; int color; setfillstyle() sets the current fill pattern and fill color used by bar(), bar3d(), fillpoly(), floodfill() and pieslice(). There are 11 predefined fill patterns. In addition you can fill a shape in with the background color or a user-defined pattern. The names for the predefined patterns are found in 'fill_patterns' in <graphics.h>: Name Value Description EMPTY_FILL 0 Fill with background color SOLID_FILL 1 Solid fill LINE_FILL 2 Fill with horizontal lines LTSLASH_FILL 3 Fill with ///, regular lines SLASH_FILL 4 Fill with ///, thick lines BKSLASH_FILL 5 Fill with , thick lines LTBKSLASH_FILL 6 Fill with , regular lines HATCH_FILL 7 Fill with hatch fill XHATCH_FILL 8 Fill with heavy hatch fill INTERLEAVE_FILL 9 Interleaving line fill WIDE_DOT_FILL 10 Widely spaced dot fill CLOSE_DOT_FILL 11 Closely spaced dot fill
  • 12. Graphics Under C/IITM/Shakoor Ab-2012 Page 12 USER_FILL 12 User-defined fill pattern All patterns except EMPTY_FILL use the current fill color.  settextstyle():Set Current Text Font, Direction and Size #include <graphics.h> void far settextstyle(font,dir,charsize); int font; int dir; int charsize; settextstyle() sets the current text font, direction and character size. All calls to outtext() and outtextxy() are affected by the new settings. The graphics library includes an 8x8 bit-mapped font, in which each character is defined by a matrix of pixels, and several stroked fonts, in which each character is defined by a series of vectors which determine how that character is drawn. 'font' can be an 8x8 bit-mapped font or one of several "stroked" fonts available. The different types of fonts available are defined in the enumeration 'font_names', defined in <graphics.h> as: Name Value Description DEFAULT_FONT 0 8x8 bit_mapped font TRIPLEX_FONT 1 Stroked triplex font SMALL_FONT 2 Stroked small font SANS_SERIF_FONT 3 Stroked sans-serif font GOTHIC_FONT 4 Stroked gothic font The 8x8 bit-mapped font is the default font and is always available. The stroked fonts are kept in separate .CHR files on disk and can be loaded at run time or converted to .OBJ files (with the BGIOBJ utility) and linked to your .EXE files. (See registerbgifont().) 'dir' can be either horizontal text (left to right) or vertical text (rotated 90 degrees counterclockwise). The values for 'dir' are defined in <graphics.h> as: Name Value Description HORIZ_DIR 0 Left to right VERT_DIR 1 Bottom to top The default direction is HORIZ_DIR. 'charsize' allows each character to be magnified by a specific factor. If 'charsize' has a value of 0, the stroked font is magnified using the default character magnification factor of 4, or the user- defined character size set using setusercharsize(). If 'charsize' has a value greater than 0, the 8x8 bit-mapped or stroked font is
  • 13. Graphics Under C/IITM/Shakoor Ab-2012 Page 13 magnified by that factor. (For example, if 'charsize' is 1, an 8x8 bit-mapped font is displayed in an 8x8 pixel rectangle. If 'charsize' is 2, an 8x8 bit-mapped font is displayed in a 16x16 pixel rectangle, etc.) settextstyle() affects all subsequent calls to outtext() and outtextxy().  setviewport():Set the Current Graphics Viewport #include <graphics.h> void far setviewport(left,top,right,bottom,clflag); int left; int top; int right; int bottom; int clflag; setviewport() defines a rectangular viewport, a "virtual screen", on the screen. The viewport's position is defined in terms of absolute screen coordinates, ('left','top'), ('right','bottom'). All subsequent graphics output is written to this viewport. If 'clflag' is set to a non-zero value, all drawings will be clipped or truncated at its boundaries. initgraph() and setgraphmode() can be used to reset the viewport to the entire screen.