Better Interactive Programs

Slides:



Advertisements
Similar presentations
Visible-Surface Detection(identification)
Advertisements

2000 Prentice Hall, Inc. All rights reserved. 1 Outline 3.1Introduction 3.2Game Loop Components 3.3How to Implement in C# 3.4Adding Image to XNA Project.
1 Applets Programming Enabling Application Delivery Via the Web.
Copyright © 2003 Pearson Education, Inc. Slide 1.
Making the System Operational
GR2 Advanced Computer Graphics AGR
15.1 Si23_03 SI23 Introduction to Computer Graphics Lecture 15 – Visible Surfaces and Shadows.
OpenGL Open a Win32 Console Application in Microsoft Visual C++.
View-Based Application Development Lecture 1 1. Flows of Lecture 1 Before Lab Introduction to the Game to be developed in this workshop Comparison between.
1 Communication in Distributed Systems REKs adaptation of Tanenbaums Distributed Systems Chapter 2.
FIFO Queues CSE 2320 – Algorithms and Data Structures Vassilis Athitsos University of Texas at Arlington 1.
Charles Kime & Thomas Kaminski © 2004 Pearson Education, Inc. Terms of Use (Hyperlinks are active in View Show mode) Terms of Use Chapter 2 – Combinational.
XP New Perspectives on Introducing Microsoft Office 2003 Tutorial 1 1 Using Common Features of Microsoft Office 2003 Tutorial 1.
1Computer Graphics Building Models John Shearer Culture Lab – space 2
Adobe InDesign CS5 - Illustrated Unit F: Working with Layers
1Computer Graphics Homogeneous Coordinates & Transformations Lecture 11/12 John Shearer Culture Lab – space 2
Lecture 1 – Introduction, Overview
1Computer Graphics Lecture 2 - What is Computer Graphics? John Shearer Culture Lab – space 2
Executional Architecture
Addition 1’s to 20.
Week 1.
CHAPTER 11 FILE INPUT & OUTPUT Introduction to Computer Science Using Ruby (c) 2012 Ophir Frieder et al.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 14: Protection.
Compositing and Blending Ed Angel Professor Emeritus of Computer Science University of New Mexico 1 E. Angel and D. Shreiner: Interactive Computer Graphics.
Graphics Pipeline.
OPENGL Return of the Survival Guide. Buffers (0,0) OpenGL holds the buffers in a coordinate system such that the origin is the lower left corner.
Computer Graphic Creator: Mohsen Asghari Session 2 Fall 2014.
Raster Displays Images are composed of arrays of pixels displayed on a raster device. Two main ways to create images: –Scan and digitize an existing image.
CSC461 Lecture 10: Widgets and Picking Objectives Introduce menus in GLUT Picking –Select objects from the display –Three methods Put things together.
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Better Interactive Programs Ed Angel Professor of Computer Science, Electrical and Computer.
Based on slides created by Edward Angel
Informationsteknologi Tuesday, November 6, 2007Computer Graphics - Class 41 Today’s class Input and interaction.
Picking. What is picking? Selecting an object on the screen What does this require? –Get Mouse Location –Compute what objects are rendered at the position.
1 Perception, Illusion and VR HNRS 299, Spring 2008 Lecture 19 Other Graphics Considerations Review.
19/4/ :32 Graphics II Syllabus Selection and Picking Session 1.
Computing & Information Sciences Kansas State University CIS 536/636 Introduction to Computer Graphics Lecture 26 of 41 William H. Hsu Department of Computing.
CSC461 Lecture 11: Interactive Programs Contents and Objectives Picking Writing modes – XOR/Copy Rubberbanding Display list.
COMPUTER GRAPHICS Hochiminh city University of Technology Faculty of Computer Science and Engineering CHAPTER 03: Input & Interaction.
Fundamentals of Computer Graphics Part 3 prof.ing.Václav Skala, CSc. University of West Bohemia Plzeň, Czech Republic ©2002 Prepared with Angel,E.: Interactive.
Korea University Korea University Computer Graphics Laboratory Computer Graphics Laboratory Jung Lee, Chapter 13.
1Computer Graphics Input and Interaction Lecture 8 John Shearer Culture Lab – space 2
CAP 4703 Computer Graphic Methods Prof. Roy Levow Lecture 3.
Input and Interaction Lecture No. 4.
CSE 470: Computer Graphics. 10/15/ Defining a Vertex A 2D vertex: glVertex2f(GLfloat x, GLfloat y); 2D vertexfloating pointopenGL parameter type.
1 Input and Interaction. 2 Input Devices Physical input devices Keyboard devices and pointing devices Logical input devices.
Computer Graphics I, Fall 2010 Input and Interaction.
Computing & Information Sciences Kansas State University Lecture 20 of 42CIS 636/736: (Introduction to) Computer Graphics Lecture 21 of 42 William H. Hsu.
1 Better Interactive Programs. 2 Objectives Learn to build more sophisticated interactive programs using ­Picking Select objects from the display Three.
OpenGL Selection. Three Selection Methods Color coding (OpenGL) Selection mode (OpenGL) Selection ray (generic)
1Computer Graphics Implementation II Lecture 16 John Shearer Culture Lab – space 2
1 Perception and VR MONT 104S, Fall 2008 Lecture 21 More Graphics for VR.
MAE152 Computer Graphics for Scientists and Engineers Fall 03 Display Lists.
OpenGL Architecture Display List Polynomial Evaluator Per Vertex Operations & Primitive Assembly Rasterization Per Fragment Operations Frame Buffer Texture.
Program 2 due 02/01  Be sure to document your program  program level doc  your name  what the program does  each function  describe the arguments.
1 Input and Interaction. 2 Objectives Introduce the basic input devices ­Physical Devices ­Logical Devices ­Input Modes Event-driven input Introduce double.
University of New Mexico
Input and Interaction Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
Selection Mode, Introduction to Widgets Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Monday, October 6, 2003.
Buffers Ed Angel Professor Emeritus of Computer Science
Better Interactive Programs
CSC461 Lecture 8: Input Devices
Advanced Menuing, Introduction to Picking
Introduction to Computer Graphics with WebGL
Display Lists & Text Glenn G. Chappell
Better Interactive Programs
Computer Graphics Buffers
Computer Graphics Practical Lesson 8
Buffers Ed Angel Professor Emeritus of Computer Science
Presentation transcript:

