Advanced Menuing, Introduction to Picking

Slides:



Advertisements
Similar presentations
Better Interactive Programs
Advertisements

Informationsteknologi Monday, November 12, 2007Computer Graphics - Class 71 Today’s class Viewing transformation Menus Mandelbrot set and pixel drawing.
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.
InteractionHofstra University1 Graphics Programming Input and Interaction.
CS 480/680 Computer Graphics Programming with Open GL Part 8: Working with Callbacks Dr. Frederick C Harris, Jr. Fall 2011.
Course Overview, Introduction to CG Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Friday, September 5, 2003.
Mouse-Based Viewing & Navigation Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Monday, November 3, 2003.
Basic OpenGL Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Wednesday, September 10, 2003.
CSC461 Lecture 11: Interactive Programs Contents and Objectives Picking Writing modes – XOR/Copy Rubberbanding Display list.
Linear Interpolation, Brief Introduction to OpenGL Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Monday, September.
IE 411/511: Visual Programming for Industrial Applications
CAP 4703 Computer Graphic Methods Prof. Roy Levow Lecture 3.
Input and Interaction Lecture No. 4.
1 Input and Interaction. 2 Input Devices Physical input devices Keyboard devices and pointing devices Logical input devices.
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.
More on Advanced Interfaces, Image Basics Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Friday, November 21, 2003.
1 Better Interactive Programs. 2 Objectives Learn to build more sophisticated interactive programs using ­Picking Select objects from the display Three.
Advanced HSR Methods Glenn G. Chappell U. of Alaska Fairbanks CS 481/681 Lecture Notes Friday, January 30, 2004.
Build-A-Button Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Wednesday, October 8, 2003.
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.
More on GLUT Programming Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Monday, September 15, 2003.
Computer Graphics: Programming, Problem Solving, and Visual Communication Steve Cunningham California State University Stanislaus and Grinnell College.
1 Graphics CSCI 343, Fall 2015 Lecture 6 Viewing, Animation, User Interface.
Pop-Up Menus Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Friday, September 26, 2003.
Accumulation-Based Effects Glenn G. Chappell U. of Alaska Fairbanks CS 481/681 Lecture Notes Wednesday, February 4, 2004.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
Introduction to Input/Interaction Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Friday, September 19, 2003.
Selection Mode, Introduction to Widgets Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Monday, October 6, 2003.
Some Notes on 3-D Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Friday, October 24, 2003.
Graphics Programming. Graphics Functions We can think of the graphics system as a black box whose inputs are function calls from an application program;
Introduction to 3-D Viewing Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Monday, October 27, 2003.
Computer Graphics (Fall 2003) COMS 4160, Lecture 5: OpenGL 1 Ravi Ramamoorthi Many slides courtesy Greg Humphreys.
Lecture 9 From Vertices to Fragments. Objectives Introduce basic implementation strategies Clipping Rasterization hidden-surface removal.
Arrays Chapter 7.
Dive Into® Visual Basic 2010 Express
- Introduction - Graphics Pipeline
OVERVIEW Objectives Follow a design document to prepare images for inclusion in a Web page Run a batch process to prepare multiple images in one step Use.
Stenciling Effects Glenn G. Chappell
Working in the Forms Developer Environment
Working with Callbacks
Introduction to Event-Driven Programming
Introduction to the Mouse
Better Interactive Programs
Computer Graphics Lecture 33
3.01 Apply Controls Associated With Visual Studio Form
Lecture 18 Fasih ur Rehman
The Graphics Rendering Pipeline
CS451Real-time Rendering Pipeline
The User Interface Lecture 2 Mon, Aug 27, 2007.
Learning Objectives • Dynamic Input Line tool. • Coordinate systems.
Chapter 13: Advanced GUIs and Graphics
Chapter 1 Editing a Photo
Introduction to Computing Using Java
Working with Callbacks
Tutorial 6 Creating Dynamic Pages
Introduction to Computer Graphics with WebGL
Projection in 3-D Glenn G. Chappell
Display Lists & Text Glenn G. Chappell
Better Interactive Programs
DB Implementation: MS Access Forms
Lecture 13 Clipping & Scan Conversion
More on Widgets, Misc. Topics
Getting Started with Adobe Illustrator CS6
Topics Graphical User Interfaces Using the tkinter Module
CS297 Graphics with Java and OpenGL
Frame Buffers Fall 2018 CS480/680.
Preview of 3-D Graphics Glenn G. Chappell
Advanced GUIs and Graphics
Presentation transcript:

