SlideShare a Scribd company logo
Better Interactive Programs
1
Objectives
• Learn to build more sophisticated interactive programs using
• Picking
• Select objects from the display
• Three methods
• Rubberbanding
• Interactive drawing of lines and rectangles
• Display Lists
• Retained mode graphics
2
Picking
•Identify a user-defined object on the display
•In principle, it should be simple because the mouse
gives the position and we should be able to determine
to which object(s) a position corresponds
•Practical difficulties
• Pipeline architecture is feed forward, hard to go from screen
back to world
• Complicated by screen being 2D, world is 3D
• How close do we have to come to object to say we selected it?
3
Three Approaches
• Hit list
• Most general approach but most difficult to implement
• Use back or some other buffer to store object ids as the objects are
rendered
• Rectangular maps
• Easy to implement for many applications
• See paint program in text
4
Rendering Modes
• OpenGL can render in one of three modes selected by
glRenderMode(mode)
• GL_RENDER: normal rendering to the frame buffer (default)
• GL_FEEDBACK: provides list of primitives rendered but no output to the
frame buffer
• GL_SELECTION: Each primitive in the view volume generates a hit
record that is placed in a name stack which can be examined later
5
Selection Mode Functions
•glSelectBuffer(): specifies name buffer
•glInitNames(): initializes name buffer
•glPushName(id): push id on name buffer
•glPopName(): pop top of name buffer
•glLoadName(id): replace top name on buffer
• id is set by application program to identify objects
6
Using Selection Mode
• Initialize name buffer
• Enter selection mode (using mouse)
• Render scene with user-defined identifiers
• Reenter normal render mode
• This operation returns number of hits
• Examine contents of name buffer (hit records)
• Hit records include id and depth information
7
Selection Mode and Picking
• As we just described it, selection mode won’t work for picking
because every primitive in the view volume will generate a hit
• Change the viewing parameters so that only those primitives near
the cursor are in the altered view volume
• Use gluPickMatrix (see text for details)
8
Using Regions of the Screen
•Many applications use a simple rectangular
arrangement of the screen
• Example: paint/CAD program
•Easier to look at mouse position and determine which
area of screen it is in than using selection mode
picking
9
drawing area
tools
menus
Using another buffer and colors for
picking
•For a small number of objects, we can assign a unique
color (often in color index mode) to each object
•We then render the scene to a color buffer other than
the front buffer so the results of the rendering are
not visible
•We then get the mouse position and use
glReadPixels() to read the color in the buffer we
just wrote at the position of the mouse
•The returned color gives the id of the object
10
Writing Modes
11
frame buffer
application
‘
bitwise logical operation
XOR write
• Usual (default) mode: source replaces destination (d’ = s)
• Cannot write temporary lines this way because we cannot recover what was
“under” the line in a fast simple way
• Exclusive OR mode (XOR) (d’ = d ⊕ s)
• x ⊕ y ⊕ x =y
• Hence, if we use XOR mode to write a line, we can draw it a second time and
line is erased!
12
Rubberbanding
• Switch to XOR write mode
• Draw object
• For line can use first mouse click to fix one endpoint and then use motion
callback to continuously update the second endpoint
• Each time mouse is moved, redraw line which erases it and then draw line
from fixed first position to to new second position
• At end, switch back to normal drawing mode and draw line
• Works for other objects: rectangles, circles
13
Rubberband Lines
14
initial display
draw line with mouse
in XOR mode
mouse moved to
new position
first point
second point
original line redrawn
with XOR
new line drawn
with XOR
XOR in OpenGL
• There are 16 possible logical operations between two bits
• All are supported by OpenGL
• Must first enable logical operations
• glEnable(GL_COLOR_LOGIC_OP)
• Choose logical operation
• glLogicOp(GL_XOR)
• glLogicOp(GL_COPY) (default)
15
Immediate and Retained Modes
•Recall that in a standard OpenGL program, once an
object is rendered there is no memory of it and to
redisplay it, we must re-execute the code for it
• Known as immediate mode graphics
• Can be especially slow if the objects are complex and must be
sent over a network
•Alternative is define objects and keep them in some
form that can be redisplayed easily
• Retained mode graphics
• Accomplished in OpenGL via display lists
16
Display Lists
• Conceptually similar to a graphics file
• Must define (name, create)
• Add contents
• Close
• In client-server environment, display list is placed on server
• Can be redisplayed without sending primitives over network each time
17
Display List Functions
• Creating a display list
GLuint id;
void init()
{
id = glGenLists( 1 );
glNewList( id, GL_COMPILE );
/* other OpenGL routines */
glEndList();
}
• Call a created list
void display()
{
glCallList( id );
}
18
Display Lists and State
• Most OpenGL functions can be put in display lists
• State changes made inside a display list persist after the display list is
executed
• Can avoid unexpected results by using glPushAttrib and
glPushMatrix upon entering a display list and
glPopAttrib and glPopMatrix before exiting
19
Hierarchy and Display Lists
20
•Consider model of a car
­ Create display list for chassis
­ Create display list for wheel
glNewList( CAR, GL_COMPILE );
glCallList( CHASSIS );
glTranslatef( … );
glCallList( WHEEL );
glTranslatef( … );
glCallList( WHEEL );
…
glEndList();

