SlideShare une entreprise Scribd logo
1  sur  21
Graphics and Mouse Programming
in Turbo C
Graphics in Turbo C
1
Header file for Graphics Functions
graphics.h header file is included which contain
functions to draw different shapes, display text in
different fonts, change colors, etc.
 initgraph(); Used to initialize graphics mode.
Syntax: void initgraph ( int *driver, int *mode, char *path);
Initializing Graphical mode
 graphresult(); It returns error code if occur in initializing
graphics.
Syntax: int graphresult (void);
 grapherrormsg(); It returns corresponding error message
of error code.
Syntax: char grapherrormsg (int errorcode);
 outtext(); Used to print string in graphic mode at
current position.
Syntax: void outtext (char textstring);
Displaying Text on screen
 outtextxy(); Used to print string in graphic mode at
given coordinates.
Syntax: void outtextxy (int x, int y, char textstring);
Y axis
X axis
 setcolor(); It sets the color of lines.
Syntax: void setcolor (int COLOR);
Coloring
 setbkcolor(); It sets the background color of screen.
Syntax: void setbkcolor (int COLOR);
Table of Colors
COLOR Name Value
BLACK 0
BLUE 1
GREEN 2
CYAN 3
RED 4
MAGENTA 5
BROWN 6
LIGHTGRAY 7
DARKGRAY 8
LIGHTBLUE 9
LIGHTGREEN 10
LIGHTCYAN 11
LIGHTRED 12
LIGHTMAGENTA 13
YELLOW 14
WHITE 15
COLOR Name Value
 rectangle(); It draws an empty rectangle.
Syntax: void rectangle (int x, int y, int x+width, int y+height );
Drawing empty/solid Rectangles
 bar();
It draws a filled rectangle.Syntax: void bar (int x, int y, int x+width, int y+height );
It draws a filled rectangle.
 setfillstyle(); It sets current fill pattern and fill color.
Syntax: void setfillstyle (int fillpattern, int COLOR);
Fill styling
Fill Patterns:
 setlinestyle(); It sets current style of lines.
Syntax: void setlinestyle (int linestyle, unsigned upattern, int thickness);
Line styling
Line Styles:
 cleardevice(); It erases the screen and move CP to origin.
Syntax: void cleardevice (void);
Some more functions
 closegraph();
Syntax: void closegraph (void);
It closes the graphics mode and returns
the screen to text mode.
Mouse Programming in Turbo C
2
Mouse Programming
Mouse programming in C is done by interacting
with registers and interrupts. dos.h also include
functions for Mouse Programming.
 Interrupt: Signal sent by a hardware for immediate
processing is known as interrupt.
Interacting with interrupts
 Register: Small data holding place of Processor.
 int86();
Syntax: int int86 (int interrupt, union REGS *inreg, union REGS *outreg);
This function is used to interact with
interrupts using registers.
The interrupt for Mouse is: 0x33
Union Data Type
union is a special data type in C which allows to
store different data types in the same memory
location.
Example:
union Data {
int I; float f;
} data;
 First Parameter of int86() function is 0x33 to interact with Mouse.
 Second Parameter is address of a union REGS type integer which is
used to input data for interrupt.
 Third Parameter is also address of a union REGS type integer in
which output by interrupt is stored.
 Both union REGS type variables are declared before main()
function. Like:
Using int86();
union REGS input, output;
 ax, bx, cx and dx register are used to input and output data.
 Syntax to input and out data from registers is:
Using int86();
// To send data to register
input.x.ax = 0;
int86( 0x33, &input, &output);
// Now output.x.ax is storing out from interrupt
Input Description Output
AX = 0 Get mouse
status
If AX = 0, Mouse
support isn’t
available
AX = 1
Show Mouse
Pointer
__
AX = 3 Get cursor
position
CX = X axis,
DX = Y axis
AX = 3 Which Mouse
button is pressed
BX = 0  No
BX = 1  Left
BX = 2  Right
Turbo C Graphics and Mouse Programming

Contenu connexe

Tendances

Window to viewport transformation&matrix representation of homogeneous co...
Window to viewport transformation&matrix representation of homogeneous co...Window to viewport transformation&matrix representation of homogeneous co...
Window to viewport transformation&matrix representation of homogeneous co...
Mani Kanth
 
The sutherland hodgeman polygon clipping algorithm
The sutherland hodgeman polygon clipping algorithmThe sutherland hodgeman polygon clipping algorithm
The sutherland hodgeman polygon clipping algorithm
Mani Kanth
 
Character generation
Character generationCharacter generation
Character generation
Ankit Garg
 
Window to viewport transformation
Window to viewport transformationWindow to viewport transformation
Window to viewport transformation
Ankit Garg
 