Better Interactive Programs Computer Graphics Better Interactive Programs Lecture 9 John Shearer Culture Lab – space 2 john.shearer@ncl.ac.uk http://di.ncl.ac.uk/teaching/csc3201/ Computer Graphics 1 Computer Graphics - Newcastle University 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 Computer Graphics 2 Computer Graphics - Newcastle University 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? Computer Graphics 3 Computer Graphics - Newcastle University 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 Computer Graphics 4 Computer Graphics - Newcastle University 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 Computer Graphics 5 Computer Graphics - Newcastle University 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 Computer Graphics 6 Computer Graphics - Newcastle University 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 Computer Graphics 7 Computer Graphics - Newcastle University 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) Computer Graphics 8 Computer Graphics - Newcastle University 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 tools menus drawing area Computer Graphics 9 Computer Graphics - Newcastle University 9

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 Computer Graphics 10 Computer Graphics - Newcastle University 10

Writing Modes application bitwise logical operation frame buffer Computer Graphics 11 Computer Graphics - Newcastle University 11

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) y  x  x =y Hence, if we use XOR mode to write a line, we can draw it a second time and line is erased! Computer Graphics 12 Computer Graphics - Newcastle University 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 Computer Graphics 13 Computer Graphics - Newcastle University 13

Rubberband Lines second point first point draw line with mouse in XOR mode initial display mouse moved to new position original line redrawn with XOR new line drawn with XOR Computer Graphics 14 Computer Graphics - Newcastle University 14

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) Computer Graphics 15 Computer Graphics - Newcastle University 15

A little more on glLogicOp glLogicOp specifies a logical operation that, when enabled, is applied between the incoming color index or RGBA color and the color index or RGBA color at the corresponding location in the frame buffer. Therefore, what ends up in the frame buffer is not necessarily the pixels we tried to draw –the frame buffer can be viewed as a form of memory, hence why one XOR followed by another has sufficient information to undo itself Computer Graphics 16 Computer Graphics - Newcastle University 16

A little more on glLogicOp 2 Computer Graphics 17 Computer Graphics - Newcastle University 17

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 Computer Graphics 18 Computer Graphics - Newcastle University 18

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 Computer Graphics 19 Computer Graphics - Newcastle University 19

Display List Functions Creating a display list GLuint id; void init() { id = glGenLists( 1 ); glNewList( id, GL_COMPILE ); /* other OpenGL routines */ glEndList(); } Call a display list void display() { glCallList( id ); } Computer Graphics 20 Computer Graphics - Newcastle University 20

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 Computer Graphics 21 Computer Graphics - Newcastle University 21

Hierarchy and Display Lists Consider model of a car Create display list for chassis Create display list for wheel glNewList( CAR, GL_COMPILE ); glCallList( CHASSIS ); glTranslatef( … ); glCallList( WHEEL ); … glEndList(); Computer Graphics 22 Computer Graphics - Newcastle University 22