SlideShare a Scribd company logo
1 of 22
Input and Interaction
1
Objectives
• Introduce the basic input devices
• Physical Devices
• Logical Devices
• Input Modes
• Event-driven input
• Introduce double buffering for smooth animations
• Programming event input with GLUT
2
Project Sketchpad
• Ivan Sutherland (MIT 1963) established the basic interactive
paradigm that characterizes interactive computer graphics:
• User sees an object on the display
• User points to (picks) the object with an input device (light pen, mouse,
trackball)
• Object changes (moves, rotates, morphs)
• Repeat
3
Graphical Input
• Devices can be described either by
• Physical properties
• Mouse
• Keyboard
• Trackball
• Logical Properties
• What is returned to program via API
• A position
• An object identifier
• Modes
• How and when input is obtained
• Request or event
4
Physical Devices
5
mouse trackball
light pen
data tablet joy stick space ball
Incremental (Relative) Devices
• Devices such as the data tablet return a position directly to the
operating system
• Devices such as the mouse, trackball, and joy stick return
incremental inputs (or velocities) to the operating system
• Must integrate these inputs to obtain an absolute position
• Rotation of cylinders in mouse
• Roll of trackball
• Difficult to obtain absolute position
• Can get variable sensitivity
6
Logical Devices
• Consider the C and C++ code
• C++: cin >> x;
• C: scanf (“%d”, &x);
• What is the input device?
• Can’t tell from the code
• Could be keyboard, file, output from another program
• The code provides logical input
• A number (an int) is returned to the program regardless of the physical
device
7
Graphical Logical Devices
•Graphical input is more varied than input to standard
programs which is usually numbers, characters, or
bits
•Two older APIs (GKS, PHIGS) defined six types of
logical input
• Locator: return a position
• Pick: return ID of an object
• Keyboard: return strings of characters
• Stroke: return array of positions
• Valuator: return floating point number
• Choice: return one of n items
8
X Window Input
•The X Window System introduced a client-server model
for a network of workstations
• Client: OpenGL program
• Graphics Server: bitmap display with a pointing device and a keyboard
9
Input Modes
• Input devices contain a trigger which can be used to send a signal to
the operating system
• Button on mouse
• Pressing or releasing a key
• When triggered, input devices return information (their measure) to
the system
• Mouse returns position information
• Keyboard returns ASCII code
10
Request Mode
• Input provided to program only when user triggers the device
• Typical of keyboard input
• Can erase (backspace), edit, correct until enter (return) key (the trigger) is
depressed
11
Event Mode
• Most systems have more than one input device, each of which can
be triggered at an arbitrary time by a user
• Each trigger generates an event whose measure is put in an event
queue which can be examined by the user program
12
Event Types
• Window: resize, expose, iconify
• Mouse: click one or more buttons
• Motion: move mouse
• Keyboard: press or release a key
• Idle: nonevent
• Define what should be done if no other event is in queue
13
Callbacks
• Programming interface for event-driven input
• Define a callback function for each type of event the graphics system
recognizes
• This user-supplied function is executed when the event occurs
• GLUT example: glutMouseFunc(mymouse)
14
mouse callback function
GLUT callbacks
GLUT recognizes a subset of the events recognized by any particular
window system (Windows, X, Macintosh)
• glutDisplayFunc
• glutMouseFunc
• glutReshapeFunc
• glutKeyboardFunc
• glutIdleFunc
• glutMotionFunc, glutPassiveMotionFunc
15
GLUT Event Loop
•Recall that the last line in main.c for a program
using GLUT must be
glutMainLoop();
which puts the program in an infinite event loop
•In each pass through the event loop, GLUT
• looks at the events in the queue
• for each event in the queue, GLUT executes the appropriate
callback function if one is defined
• if no callback is defined for the event, the event is ignored
16
The display callback
•The display callback is executed whenever GLUT
determines that the window should be refreshed, for
example
• When the window is first opened
• When the window is reshaped
• When a window is exposed
• When the user program decides it wants to change the display
•In main.c
• glutDisplayFunc(mydisplay) identifies the function
to be executed
• Every GLUT program must have a display callback
17
Posting redisplays
•Many events may invoke the display callback function
• Can lead to multiple executions of the display callback on a
single pass through the event loop
•We can avoid this problem by instead using
glutPostRedisplay();
which sets a flag.
•GLUT checks to see if the flag is set at the end of the
event loop
•If set then the display callback function is executed
18
Animating a Display
•When we redraw the display through the display
callback, we usually start by clearing the window
• glClear()
then draw the altered display
•Problem: the drawing of information in the frame
buffer is decoupled from the display of its contents
• Graphics systems use dual ported memory
•Hence we can see partially drawn display
• See the program single_double.c for an example with a
rotating cube
19
Double Buffering
•Instead of one color buffer, we use two
• Front Buffer: one that is displayed but not written to
• Back Buffer: one that is written to but not displayed
•Program then requests a double buffer in main.c
• glutInitDisplayMode(GL_RGB | GL_DOUBLE)
• At the end of the display callback buffers are swapped
20
void mydisplay()
{
glClear(GL_COLOR_BUFFER_BIT|….)
.
/* draw graphics here */
.
glutSwapBuffers()
}
Using the idle callback
• The idle callback is executed whenever there are no events in
the event queue
• glutIdleFunc(myidle)
• Useful for animations
21
void myidle() {
/* change something */
t += dt
glutPostRedisplay();
}
Void mydisplay() {
glClear();
/* draw something that depends on t */
glutSwapBuffers();
}
Using globals
•The form of all GLUT callbacks is fixed
• void mydisplay()
• void mymouse(GLint button, GLint state,
GLint x, GLint y)
•Must use globals to pass information to callbacks
22
float t; /*global */
void mydisplay()
{
/* draw something that depends on t
}

More Related Content

What's hot

2D transformation (Computer Graphics)
2D transformation (Computer Graphics)2D transformation (Computer Graphics)
2D transformation (Computer Graphics)Timbal Mayank
 
Computer graphics iv unit
Computer graphics iv unitComputer graphics iv unit
Computer graphics iv unitaravindangc
 
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
 
Cohen sutherland line clipping
Cohen sutherland line clippingCohen sutherland line clipping
Cohen sutherland line clippingMani Kanth
 
Random scan displays and raster scan displays
Random scan displays and raster scan displaysRandom scan displays and raster scan displays
Random scan displays and raster scan displaysSomya Bagai
 
Back face detection
Back face detectionBack face detection
Back face detectionPooja Dixit
 
Scan line method
Scan line methodScan line method
Scan line methodPooja Dixit
 
3 d viewing projection
3 d viewing  projection3 d viewing  projection
3 d viewing projectionPooja Dixit
 
Feature selection concepts and methods
Feature selection concepts and methodsFeature selection concepts and methods
Feature selection concepts and methodsReza Ramezani
 
Overview of the graphics system
Overview of the graphics systemOverview of the graphics system
Overview of the graphics systemKamal Acharya
 
line attributes.pptx
line attributes.pptxline attributes.pptx
line attributes.pptxRubaNagarajan
 
Attributes of output Primitive
Attributes of output Primitive Attributes of output Primitive
Attributes of output Primitive SachiniGunawardana
 
3 d display-methods-in-computer-graphics(For DIU)
3 d display-methods-in-computer-graphics(For DIU)3 d display-methods-in-computer-graphics(For DIU)
3 d display-methods-in-computer-graphics(For DIU)Rajon rdx
 
Visible surface identification
Visible surface identificationVisible surface identification
Visible surface identificationPooja Dixit
 
Output primitives in Computer Graphics
Output primitives in Computer GraphicsOutput primitives in Computer Graphics
Output primitives in Computer GraphicsKamal Acharya
 
Attributes of Output Primitives
Attributes of Output PrimitivesAttributes of Output Primitives
Attributes of Output PrimitivesRenita Santhmayora
 

What's hot (20)

3 d display methods
3 d display methods3 d display methods
3 d display methods
 
2D transformation (Computer Graphics)
2D transformation (Computer Graphics)2D transformation (Computer Graphics)
2D transformation (Computer Graphics)
 
Computer graphics iv unit
Computer graphics iv unitComputer graphics iv unit
Computer graphics iv unit
 
Attributes of output primitive(line attributes)
Attributes of output primitive(line attributes)Attributes of output primitive(line attributes)
Attributes of output primitive(line attributes)
 
Cohen sutherland line clipping
Cohen sutherland line clippingCohen sutherland line clipping
Cohen sutherland line clipping
 
Random scan displays and raster scan displays
Random scan displays and raster scan displaysRandom scan displays and raster scan displays
Random scan displays and raster scan displays
 
Back face detection
Back face detectionBack face detection
Back face detection
 
Scan line method
Scan line methodScan line method
Scan line method
 
ANIMATION SEQUENCE
ANIMATION SEQUENCEANIMATION SEQUENCE
ANIMATION SEQUENCE
 
3 d viewing projection
3 d viewing  projection3 d viewing  projection
3 d viewing projection
 
Feature selection concepts and methods
Feature selection concepts and methodsFeature selection concepts and methods
Feature selection concepts and methods
 
Overview of the graphics system
Overview of the graphics systemOverview of the graphics system
Overview of the graphics system
 
line attributes.pptx
line attributes.pptxline attributes.pptx
line attributes.pptx
 
Attributes of output Primitive
Attributes of output Primitive Attributes of output Primitive
Attributes of output Primitive
 
Frame buffer
Frame bufferFrame buffer
Frame buffer
 
3 d display-methods-in-computer-graphics(For DIU)
3 d display-methods-in-computer-graphics(For DIU)3 d display-methods-in-computer-graphics(For DIU)
3 d display-methods-in-computer-graphics(For DIU)
 
UNIT-IV
UNIT-IVUNIT-IV
UNIT-IV
 
Visible surface identification
Visible surface identificationVisible surface identification
Visible surface identification
 
Output primitives in Computer Graphics
Output primitives in Computer GraphicsOutput primitives in Computer Graphics
Output primitives in Computer Graphics
 
Attributes of Output Primitives
Attributes of Output PrimitivesAttributes of Output Primitives
Attributes of Output Primitives
 

Similar to Input and Interaction: Devices, Modes, and Event-Driven Programming

Computer Graphics with OpenGL presentation Slides.pptx
Computer Graphics with OpenGL presentation Slides.pptxComputer Graphics with OpenGL presentation Slides.pptx
Computer Graphics with OpenGL presentation Slides.pptxAnandM62785
 
OpenGL Introduction.
OpenGL Introduction.OpenGL Introduction.
OpenGL Introduction.Girish Ghate
 
C game programming - SDL
C game programming - SDLC game programming - SDL
C game programming - SDLWingston
 
Computer Graphics Project Report on Sinking Ship using OpenGL
Computer Graphics Project Report on Sinking Ship using OpenGL Computer Graphics Project Report on Sinking Ship using OpenGL
Computer Graphics Project Report on Sinking Ship using OpenGL Sharath Raj
 
07 Systems Software Programming-IPC-Signals.pptx
07 Systems Software Programming-IPC-Signals.pptx07 Systems Software Programming-IPC-Signals.pptx
07 Systems Software Programming-IPC-Signals.pptxKushalSrivastava23
 
clWrap: Nonsense free control of your GPU
clWrap: Nonsense free control of your GPUclWrap: Nonsense free control of your GPU
clWrap: Nonsense free control of your GPUJohn Colvin
 
Petri Niemi Qt Advanced Part 2
Petri Niemi Qt Advanced Part 2Petri Niemi Qt Advanced Part 2
Petri Niemi Qt Advanced Part 2NokiaAppForum
 
Lecture 6 introduction to open gl and glut
Lecture 6   introduction to open gl and glutLecture 6   introduction to open gl and glut
Lecture 6 introduction to open gl and glutsimpleok
 
cse581_03_EventProgramming.ppt
cse581_03_EventProgramming.pptcse581_03_EventProgramming.ppt
cse581_03_EventProgramming.ppttadudemise
 
ppt_3DWM_CG-1[1] 04july.ppt of wind mill project.
ppt_3DWM_CG-1[1] 04july.ppt of wind mill project.ppt_3DWM_CG-1[1] 04july.ppt of wind mill project.
ppt_3DWM_CG-1[1] 04july.ppt of wind mill project.PunyaGowda8
 
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.pptxssuser255bf1
 
Chapter02 graphics-programming
Chapter02 graphics-programmingChapter02 graphics-programming
Chapter02 graphics-programmingMohammed Romi
 
Python is a high-level, general-purpose programming language. Its design phil...
Python is a high-level, general-purpose programming language. Its design phil...Python is a high-level, general-purpose programming language. Its design phil...
Python is a high-level, general-purpose programming language. Its design phil...bhargavi804095
 
Better Interactive Programs
Better Interactive ProgramsBetter Interactive Programs
Better Interactive ProgramsSyed Zaid Irshad
 

Similar to Input and Interaction: Devices, Modes, and Event-Driven Programming (20)

Opengl (1)
Opengl (1)Opengl (1)
Opengl (1)
 
Computer Graphics with OpenGL presentation Slides.pptx
Computer Graphics with OpenGL presentation Slides.pptxComputer Graphics with OpenGL presentation Slides.pptx
Computer Graphics with OpenGL presentation Slides.pptx
 
OpenGL Introduction.
OpenGL Introduction.OpenGL Introduction.
OpenGL Introduction.
 
Hill ch2ed3
Hill ch2ed3Hill ch2ed3
Hill ch2ed3
 
C game programming - SDL
C game programming - SDLC game programming - SDL
C game programming - SDL
 
Open gl
Open glOpen gl
Open gl
 
2D graphics
2D graphics2D graphics
2D graphics
 
Computer Graphics Project Report on Sinking Ship using OpenGL
Computer Graphics Project Report on Sinking Ship using OpenGL Computer Graphics Project Report on Sinking Ship using OpenGL
Computer Graphics Project Report on Sinking Ship using OpenGL
 
07 Systems Software Programming-IPC-Signals.pptx
07 Systems Software Programming-IPC-Signals.pptx07 Systems Software Programming-IPC-Signals.pptx
07 Systems Software Programming-IPC-Signals.pptx
 
clWrap: Nonsense free control of your GPU
clWrap: Nonsense free control of your GPUclWrap: Nonsense free control of your GPU
clWrap: Nonsense free control of your GPU
 
Petri Niemi Qt Advanced Part 2
Petri Niemi Qt Advanced Part 2Petri Niemi Qt Advanced Part 2
Petri Niemi Qt Advanced Part 2
 
Lecture 6 introduction to open gl and glut
Lecture 6   introduction to open gl and glutLecture 6   introduction to open gl and glut
Lecture 6 introduction to open gl and glut
 
Programming with OpenGL
Programming with OpenGLProgramming with OpenGL
Programming with OpenGL
 
03_GUI.ppt
03_GUI.ppt03_GUI.ppt
03_GUI.ppt
 
cse581_03_EventProgramming.ppt
cse581_03_EventProgramming.pptcse581_03_EventProgramming.ppt
cse581_03_EventProgramming.ppt
 
ppt_3DWM_CG-1[1] 04july.ppt of wind mill project.
ppt_3DWM_CG-1[1] 04july.ppt of wind mill project.ppt_3DWM_CG-1[1] 04july.ppt of wind mill project.
ppt_3DWM_CG-1[1] 04july.ppt of wind mill project.
 
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
 
Chapter02 graphics-programming
Chapter02 graphics-programmingChapter02 graphics-programming
Chapter02 graphics-programming
 
Python is a high-level, general-purpose programming language. Its design phil...
Python is a high-level, general-purpose programming language. Its design phil...Python is a high-level, general-purpose programming language. Its design phil...
Python is a high-level, general-purpose programming language. Its design phil...
 
Better Interactive Programs
Better Interactive ProgramsBetter Interactive Programs
Better Interactive Programs
 

More from Syed Zaid Irshad

More from Syed Zaid Irshad (20)

Operating System.pdf
Operating System.pdfOperating System.pdf
Operating System.pdf
 
DBMS_Lab_Manual_&_Solution
DBMS_Lab_Manual_&_SolutionDBMS_Lab_Manual_&_Solution
DBMS_Lab_Manual_&_Solution
 
Data Structure and Algorithms.pptx
Data Structure and Algorithms.pptxData Structure and Algorithms.pptx
Data Structure and Algorithms.pptx
 
Design and Analysis of Algorithms.pptx
Design and Analysis of Algorithms.pptxDesign and Analysis of Algorithms.pptx
Design and Analysis of Algorithms.pptx
 
Professional Issues in Computing
Professional Issues in ComputingProfessional Issues in Computing
Professional Issues in Computing
 
Reduce course notes class xi
Reduce course notes class xiReduce course notes class xi
Reduce course notes class xi
 
Reduce course notes class xii
Reduce course notes class xiiReduce course notes class xii
Reduce course notes class xii
 
Introduction to Database
Introduction to DatabaseIntroduction to Database
Introduction to Database
 
C Language
C LanguageC Language
C Language
 
Flowchart
FlowchartFlowchart
Flowchart
 
Algorithm Pseudo
Algorithm PseudoAlgorithm Pseudo
Algorithm Pseudo
 
Computer Programming
Computer ProgrammingComputer Programming
Computer Programming
 
ICS 2nd Year Book Introduction
ICS 2nd Year Book IntroductionICS 2nd Year Book Introduction
ICS 2nd Year Book Introduction
 
Security, Copyright and the Law
Security, Copyright and the LawSecurity, Copyright and the Law
Security, Copyright and the Law
 
Computer Architecture
Computer ArchitectureComputer Architecture
Computer Architecture
 
Data Communication
Data CommunicationData Communication
Data Communication
 
Information Networks
Information NetworksInformation Networks
Information Networks
 
Basic Concept of Information Technology
Basic Concept of Information TechnologyBasic Concept of Information Technology
Basic Concept of Information Technology
 
Introduction to ICS 1st Year Book
Introduction to ICS 1st Year BookIntroduction to ICS 1st Year Book
Introduction to ICS 1st Year Book
 
Using the set operators
Using the set operatorsUsing the set operators
Using the set operators
 

Recently uploaded

Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Dr.Costas Sachpazis
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxupamatechverse
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...ranjana rawat
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...Call Girls in Nagpur High Profile
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...Soham Mondal
 
result management system report for college project
result management system report for college projectresult management system report for college project
result management system report for college projectTonystark477637
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)simmis5
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations120cr0395
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSSIVASHANKAR N
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxupamatechverse
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performancesivaprakash250
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Christo Ananth
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escortsranjana rawat
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130Suhani Kapoor
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Dr.Costas Sachpazis
 
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINEMANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINESIVASHANKAR N
 
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 

Recently uploaded (20)

Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptx
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
 
result management system report for college project
result management system report for college projectresult management system report for college project
result management system report for college project
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
 
Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
 
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINEDJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptx
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performance
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
 
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINEMANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
 
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 

Input and Interaction: Devices, Modes, and Event-Driven Programming

  • 2. Objectives • Introduce the basic input devices • Physical Devices • Logical Devices • Input Modes • Event-driven input • Introduce double buffering for smooth animations • Programming event input with GLUT 2
  • 3. Project Sketchpad • Ivan Sutherland (MIT 1963) established the basic interactive paradigm that characterizes interactive computer graphics: • User sees an object on the display • User points to (picks) the object with an input device (light pen, mouse, trackball) • Object changes (moves, rotates, morphs) • Repeat 3
  • 4. Graphical Input • Devices can be described either by • Physical properties • Mouse • Keyboard • Trackball • Logical Properties • What is returned to program via API • A position • An object identifier • Modes • How and when input is obtained • Request or event 4
  • 5. Physical Devices 5 mouse trackball light pen data tablet joy stick space ball
  • 6. Incremental (Relative) Devices • Devices such as the data tablet return a position directly to the operating system • Devices such as the mouse, trackball, and joy stick return incremental inputs (or velocities) to the operating system • Must integrate these inputs to obtain an absolute position • Rotation of cylinders in mouse • Roll of trackball • Difficult to obtain absolute position • Can get variable sensitivity 6
  • 7. Logical Devices • Consider the C and C++ code • C++: cin >> x; • C: scanf (“%d”, &x); • What is the input device? • Can’t tell from the code • Could be keyboard, file, output from another program • The code provides logical input • A number (an int) is returned to the program regardless of the physical device 7
  • 8. Graphical Logical Devices •Graphical input is more varied than input to standard programs which is usually numbers, characters, or bits •Two older APIs (GKS, PHIGS) defined six types of logical input • Locator: return a position • Pick: return ID of an object • Keyboard: return strings of characters • Stroke: return array of positions • Valuator: return floating point number • Choice: return one of n items 8
  • 9. X Window Input •The X Window System introduced a client-server model for a network of workstations • Client: OpenGL program • Graphics Server: bitmap display with a pointing device and a keyboard 9
  • 10. Input Modes • Input devices contain a trigger which can be used to send a signal to the operating system • Button on mouse • Pressing or releasing a key • When triggered, input devices return information (their measure) to the system • Mouse returns position information • Keyboard returns ASCII code 10
  • 11. Request Mode • Input provided to program only when user triggers the device • Typical of keyboard input • Can erase (backspace), edit, correct until enter (return) key (the trigger) is depressed 11
  • 12. Event Mode • Most systems have more than one input device, each of which can be triggered at an arbitrary time by a user • Each trigger generates an event whose measure is put in an event queue which can be examined by the user program 12
  • 13. Event Types • Window: resize, expose, iconify • Mouse: click one or more buttons • Motion: move mouse • Keyboard: press or release a key • Idle: nonevent • Define what should be done if no other event is in queue 13
  • 14. Callbacks • Programming interface for event-driven input • Define a callback function for each type of event the graphics system recognizes • This user-supplied function is executed when the event occurs • GLUT example: glutMouseFunc(mymouse) 14 mouse callback function
  • 15. GLUT callbacks GLUT recognizes a subset of the events recognized by any particular window system (Windows, X, Macintosh) • glutDisplayFunc • glutMouseFunc • glutReshapeFunc • glutKeyboardFunc • glutIdleFunc • glutMotionFunc, glutPassiveMotionFunc 15
  • 16. GLUT Event Loop •Recall that the last line in main.c for a program using GLUT must be glutMainLoop(); which puts the program in an infinite event loop •In each pass through the event loop, GLUT • looks at the events in the queue • for each event in the queue, GLUT executes the appropriate callback function if one is defined • if no callback is defined for the event, the event is ignored 16
  • 17. The display callback •The display callback is executed whenever GLUT determines that the window should be refreshed, for example • When the window is first opened • When the window is reshaped • When a window is exposed • When the user program decides it wants to change the display •In main.c • glutDisplayFunc(mydisplay) identifies the function to be executed • Every GLUT program must have a display callback 17
  • 18. Posting redisplays •Many events may invoke the display callback function • Can lead to multiple executions of the display callback on a single pass through the event loop •We can avoid this problem by instead using glutPostRedisplay(); which sets a flag. •GLUT checks to see if the flag is set at the end of the event loop •If set then the display callback function is executed 18
  • 19. Animating a Display •When we redraw the display through the display callback, we usually start by clearing the window • glClear() then draw the altered display •Problem: the drawing of information in the frame buffer is decoupled from the display of its contents • Graphics systems use dual ported memory •Hence we can see partially drawn display • See the program single_double.c for an example with a rotating cube 19
  • 20. Double Buffering •Instead of one color buffer, we use two • Front Buffer: one that is displayed but not written to • Back Buffer: one that is written to but not displayed •Program then requests a double buffer in main.c • glutInitDisplayMode(GL_RGB | GL_DOUBLE) • At the end of the display callback buffers are swapped 20 void mydisplay() { glClear(GL_COLOR_BUFFER_BIT|….) . /* draw graphics here */ . glutSwapBuffers() }
  • 21. Using the idle callback • The idle callback is executed whenever there are no events in the event queue • glutIdleFunc(myidle) • Useful for animations 21 void myidle() { /* change something */ t += dt glutPostRedisplay(); } Void mydisplay() { glClear(); /* draw something that depends on t */ glutSwapBuffers(); }
  • 22. Using globals •The form of all GLUT callbacks is fixed • void mydisplay() • void mymouse(GLint button, GLint state, GLint x, GLint y) •Must use globals to pass information to callbacks 22 float t; /*global */ void mydisplay() { /* draw something that depends on t }