Composite transformations
Composite transformationsComposite transformations
Composite transformations
Mohd Arif
 

Tendances (20)

2D transformation (Computer Graphics)
2D transformation (Computer Graphics)2D transformation (Computer Graphics)
2D transformation (Computer Graphics)
 
Window to viewport transformation&matrix representation of homogeneous co...
Window to viewport transformation&matrix representation of homogeneous co...Window to viewport transformation&matrix representation of homogeneous co...
Window to viewport transformation&matrix representation of homogeneous co...
 
The sutherland hodgeman polygon clipping algorithm
The sutherland hodgeman polygon clipping algorithmThe sutherland hodgeman polygon clipping algorithm
The sutherland hodgeman polygon clipping algorithm
 
Computer Graphics
Computer GraphicsComputer Graphics
Computer Graphics
 
Character generation
Character generationCharacter generation
Character generation
 
computer graphics
computer graphicscomputer graphics
computer graphics
 
Computer Graphics Lab File C Programs
Computer Graphics Lab File C ProgramsComputer Graphics Lab File C Programs
Computer Graphics Lab File C Programs
 
Computer graphics lab report with code in cpp
Computer graphics lab report with code in cppComputer graphics lab report with code in cpp
Computer graphics lab report with code in cpp
 
Bezier curve & B spline curve
Bezier curve  & B spline curveBezier curve  & B spline curve
Bezier curve & B spline curve
 
Curves and surfaces
Curves and surfacesCurves and surfaces
Curves and surfaces
 
Computer Graphic - Lines, Circles and Ellipse
Computer Graphic - Lines, Circles and EllipseComputer Graphic - Lines, Circles and Ellipse
Computer Graphic - Lines, Circles and Ellipse
 
Window to viewport transformation
Window to viewport transformationWindow to viewport transformation
Window to viewport transformation
 
Input devices in computer graphics
Input devices in computer graphicsInput devices in computer graphics
Input devices in computer graphics
 
3 d viewing projection
3 d viewing  projection3 d viewing  projection
3 d viewing projection
 
Graphics software and standards
Graphics software and standardsGraphics software and standards
Graphics software and standards
 
Cohen-Sutherland Line Clipping Algorithm
Cohen-Sutherland Line Clipping AlgorithmCohen-Sutherland Line Clipping Algorithm
Cohen-Sutherland Line Clipping Algorithm
 
Computer graphics
Computer graphics   Computer graphics
Computer graphics
 
Composite transformations
Composite transformationsComposite transformations
Composite transformations
 
Computer graphics(parametric cubic curves)
Computer graphics(parametric cubic curves)Computer graphics(parametric cubic curves)
Computer graphics(parametric cubic curves)
 
2D Transformation
2D Transformation2D Transformation
2D Transformation
 

Similaire à Turbo C Graphics and Mouse Programming

Opengl4 quick reference card
Opengl4 quick reference cardOpengl4 quick reference card
Opengl4 quick reference card
Adrien Wattez
 
C programming session 01
C programming session 01C programming session 01
C programming session 01
Dushmanta Nath
 

Similaire à Turbo C Graphics and Mouse Programming (20)

OpenGL ES 3.1 Reference Card
OpenGL ES 3.1 Reference CardOpenGL ES 3.1 Reference Card
OpenGL ES 3.1 Reference Card
 
OpenGL 4.4 Reference Card
OpenGL 4.4 Reference CardOpenGL 4.4 Reference Card
OpenGL 4.4 Reference Card
 
Opengl4 quick reference card
Opengl4 quick reference cardOpengl4 quick reference card
Opengl4 quick reference card
 
Hooking signals and dumping the callstack
Hooking signals and dumping the callstackHooking signals and dumping the callstack
Hooking signals and dumping the callstack
 
Chapter 1
Chapter 1Chapter 1
Chapter 1
 
C Programming Language
C Programming LanguageC Programming Language
C Programming Language
 
OpenGL ES 3.2 Reference Guide
OpenGL ES 3.2 Reference GuideOpenGL ES 3.2 Reference Guide
OpenGL ES 3.2 Reference Guide
 
C programming language tutorial
C programming language tutorial C programming language tutorial
C programming language tutorial
 
Unit1 C
Unit1 CUnit1 C
Unit1 C
 
Unit1 C
Unit1 CUnit1 C
Unit1 C
 
Advanced+pointers
Advanced+pointersAdvanced+pointers
Advanced+pointers
 
programming language in c&c++
programming language in c&c++programming language in c&c++
programming language in c&c++
 
Static analysis of C++ source code
Static analysis of C++ source codeStatic analysis of C++ source code
Static analysis of C++ source code
 