Advanced Menuing, Introduction to Picking Glenn G. Chappell CHAPPELLG@member.ams.org U. of Alaska Fairbanks CS 381 Lecture Notes Monday, September 29, 2003

Review: Using GLUT Menus [1/3] What we can do with GLUT menus: We can create (and destroy) menu data structures. Create a menu with glutCreateMenu. Creation  display. We can add entries (and submenus) to an existing menu. Add an entry with glutAddMenuEntry. We can attach a previously created menu to a mouse button (and we can also detach it). Attach a menu with glutAttachMenu. We can change the entries of a menu. Each menu has associated callback: the handler function. This is called when the user selects an entry in that menu. As is typical with GUI toolkits, under GLUT the application does not draw pop-up menus. GLUT does that. GLUT is entirely in control while a pop-up menu is visible. 29 Sep 2003 CS 381

Review: Using GLUT Menus [2/3] The menu-creation function from creature.cpp. This is called in function init. void make_main_menu() { glutCreateMenu(handle_main_menu); glutAddMenuEntry("Toggle eye color", 1); glutAddMenuEntry("Toggle mouth motion", 2); glutAddMenuEntry("Quit", 3); glutAddMenuEntry("------------------------", 999); … glutAddMenuEntry("for CS 381, fall 2003", 999); glutAttachMenu(GLUT_RIGHT_BUTTON); } 29 Sep 2003 CS 381

Review: Using GLUT Menus [3/3] The menu handler function from creature.cpp. Must be declared before make_main_menu. As with all GLUT callbacks, you do not call this function; GLUT does. // handle_main_menu // Menu handling callback function for our menu void handle_main_menu(int value) { switch (value) case 1: // Toggle eye color blueeyes = !blueeyes; glutPostRedisplay(); break; … case 3: // Quit exit(0); case 999: // Other menu items do nothing 29 Sep 2003 CS 381

(Review?) Advanced Menuing: The Current Menu Some GLUT menuing commands (e.g., glutAddMenuEntry, glutAttachMenu) deal with the current menu. If you have just one menu, then it is the current menu. glutCreateMenu sets the current menu to the menu created. In a menu handler, the current menu is the one handled. Function glutCreateMenu returns an int identifying the menu created. If you have multiple menus, save this value. int menu_x = glutCreateMenu(handle_menu_x); You can set the current menu yourself using glutSetMenu. There is also a “current window”. It is dealt with similarly. 29 Sep 2003 CS 381

(Review?) Advanced Menuing: Submenus A submenu is a menu that is an item in another menu. To make a submenu (in the “main” menu): Create the submenu (as an ordinary menu, but do not attach it). Create the main menu. Use glutAddSubMenu to make submenu an item in the main menu. int superduper_menu = glutCreateMenu(handle_superduper_menu); … int rightmouse_menu = glutCreateMenu(handle_rightmouse_menu); glutAddSubMenu("Super-Duper Stuff", superduper_menu); The submenu does not need to be attached. See dumbsubmenus.cpp, on the web page, for sample code. 29 Sep 2003 CS 381

(Review?) Advanced Menuing: Changing Menu Entries To change the text or return value of a menu entry: Set the the current menu, by passing the proper ID to glutSetMenu. If you are in the menu handler, this is unnecessary. glutSetMenu(superduper_menu); Use glutChangeToMenuEntry to set the new text & return value. This function takes 3 parameters: The entry number (int): count from the top of the menu, starting at 1. The new text (char*). The new return value (int). glutChangeToMenuEntry(1, the_entry.c_str(), 1); You can also change submenus, using glutChangeToSubMenu; see the GLUT documentation. See menuchange.cpp, on the web page, for sample code. 29 Sep 2003 CS 381