More Related Content

Similar to Better Interactive Programs

Chapter02 graphics-programming
Chapter02 graphics-programmingChapter02 graphics-programming
Chapter02 graphics-programming
Mohammed Romi
 
2D graphics
2D graphics2D graphics
2D graphics
Muhammad Rashid
 
C game programming - SDL
C game programming - SDLC game programming - SDL
C game programming - SDL
Wingston
 
Input and Interaction
Input and InteractionInput and Interaction
Input and Interaction
Syed Zaid Irshad
 
02 direct3 d_pipeline
02 direct3 d_pipeline02 direct3 d_pipeline
02 direct3 d_pipeline
Girish Ghate
 
openGL basics for sample program (1).ppt
openGL basics for sample program (1).pptopenGL basics for sample program (1).ppt
openGL basics for sample program (1).ppt
HIMANKMISHRA2
 
openGL basics for sample program.ppt
openGL basics for sample program.pptopenGL basics for sample program.ppt
openGL basics for sample program.ppt
HIMANKMISHRA2
 
Unit 11. Graphics
Unit 11. GraphicsUnit 11. Graphics
Unit 11. Graphics
Ashim Lamichhane
 
september11.ppt
september11.pptseptember11.ppt
september11.ppt
CharlesMatu2
 
BSidesDelhi 2018: Headshot - Game Hacking on macOS
BSidesDelhi 2018: Headshot - Game Hacking on macOSBSidesDelhi 2018: Headshot - Game Hacking on macOS
BSidesDelhi 2018: Headshot - Game Hacking on macOS
BSides Delhi
 
CGV.pptx
CGV.pptxCGV.pptx
Данило Ульянич “C89 OpenGL for ARM microcontrollers on Cortex-M. Basic functi...
Данило Ульянич “C89 OpenGL for ARM microcontrollers on Cortex-M. Basic functi...Данило Ульянич “C89 OpenGL for ARM microcontrollers on Cortex-M. Basic functi...
Данило Ульянич “C89 OpenGL for ARM microcontrollers on Cortex-M. Basic functi...
Lviv Startup Club
 
Graphics Libraries
Graphics LibrariesGraphics Libraries
Graphics Libraries
Prachi Mishra
 
Profiling tools and Android Performance patterns
Profiling tools and Android Performance patternsProfiling tools and Android Performance patterns
Profiling tools and Android Performance patterns
icemobile
 
OpenGL Introduction.
OpenGL Introduction.OpenGL Introduction.
OpenGL Introduction.
Girish Ghate
 
GLSL
GLSLGLSL
Opengl (1)
Opengl (1)Opengl (1)
Opengl (1)
ch samaram
 
Programming with OpenGL
Programming with OpenGLProgramming with OpenGL
Programming with OpenGL
Syed Zaid Irshad
 
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
 
18csl67 vtu lab manual
18csl67 vtu lab manual18csl67 vtu lab manual
18csl67 vtu lab manual
NatsuDragoneel5
 

Similar to Better Interactive Programs (20)

Chapter02 graphics-programming
Chapter02 graphics-programmingChapter02 graphics-programming
Chapter02 graphics-programming
 