Static analysis of C++ source code
Static analysis of C++ source codeStatic analysis of C++ source code
Static analysis of C++ source code
 
Managing I/O in c++
Managing I/O in c++Managing I/O in c++
Managing I/O in c++
 
Computer graphics
Computer graphics Computer graphics
Computer graphics
 
Embedded C - Lecture 2
Embedded C - Lecture 2Embedded C - Lecture 2
Embedded C - Lecture 2
 
c.ppt
c.pptc.ppt
c.ppt
 
7512635.ppt
7512635.ppt7512635.ppt
7512635.ppt
 
C programming session 01
C programming session 01C programming session 01
C programming session 01
 

Dernier

Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
ZurliaSoop
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
AnaAcapella
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
heathfieldcps1
 

Dernier (20)

Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptx
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 

Turbo C Graphics and Mouse Programming

  • 1. Graphics and Mouse Programming in Turbo C
  • 3. Header file for Graphics Functions graphics.h header file is included which contain functions to draw different shapes, display text in different fonts, change colors, etc.
  • 4.  initgraph(); Used to initialize graphics mode. Syntax: void initgraph ( int *driver, int *mode, char *path); Initializing Graphical mode  graphresult(); It returns error code if occur in initializing graphics. Syntax: int graphresult (void);  grapherrormsg(); It returns corresponding error message of error code. Syntax: char grapherrormsg (int errorcode);
  • 5.  outtext(); Used to print string in graphic mode at current position. Syntax: void outtext (char textstring); Displaying Text on screen  outtextxy(); Used to print string in graphic mode at given coordinates. Syntax: void outtextxy (int x, int y, char textstring);
  • 6.
  • 8.  setcolor(); It sets the color of lines. Syntax: void setcolor (int COLOR); Coloring  setbkcolor(); It sets the background color of screen. Syntax: void setbkcolor (int COLOR);
  • 9. Table of Colors COLOR Name Value BLACK 0 BLUE 1 GREEN 2 CYAN 3 RED 4 MAGENTA 5 BROWN 6 LIGHTGRAY 7 DARKGRAY 8 LIGHTBLUE 9 LIGHTGREEN 10 LIGHTCYAN 11 LIGHTRED 12 LIGHTMAGENTA 13 YELLOW 14 WHITE 15 COLOR Name Value
  • 10.  rectangle(); It draws an empty rectangle. Syntax: void rectangle (int x, int y, int x+width, int y+height ); Drawing empty/solid Rectangles  bar(); It draws a filled rectangle.Syntax: void bar (int x, int y, int x+width, int y+height ); It draws a filled rectangle.
  • 11.  setfillstyle(); It sets current fill pattern and fill color. Syntax: void setfillstyle (int fillpattern, int COLOR); Fill styling Fill Patterns:
  • 12.  setlinestyle(); It sets current style of lines. Syntax: void setlinestyle (int linestyle, unsigned upattern, int thickness); Line styling Line Styles:
  • 13.  cleardevice(); It erases the screen and move CP to origin. Syntax: void cleardevice (void); Some more functions  closegraph(); Syntax: void closegraph (void); It closes the graphics mode and returns the screen to text mode.
  • 14. Mouse Programming in Turbo C 2
  • 15. Mouse Programming Mouse programming in C is done by interacting with registers and interrupts. dos.h also include functions for Mouse Programming.
  • 16.  Interrupt: Signal sent by a hardware for immediate processing is known as interrupt. Interacting with interrupts  Register: Small data holding place of Processor.  int86(); Syntax: int int86 (int interrupt, union REGS *inreg, union REGS *outreg); This function is used to interact with interrupts using registers. The interrupt for Mouse is: 0x33
  • 17. Union Data Type union is a special data type in C which allows to store different data types in the same memory location. Example: union Data { int I; float f; } data;
  • 18.  First Parameter of int86() function is 0x33 to interact with Mouse.  Second Parameter is address of a union REGS type integer which is used to input data for interrupt.  Third Parameter is also address of a union REGS type integer in which output by interrupt is stored.  Both union REGS type variables are declared before main() function. Like: Using int86(); union REGS input, output;
  • 19.  ax, bx, cx and dx register are used to input and output data.  Syntax to input and out data from registers is: Using int86(); // To send data to register input.x.ax = 0; int86( 0x33, &input, &output); // Now output.x.ax is storing out from interrupt
  • 20. Input Description Output AX = 0 Get mouse status If AX = 0, Mouse support isn’t available AX = 1 Show Mouse Pointer __ AX = 3 Get cursor position CX = X axis, DX = Y axis AX = 3 Which Mouse button is pressed BX = 0  No BX = 1  Left BX = 2  Right