Picking: Overview With a pointing device we can point at things. The program must determine what is being pointed at. This called picking. We will discuss: What picking is and what it is for. Issues involved in picking. Three picking methods. The “obvious” method, and two that depend on specialized commands. The first programming assignment after the test (#4) will involve picking. 29 Sep 2003 CS 381

Picking: Definitions In a CG scene, we often have a number of objects. Objects are made up of graphics primitives. The extent of an object or primitive is the collection of pixels (screen positions) that are used to display it. When the user clicks the mouse, we generally want to know: Whether the click was in the extent of an object and, if so, which object. We use the term picking to encompass both the user’s action and the program’s determination of which object was chosen. Sometimes we consider the concept of extent in a looser fashion. We can allow clicks near an object, not necessarily right on it. Sometimes we allow clicks anywhere in the smallest screen-aligned rectangle that encloses a displayed object. This is called the bounding rectangle. 29 Sep 2003 CS 381

Picking: Uses When do we use picking? When doing click-and-drag: Moving/resizing windows. Moving icons. When using widgets (controls). What kind of mouse-based input does not involve picking? Various game controls. Painting. Unless you count the in-drawing-area test. 29 Sep 2003 CS 381

Picking: Issues Recall the OpenGL geometry rendering pipeline: We send geometric primitives into the pipeline. Images on the screen emerge. When we do picking, we want to reverse this. We begin with a screen position (the mouse location). We want to know what primitive, if any, appears there. Again, primitives are generally grouped into objects. But the geometry pipeline does not run backwards! Vertex Operations Rasterization Fragment Operations Vertex enters here To framebuffer Vertices (object coordinates) Vertices (window coordinates) Fragments Fragments 29 Sep 2003 CS 381

Picking: Method #1: Extent Testing The “obvious” way to do picking: Figure out the extent of each object. For each, test whether the mouse position is inside it. In a 2½-D interface (e.g., overlapping windows), can test in front-to-back order. Disadvantage Can be tricky, if objects are not screen-aligned rectangles. (However, they very often are!) Next we look at two methods that take advantage of CG internals, and do not have the above problem. 29 Sep 2003 CS 381

Picking: Method #2: Buffer Reading [1/2] If we can read the frame buffer: Draw each object in a different, solid color. Read the color of the pixel at the mouse position to determine what was clicked on. Double buffering makes this nicer. Draw to and read from the back buffer, without swapping. Then users don’t need to see the strangely colored version of the scene. 29 Sep 2003 CS 381

Picking: Method #2: Buffer Reading [2/2] The OpenGL command glReadPixels reads a rectangular block of pixels from a color buffer. The block can be 11 (a single pixel). Watch out for precision! The color returned may not be exactly the color that was drawn. May need to call glDrawBuffer to set which buffer is drawn to. 1 parameter: generally GL_FRONT (default) or GL_BACK. When double buffering is enabled (GLUT_DOUBLE), GLUT does “glDrawBuffer(GL_BACK);”. So you probably do not need to call glDrawBuffer yourself. May need to call glReadBuffer to set which buffer is read. 29 Sep 2003 CS 381

Picking: Method #3: Selection Mode OpenGL allows “names” to be given to primitives. A name is just an integer, as usual. In selection mode, the application can get a list of the names of primitives that made it all the way to rasterization. That is, those primitives that were not discarded during clipping. The Method Name each object in the scene. Assign a name to each primitive according to what object it is part of. Set the clipping region to be a very small rectangle at the mouse position. Set selection mode and draw the scene. As with the previous method, the user need not see the results. Get the list. It contains the names of objects that were clicked on. If there is more than one, take the front-most. OpenGL details in a forthcoming lecture … 29 Sep 2003 CS 381