2D graphics
2D graphics2D graphics
2D graphics
 
C game programming - SDL
C game programming - SDLC game programming - SDL
C game programming - SDL
 
Input and Interaction
Input and InteractionInput and Interaction
Input and Interaction
 
02 direct3 d_pipeline
02 direct3 d_pipeline02 direct3 d_pipeline
02 direct3 d_pipeline
 
openGL basics for sample program (1).ppt
openGL basics for sample program (1).pptopenGL basics for sample program (1).ppt
openGL basics for sample program (1).ppt
 
openGL basics for sample program.ppt
openGL basics for sample program.pptopenGL basics for sample program.ppt
openGL basics for sample program.ppt
 
Unit 11. Graphics
Unit 11. GraphicsUnit 11. Graphics
Unit 11. Graphics
 
september11.ppt
september11.pptseptember11.ppt
september11.ppt
 
BSidesDelhi 2018: Headshot - Game Hacking on macOS
BSidesDelhi 2018: Headshot - Game Hacking on macOSBSidesDelhi 2018: Headshot - Game Hacking on macOS
BSidesDelhi 2018: Headshot - Game Hacking on macOS
 
CGV.pptx
CGV.pptxCGV.pptx
CGV.pptx
 
Данило Ульянич “C89 OpenGL for ARM microcontrollers on Cortex-M. Basic functi...
Данило Ульянич “C89 OpenGL for ARM microcontrollers on Cortex-M. Basic functi...Данило Ульянич “C89 OpenGL for ARM microcontrollers on Cortex-M. Basic functi...
Данило Ульянич “C89 OpenGL for ARM microcontrollers on Cortex-M. Basic functi...
 
Graphics Libraries
Graphics LibrariesGraphics Libraries
Graphics Libraries
 
Profiling tools and Android Performance patterns
Profiling tools and Android Performance patternsProfiling tools and Android Performance patterns
Profiling tools and Android Performance patterns
 
OpenGL Introduction.
OpenGL Introduction.OpenGL Introduction.
OpenGL Introduction.
 
GLSL
GLSLGLSL
GLSL
 
Opengl (1)
Opengl (1)Opengl (1)
Opengl (1)
 
Programming with OpenGL
Programming with OpenGLProgramming with OpenGL
Programming with OpenGL
 
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.
 
18csl67 vtu lab manual
18csl67 vtu lab manual18csl67 vtu lab manual
18csl67 vtu lab manual
 

More from Syed Zaid Irshad

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

CEC 352 - SATELLITE COMMUNICATION UNIT 1
CEC 352 - SATELLITE COMMUNICATION UNIT 1CEC 352 - SATELLITE COMMUNICATION UNIT 1
CEC 352 - SATELLITE COMMUNICATION UNIT 1
PKavitha10
 
International Conference on NLP, Artificial Intelligence, Machine Learning an...
International Conference on NLP, Artificial Intelligence, Machine Learning an...International Conference on NLP, Artificial Intelligence, Machine Learning an...
International Conference on NLP, Artificial Intelligence, Machine Learning an...
gerogepatton
 
Transformers design and coooling methods
Transformers design and coooling methodsTransformers design and coooling methods
Transformers design and coooling methods
Roger Rozario
 
Certificates - Mahmoud Mohamed Moursi Ahmed
Certificates - Mahmoud Mohamed Moursi AhmedCertificates - Mahmoud Mohamed Moursi Ahmed
Certificates - Mahmoud Mohamed Moursi Ahmed
Mahmoud Morsy
 
BRAIN TUMOR DETECTION for seminar ppt.pdf
BRAIN TUMOR DETECTION for seminar ppt.pdfBRAIN TUMOR DETECTION for seminar ppt.pdf
BRAIN TUMOR DETECTION for seminar ppt.pdf
LAXMAREDDY22
 
官方认证美国密歇根州立大学毕业证学位证书原版一模一样
官方认证美国密歇根州立大学毕业证学位证书原版一模一样官方认证美国密歇根州立大学毕业证学位证书原版一模一样
官方认证美国密歇根州立大学毕业证学位证书原版一模一样
171ticu
 
