CSC461 Lecture 11: Interactive Programs Contents and Objectives Picking Writing modes – XOR/Copy Rubberbanding Display list.

Slides:



Advertisements
Similar presentations
OpenGL Open a Win32 Console Application in Microsoft Visual C++.
Advertisements

Better Interactive Programs
Status – Week 257 Victor Moya. Summary GPU interface. GPU interface. GPU state. GPU state. API/Driver State. API/Driver State. Driver/CPU Proxy. Driver/CPU.
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.
Chapter 12 Interactive Graphics Chih-Kuo Yeh. Direct Manipulation Demo.
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Better Interactive Programs Ed Angel Professor of Computer Science, Electrical and Computer.
Projections and Picking Wed 24 Sep 2003
Hierarchical ModelingHofstra University1 Modeling Define volumetric objects in terms of surfaces patches that surround the volume Each surface patch is.
University of British Columbia CPSC 414 Computer Graphics Week 3, Monday 15 Oct 03 © Tamara Munzner 1 Hierarchies, Display Lists recap: matrix hierarchies,
Based on slides created by Edward Angel
OpenGL (II). How to Draw a 3-D object on Screen?
Informationsteknologi Tuesday, November 6, 2007Computer Graphics - Class 41 Today’s class Input and interaction.
2D Transformations. World Coordinates Translate Rotate Scale Viewport Transforms Hierarchical Model Transforms Putting it all together.
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.
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.
Demetriou/Loizidou – ACSC330 – Chapter 3 Input and Interaction Dr. Giorgos A. Demetriou Dr. Stephania Loizidou Himona Computer Science Frederick Institute.
Graphical Objects and Scene Graphs 1 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009.
COMPUTER GRAPHICS Hochiminh city University of Technology Faculty of Computer Science and Engineering CHAPTER 03: Input & Interaction.
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Chapter 3: Input and Interaction.
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Programming with OpenGL Part 3: Three Dimensions Ed Angel Professor of Computer Science,
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.
1 k Jarek Rossignac,  2008 Processing  Install Processing  Learn how to edit, run, save, export, post programs  Understand.
Korea University Korea University Computer Graphics Laboratory Computer Graphics Laboratory Jung Lee, Chapter 13.
Picking and Curves Week 6 David Breen Department of Computer Science Drexel University Based on material from Ed Angel, University of New Mexico CS 480/680.
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.
Homogeneous Form, Introduction to 3-D Graphics Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Monday, October 20,
Computing & Information Sciences Kansas State University Lecture 20 of 42CIS 636/736: (Introduction to) Computer Graphics Lecture 21 of 42 William H. Hsu.
Week 4 Lecture 1: Hierarchical Modeling Part 1 Based on Interactive Computer Graphics (Angel) - Chapter 10 1 Angel: Interactive Computer Graphics 5E ©
CS 480/680 Computer Graphics Programming with Open GL Part 7: Input and Interaction Dr. Frederick C Harris, Jr. Fall 2011.
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)
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 E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012 Programming with OpenGL Part 2: Complete Programs Ed Angel Professor.
What are shaders? In the field of computer graphics, a shader is a computer program that runs on the graphics processing unit(GPU) and is used to do shading.
OpenGL API 2D Graphic Primitives Angel Angel: Interactive Computer Graphics5E © Addison-Wesley
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.
Computer Graphics I, Fall Programming with OpenGL Part 2: Complete Programs.
Computer Graphics and Visualization (06 CS 65)
Better Interactive Programs
Input and Interaction Ed Angel
CSC461 Lecture 8: Input Devices
Programming with OpenGL Part 2: Complete Programs
Advanced Menuing, Introduction to Picking
Input and Interactions
Project 1: Into Space! CG Concepts Needed
Introduction to Computer Graphics with WebGL
Display Lists & Text Glenn G. Chappell
Better Interactive Programs
Fundamentals of Computer Graphics Part 3
Input and Interaction Ed Angel
University of New Mexico
Computer Graphics Practical Lesson 8
Input and Interaction Ed Angel
Programming with OpenGL Part 2: Complete Programs
Programming with OpenGL Part 2: Complete Programs
Picking in OpenGL Yingcai Xiao.
Presentation transcript:

CSC461 Lecture 11: Interactive Programs Contents and Objectives Picking Writing modes – XOR/Copy Rubberbanding Display list

Bounding Rectangles: Paint A simple painting program with text, lines, triangles, rectangles, and points Useful for CAD design int pick(int x, int y) { y = wh – y; if (y<wh-ww/10) return 0; else if (x<ww/10) return LINE; else if (x<ww/5) return RECTANGLE; else if (x<3*ww/10) return TRIANGLE; else if (x<2*ww/5) return POINTS; else if (x<ww/2) return TEXT; else if return 0; } ABC

Hit List: 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

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

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

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 –gluPickMatrix(x, y, w, h, *vp) –Creates a projection matrix for picking that restricts drawing to a w x h area centered at (x, y) within the viewport vp. –Only in the buffer, not on the screen Reenter normal render mode –GLInt glRenderMode(GL_RENDER); –Returns the number of hits Process the hits to find the object picked

Writing Modes frame buffer application ‘ bitwise logical operation

XOR write Usual (default) mode: source replaces destination (d’ = s) – copy mode –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!

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 (copy mode) drawing mode and draw line –Works for other objects: rectangles, circles

Rubberband Lines 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)

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

Display Lists – user-defined objects 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

Render Mode Flag GL_COMPILE send the display list to the server but not display its content GL_COMPILE_AND EXECUTE immediate display the content and save the list to the server

Display List Functions Creating a display list – –glNewList … glEndList Call a created list –glCallList GLuint id; glNewList( id, GL_COMPILE ); glBegin(GL_POLYGON); /* define a polygon */ glEnd();glEndList(); void display( void ) { glCallList( id ); glCallList( id );}

Multiple Display Lists Generate a set of display lists glGenLists(num) – generate num display lists, return the index of the first list Call a list of display lists glListBase(base) // set the first list glCallLists(num, type, pointer) // pointer to an array of values, base+array-element is the display list identifiers

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

Hierarchy and Display Lists Consider model of a car ­Create display list for chassis ­Create display list for wheel 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();