Interaction with Graphics System

Slides:



Advertisements
Similar presentations
OpenGL CMSC340 3D Character Design & Animation. What is OpenGL? A low-level graphics library specification designed for use with the C and C++ provides…
Advertisements

1 Computer Graphics Chapter 2 Input Devices. RM[2]-2 Input Devices Logical Input Devices  Categorized based on functional characteristics.  Each device.
CS 4731 Lecture 2: Intro to 2D, 3D, OpenGL and GLUT (Part I) Emmanuel Agu.
Chapter 3: Input and Interaction Instructor: Shih-Shinh Huang 1.
CSC461 Lecture 10: Widgets and Picking Objectives Introduce menus in GLUT Picking –Select objects from the display –Three methods Put things together.
OpenGL (I). What is OpenGL (OGL)? OGL is a 3D graphics & modeling library Can also use it to draw 2D objects.
CSC 461: Lecture 51 CSC461 Lecture 5: Simple OpenGL Program Objectives: Discuss a simple program Discuss a simple program Introduce the OpenGL program.
InteractionHofstra University1 Graphics Programming Input and Interaction.
31/1/2006Based on: Angel (4th Edition) & Akeine-Möller & Haines (2nd Edition)1 CSC345: Advanced Graphics & Virtual Environments Lecture 3: Introduction.
InteractionHofstra University1 Graphics Programming Input and Interaction.
1 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 GLUT Callback Functions.
Based on slides created by Edward Angel
CSC461 Lecture 9: GLUT Callbacks Objectives Introduce double buffering for smooth animations Programming event input with GLUT.
Today … The rendering pipeline in detail What is OpenGL
CS 480/680 Computer Graphics Programming with Open GL Part 8: Working with Callbacks Dr. Frederick C Harris, Jr. Fall 2011.
Using Graphics Libraries Lecture 3 Mon, Sep 1, 2003.
19/4/ :32 Graphics II Syllabus Selection and Picking Session 1.
Introduction to OpenGL and GLUT GLUT. What is OpenGL? An application programming interface (API) A (low-level) Graphics rendering API Generate high-quality.
1 Working with Callbacks Yuanfeng Zhou Shandong University.
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.
More on Drawing in OpenGL: Examples CSC 2141 Introduction to Computer Graphics.
WORKING WITH CALLBACKS Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico Angel: Interactive.
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.
Input and Interaction Chapter 3. CS 480/680Chapter 3 -- Input and Interaction2 n Introduction: -We now turn to the development of interactive graphics.
Lecture 5: Interaction 1  Principles of Interactive Graphics  CMSCD2012  Dr David England, Room 711,  ex 2271 
School of Computer Science University of Seoul. 1. Interaction 2. Input Devices 3. Clients and Servers 4. Display Lists 5. Programming Event-Driven Input.
Input and Interaction Chapter 3. CS 480/680 2Chapter 3 -- Input and Interaction Introduction: Introduction: We now turn to the development of interactive.
1Computer Graphics Input and Interaction Lecture 8 John Shearer Culture Lab – space 2
CAP 4703 Computer Graphic Methods Prof. Roy Levow Lecture 3.
Lecture 3 OpenGL.
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.
Introduction to GL Geb Thomas. Example Code int main(int argc, char **argv) { glutInit(&argc, argv); glutInitDisplayMode ( GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH);
CS 480/680 Computer Graphics Programming with Open GL Part 7: Input and Interaction Dr. Frederick C Harris, Jr. Fall 2011.
Introduction to OpenGL and GLUT. What’s OpenGL? An Application Programming Interface (API) A low-level graphics programming API – Contains over 250 functions.
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.
Computer Graphics I, Fall 2010 Working with Callbacks.
Input and Interaction Yuanfeng Zhou Shandong University Software College 1.
University of New Mexico
Input and Interaction Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico.
Pop-Up Menus Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Friday, September 26, 2003.
NoufNaief.net TA: Nouf Al-harbi.
GLUT functions glutInit allows application to get command line arguments and initializes system gluInitDisplayMode requests properties for the window.
Doç. Dr. Cemil Öz SAÜ Bilgisayar Mühendisliği Dr. Cemil Öz.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
12/22/ :38 1 Comp 175C - Computer Graphics Dan Hebert Computer Graphics Comp 175 Chapter 3 Instructor: Dan Hebert.
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Input and Interaction Ed Angel Professor of Computer Science, Electrical and Computer Engineering,
31/1/2006Based on: Angel (4th Edition) & Akeine-Möller & Haines (2nd Edition)1 CSC345: Advanced Graphics & Virtual Environments Lecture 2: Introduction.
Introduction to Graphics Programming. Graphics API.
1 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 Working with Callbacks.
CSC Graphics Programming Budditha Hettige Department of Statistics and Computer Science.
INTRODUCTION TO OPENGL
Review GLUT Callback Functions
Computer Graphics - Chapter 3 Input and Interaction
Working with Callbacks
CS5500 Computer Graphics March 2, 2006.
CSC461 Lecture 8: Input Devices
The User Interface Lecture 2 Mon, Aug 27, 2007.
Input and Interaction Chapter 3.
Input and Interactions
Working with Callbacks
PROGRAM 8 newpaint.c E. Angel.
Isaac Gang University of Mary Hardin-Baylor
Fundamentals of Computer Graphics Part 3
Input and Interaction Ed Angel
University of New Mexico
Input and Interaction Ed Angel
Input and Interaction Ed Angel Professor Emeritus of Computer Science,
Presentation transcript:

Interaction with Graphics System User Display React to Change Change Image Input Device

Computer Graphics Conceptual Model API Output Devices Application Program Application Model Graphics System Input Devices Function Calls or Protocol Data

Physical vs. Logical Input Devices Application Program Logical Device Software Driver Physical Device Mouse, Keyboard Trackball, etc.

What is it?

Logical Input Devices String Provides ASCII strings to user program Usually implemented as physical keyboard Locator Inputs position in defined coordinate system Absolute vs. relative Direct vs. indirect Choice Choice among a discrete number of options Implemented by menus or control button widget Valuator (or Dial) Provides analog input to user program Bounded vs. unbounded Often implemented as slidebar widget

Logical Input Devices, contd. Pick Returns identifier of an object to user program Can be implemented by locator and choice Stroke Returns an array of locations

Measure vs. Trigger The measure of a device is the value returned to the user program. String device: ASCII string Locator: Location coordinates Choice: Identifier of option chosen etc. Trigger of a device is a physical signal that the user can use to signal the computer that the measure is available. String device (keyboard): Return key Locator (mouse): mouse button(s)

Request Mode Input 1. Program requests measure of a device and blocks. Trigger Process Measure Process Program Trigger Measure 1. Program requests measure of a device and blocks. 2. Measure process maintains current measure. 3. Trigger process signals measure process to return measure. request_locator(device_id, &measure);

Sample Mode Input 1. Program requests measure of a device and blocks. Process Program Measure 1. Program requests measure of a device and blocks. 2. Measure process immediately returns current measure. sample_locator(device_id, &measure);

Event Mode Input Trigger Process Measure Process Event Queue Program Device & Measure Await Event Queue Events Program Event

Event Driven Interaction-Blocking Initialize, including generating the initial image; Activate input devices in event mode; do { wait for user-triggered event on any device; switch (which device caused event) { case DEVICE_1: collect DEVICE_1 measure, process, respond; case DEVICE_2: collect DEVICE_2 measure, process, respond; ... } while (user does not request exit);

Event Driven Interaction-NonBlocking Initialize, including generating the initial image; Activate input devices in event mode; do { if (there is an event on the event queue) switch (which device caused event) { case DEVICE_1: collect DEVICE_1 data, process, respond; case DEVICE_2: collect DEVICE_2 data, process, respond; ... } Do background processing; while (user does not request exit);

GL Library Organization Window OS Application GL GLU GLUT

GLUT Event Processing Event in Queue No Call Idle Function Yes Call Function n Pop Event From Queue Call Function n Call Function n Call Function n Call Function n Call Function n Switch on Event Type

Callbacks NB: Function parameters must match measures contained Event Type “Registered” Function Event A m1, m2 function_A(m1, m2) Event B function_B( ) Event C function_C( ) Event D Event E Event F No Event Idle function( ) NB: Function parameters must match measures contained in associated event.

Display Event Trigger: GLUT determines that the window needs to be redisplayed. A display event is generated when the window is first drawn. Callback function form: void display(); Registration: glutDisplayFunc(display); A display callback function must be registered for each window.

GLUT Mouse Event Trigger: Any mouse button is depressed or released. Callback function form: void mouse_callback_func(int button, int state, int x, int y); Registration: glutMouseFunc(mouse_callback_function);

GLUT Defined Mouse Constants GLUT_LEFT_BUTTON GLUT_MIDDLE_BUTTON GLUT_RIGHT_BUTTON GLUT_UP GLUT_DOWN Systems with only one mouse button can only generate a GLUT_LEFT_BUTTON callback.

GLUT Reshape Event Trigger: Active window is resized Callback function form: void reshape_func(GLsizei w, GLsizei h); Registration: glutReshapeFunc(reshape_func);

GLUT Move Event Trigger: The mouse is moved while one or more mouse buttons are pressed. Callback function form: void motion_func(int x, int y); Registration: glutMotionFunc(motion_func);

GLUT Keyboard Event Trigger: Any key is depressed. Callback function form: void keyboard_function(unsigned char key, int x, int y); Registration: glutKeyboardFunc(keyboard_function);

Other Defined Events in GLUT glutPassiveMotionFunc glutVisibilityFunc glutEntryFunc glutSpecialFunc glutSpaceballMotionFunc glutSpaceballRotateFunc glutSpaceballButtonFunc glutButtonBoxFunc glutDialsFunc glutTabletMotionFunc glutTabletButtonFunc glutMenuStatusFunc

Example: Simple Square Drawing Program Open a window. Clear it to black. Draw a box at location of the mouse each time the left button is clicked. Color of box should be randomly selected from RGB space. Clear window when resized. Quit when right button is clicked.

Square Program Source Code Slide 1 /* This program illustrates the use of the glut library for interfacing with a Window System */ /* The program opens a window, clears it to black, then draws a box at the location of the mouse each time the left button is clicked. The right button exits the program The program also reacts correctly when the window is moved or resized by clearing the new window to black*/ #include <GL/gl.h> #include <GL/glut.h> /* globals */ GLsizei wh = 500, ww = 500; /* initial window size */ GLfloat size = 3.0; /* half side length of square */

Square Program Source Code Slide 2 void drawSquare(int x, int y) { y=wh-y; glColor3ub( (char) random()%256, (char) random()%256, (char) random()%256); glBegin(GL_POLYGON); glVertex2f(x+size, y+size); glVertex2f(x-size, y+size); glVertex2f(x-size, y-size); glVertex2f(x+size, y-size); glEnd(); glFlush(); }

Square Program Source Code Slide 3 void myReshape(GLsizei w, GLsizei h) { /* adjust clipping box */ glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0.0, (GLdouble)w, 0.0, (GLdouble)h, -1.0, 1.0); glMatrixMode(GL_MODELVIEW); /* adjust viewport and clear */ glViewport(0,0,w,h); glClearColor (0.0, 0.0, 0.0, 0.0); glClear(GL_COLOR_BUFFER_BIT); glFlush(); /* set global size for use by drawing routine */ ww = w; wh = h; }

Square Program Source Code Slide 4 void myinit(void) { glViewport(0,0,ww,wh); /* Pick 2D clipping window to match size of screen window This choice avoids having to scale object coordinates each time window is resized */ glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0.0, (GLdouble) ww , 0.0, (GLdouble) wh , -1.0, 1.0); /* set clear color to black and clear window */ glClearColor (0.0, 0.0, 0.0, 0.0); glClear(GL_COLOR_BUFFER_BIT); glFlush(); /* callback routine for reshape event */ glutReshapeFunc(myReshape); }

Square Program Source Code Slide 5 void mouse(int btn, int state, int x, int y) { if(btn==GLUT_RIGHT_BUTTON&state==GLUT_DOWN) exit(); } int main(int argc, char** argv) glutInit(&argc,argv); glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB); glutCreateWindow("square"); myinit (); glutReshapeFunc (myReshape); glutMouseFunc (mouse); glutMotionFunc(drawSquare); glutMainLoop();

Output of “Square” Program

Implementing Choice: Menus in GLUT Four steps: Create menu: glutCreateMenu(menu); Define menu entries: glutAddMenuEntry Attach menu to a mouse button: gluAttachMenu Define callback function: void menu(int id);

Creating a Menu in GLUT int glutCreateMenu(void (*func)(int value)); Menu Identifier Choice Callback Function Creates a new pop-up menu. Returns a unique integer identifier for the menu. Takes as argument a pointer to a single callback function that takes an integer argument. The integer argument of the callback is mapped to the menu choice. Sets the current menu to the newly created menu.

Associating a Menu with a Mouse Key void glutAttachMenu(int button); Associates the selected button with the current menu. button is selected from the GLUT defined button constants: GLUT_LEFT_BUTTON, GLUT_MIDDLE_BUTTON, GLUT_RIGHT_BUTTON

Adding Entries to the Menu void glutAddMenuEntry(char *name, int value); String to appear in menu entry. Value to be passed to callback function. Adds a menu entry to the bottom of the current menu.

Building a Sub-menu void glutAddSubMenu(char *name, int menu); ASCII string to display in the menu item from which to cascade sub-menu. Identifier of menu to cascade from this sub-menu item.