Engineering Drawings Lecture Detail Drawings 2014.pdf
Engineering Drawings Lecture Detail Drawings 2014.pdfEngineering Drawings Lecture Detail Drawings 2014.pdf
Engineering Drawings Lecture Detail Drawings 2014.pdf
abbyasa1014
 
22CYT12-Unit-V-E Waste and its Management.ppt
22CYT12-Unit-V-E Waste and its Management.ppt22CYT12-Unit-V-E Waste and its Management.ppt
22CYT12-Unit-V-E Waste and its Management.ppt
KrishnaveniKrishnara1
 
Software Quality Assurance-se412-v11.ppt
Software Quality Assurance-se412-v11.pptSoftware Quality Assurance-se412-v11.ppt
Software Quality Assurance-se412-v11.ppt
TaghreedAltamimi
 
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressionsKuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
Victor Morales
 
132/33KV substation case study Presentation
132/33KV substation case study Presentation132/33KV substation case study Presentation
132/33KV substation case study Presentation
kandramariana6
 
Hematology Analyzer Machine - Complete Blood Count
Hematology Analyzer Machine - Complete Blood CountHematology Analyzer Machine - Complete Blood Count
Hematology Analyzer Machine - Complete Blood Count
shahdabdulbaset
 
Use PyCharm for remote debugging of WSL on a Windo cf5c162d672e4e58b4dde5d797...
Use PyCharm for remote debugging of WSL on a Windo cf5c162d672e4e58b4dde5d797...Use PyCharm for remote debugging of WSL on a Windo cf5c162d672e4e58b4dde5d797...
Use PyCharm for remote debugging of WSL on a Windo cf5c162d672e4e58b4dde5d797...
shadow0702a
 
Generative AI leverages algorithms to create various forms of content
Generative AI leverages algorithms to create various forms of contentGenerative AI leverages algorithms to create various forms of content
Generative AI leverages algorithms to create various forms of content
Hitesh Mohapatra
 
cnn.pptx Convolutional neural network used for image classication
cnn.pptx Convolutional neural network used for image classicationcnn.pptx Convolutional neural network used for image classication
cnn.pptx Convolutional neural network used for image classication
SakkaravarthiShanmug
 
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
insn4465
 
artificial intelligence and data science contents.pptx
artificial intelligence and data science contents.pptxartificial intelligence and data science contents.pptx
artificial intelligence and data science contents.pptx
GauravCar
 
Introduction to AI Safety (public presentation).pptx
Introduction to AI Safety (public presentation).pptxIntroduction to AI Safety (public presentation).pptx
Introduction to AI Safety (public presentation).pptx
MiscAnnoy1
 
spirit beverages ppt without graphics.pptx
spirit beverages ppt without graphics.pptxspirit beverages ppt without graphics.pptx
spirit beverages ppt without graphics.pptx
Madan Karki
 
学校原版美国波士顿大学毕业证学历学位证书原版一模一样
学校原版美国波士顿大学毕业证学历学位证书原版一模一样学校原版美国波士顿大学毕业证学历学位证书原版一模一样
学校原版美国波士顿大学毕业证学历学位证书原版一模一样
171ticu
 

Recently uploaded (20)

CEC 352 - SATELLITE COMMUNICATION UNIT 1
CEC 352 - SATELLITE COMMUNICATION UNIT 1CEC 352 - SATELLITE COMMUNICATION UNIT 1
CEC 352 - SATELLITE COMMUNICATION UNIT 1
 
International Conference on NLP, Artificial Intelligence, Machine Learning an...
International Conference on NLP, Artificial Intelligence, Machine Learning an...International Conference on NLP, Artificial Intelligence, Machine Learning an...
International Conference on NLP, Artificial Intelligence, Machine Learning an...
 
Transformers design and coooling methods
Transformers design and coooling methodsTransformers design and coooling methods
Transformers design and coooling methods
 
Certificates - Mahmoud Mohamed Moursi Ahmed
Certificates - Mahmoud Mohamed Moursi AhmedCertificates - Mahmoud Mohamed Moursi Ahmed
Certificates - Mahmoud Mohamed Moursi Ahmed
 
BRAIN TUMOR DETECTION for seminar ppt.pdf
BRAIN TUMOR DETECTION for seminar ppt.pdfBRAIN TUMOR DETECTION for seminar ppt.pdf
BRAIN TUMOR DETECTION for seminar ppt.pdf
 
官方认证美国密歇根州立大学毕业证学位证书原版一模一样
官方认证美国密歇根州立大学毕业证学位证书原版一模一样官方认证美国密歇根州立大学毕业证学位证书原版一模一样
官方认证美国密歇根州立大学毕业证学位证书原版一模一样
 
Engineering Drawings Lecture Detail Drawings 2014.pdf
Engineering Drawings Lecture Detail Drawings 2014.pdfEngineering Drawings Lecture Detail Drawings 2014.pdf
Engineering Drawings Lecture Detail Drawings 2014.pdf
 
22CYT12-Unit-V-E Waste and its Management.ppt
22CYT12-Unit-V-E Waste and its Management.ppt22CYT12-Unit-V-E Waste and its Management.ppt
22CYT12-Unit-V-E Waste and its Management.ppt
 
Software Quality Assurance-se412-v11.ppt
Software Quality Assurance-se412-v11.pptSoftware Quality Assurance-se412-v11.ppt
Software Quality Assurance-se412-v11.ppt
 
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressionsKuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
 
132/33KV substation case study Presentation
132/33KV substation case study Presentation132/33KV substation case study Presentation
132/33KV substation case study Presentation
 
Hematology Analyzer Machine - Complete Blood Count
Hematology Analyzer Machine - Complete Blood CountHematology Analyzer Machine - Complete Blood Count
Hematology Analyzer Machine - Complete Blood Count
 
Use PyCharm for remote debugging of WSL on a Windo cf5c162d672e4e58b4dde5d797...
Use PyCharm for remote debugging of WSL on a Windo cf5c162d672e4e58b4dde5d797...Use PyCharm for remote debugging of WSL on a Windo cf5c162d672e4e58b4dde5d797...
Use PyCharm for remote debugging of WSL on a Windo cf5c162d672e4e58b4dde5d797...
 
Generative AI leverages algorithms to create various forms of content
Generative AI leverages algorithms to create various forms of contentGenerative AI leverages algorithms to create various forms of content
Generative AI leverages algorithms to create various forms of content
 
cnn.pptx Convolutional neural network used for image classication
cnn.pptx Convolutional neural network used for image classicationcnn.pptx Convolutional neural network used for image classication
cnn.pptx Convolutional neural network used for image classication
 
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
 
artificial intelligence and data science contents.pptx
artificial intelligence and data science contents.pptxartificial intelligence and data science contents.pptx
artificial intelligence and data science contents.pptx
 
Introduction to AI Safety (public presentation).pptx
Introduction to AI Safety (public presentation).pptxIntroduction to AI Safety (public presentation).pptx
Introduction to AI Safety (public presentation).pptx
 
spirit beverages ppt without graphics.pptx
spirit beverages ppt without graphics.pptxspirit beverages ppt without graphics.pptx
spirit beverages ppt without graphics.pptx
 
学校原版美国波士顿大学毕业证学历学位证书原版一模一样
学校原版美国波士顿大学毕业证学历学位证书原版一模一样学校原版美国波士顿大学毕业证学历学位证书原版一模一样
学校原版美国波士顿大学毕业证学历学位证书原版一模一样
 

Better Interactive Programs

  • 2. Objectives • Learn to build more sophisticated interactive programs using • Picking • Select objects from the display • Three methods • Rubberbanding • Interactive drawing of lines and rectangles • Display Lists • Retained mode graphics 2
  • 3. Picking •Identify a user-defined object on the display •In principle, it should be simple because the mouse gives the position and we should be able to determine to which object(s) a position corresponds •Practical difficulties • Pipeline architecture is feed forward, hard to go from screen back to world • Complicated by screen being 2D, world is 3D • How close do we have to come to object to say we selected it? 3
  • 4. Three Approaches • Hit list • Most general approach but most difficult to implement • Use back or some other buffer to store object ids as the objects are rendered • Rectangular maps • Easy to implement for many applications • See paint program in text 4
  • 5. Rendering Modes • OpenGL can render in one of three modes selected by glRenderMode(mode) • GL_RENDER: normal rendering to the frame buffer (default) • GL_FEEDBACK: provides list of primitives rendered but no output to the frame buffer • GL_SELECTION: Each primitive in the view volume generates a hit record that is placed in a name stack which can be examined later 5
  • 6. Selection Mode Functions •glSelectBuffer(): specifies name buffer •glInitNames(): initializes name buffer •glPushName(id): push id on name buffer •glPopName(): pop top of name buffer •glLoadName(id): replace top name on buffer • id is set by application program to identify objects 6
  • 7. Using Selection Mode • Initialize name buffer • Enter selection mode (using mouse) • Render scene with user-defined identifiers • Reenter normal render mode • This operation returns number of hits • Examine contents of name buffer (hit records) • Hit records include id and depth information 7
  • 8. Selection Mode and Picking • As we just described it, selection mode won’t work for picking because every primitive in the view volume will generate a hit • Change the viewing parameters so that only those primitives near the cursor are in the altered view volume • Use gluPickMatrix (see text for details) 8
  • 9. Using Regions of the Screen •Many applications use a simple rectangular arrangement of the screen • Example: paint/CAD program •Easier to look at mouse position and determine which area of screen it is in than using selection mode picking 9 drawing area tools menus
  • 10. Using another buffer and colors for picking •For a small number of objects, we can assign a unique color (often in color index mode) to each object •We then render the scene to a color buffer other than the front buffer so the results of the rendering are not visible •We then get the mouse position and use glReadPixels() to read the color in the buffer we just wrote at the position of the mouse •The returned color gives the id of the object 10
  • 12. XOR write • Usual (default) mode: source replaces destination (d’ = s) • Cannot write temporary lines this way because we cannot recover what was “under” the line in a fast simple way • Exclusive OR mode (XOR) (d’ = d ⊕ s) • x ⊕ y ⊕ x =y • Hence, if we use XOR mode to write a line, we can draw it a second time and line is erased! 12
  • 13. Rubberbanding • Switch to XOR write mode • Draw object • For line can use first mouse click to fix one endpoint and then use motion callback to continuously update the second endpoint • Each time mouse is moved, redraw line which erases it and then draw line from fixed first position to to new second position • At end, switch back to normal drawing mode and draw line • Works for other objects: rectangles, circles 13
  • 14. Rubberband Lines 14 initial display draw line with mouse in XOR mode mouse moved to new position first point second point original line redrawn with XOR new line drawn with XOR
  • 15. XOR in OpenGL • There are 16 possible logical operations between two bits • All are supported by OpenGL • Must first enable logical operations • glEnable(GL_COLOR_LOGIC_OP) • Choose logical operation • glLogicOp(GL_XOR) • glLogicOp(GL_COPY) (default) 15
  • 16. Immediate and Retained Modes •Recall that in a standard OpenGL program, once an object is rendered there is no memory of it and to redisplay it, we must re-execute the code for it • Known as immediate mode graphics • Can be especially slow if the objects are complex and must be sent over a network •Alternative is define objects and keep them in some form that can be redisplayed easily • Retained mode graphics • Accomplished in OpenGL via display lists 16
  • 17. Display Lists • Conceptually similar to a graphics file • Must define (name, create) • Add contents • Close • In client-server environment, display list is placed on server • Can be redisplayed without sending primitives over network each time 17
  • 18. Display List Functions • Creating a display list GLuint id; void init() { id = glGenLists( 1 ); glNewList( id, GL_COMPILE ); /* other OpenGL routines */ glEndList(); } • Call a created list void display() { glCallList( id ); } 18
  • 19. Display Lists and State • Most OpenGL functions can be put in display lists • State changes made inside a display list persist after the display list is executed • Can avoid unexpected results by using glPushAttrib and glPushMatrix upon entering a display list and glPopAttrib and glPopMatrix before exiting 19
  • 20. Hierarchy and Display Lists 20 •Consider model of a car ­ Create display list for chassis ­ Create display list for wheel glNewList( CAR, GL_COMPILE ); glCallList( CHASSIS ); glTranslatef( … ); glCallList( WHEEL ); glTranslatef( … ); glCallList( WHEEL ); … glEndList();