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.

Slides:



Advertisements
Similar presentations
Better Interactive Programs
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.
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.
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.
Programming with OpenGL Part 1: Background Mohan Sridharan Based on slides created by Edward Angel CS4395: Computer Graphics 1.
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.
Informationsteknologi Tuesday, November 6, 2007Computer Graphics - Class 41 Today’s class Input and interaction.
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.
Suriyong L., Computer Multimedia1 Input and Interaction Interactive program is something make CG look interesting.
19/4/ :32 Graphics II Syllabus Selection and Picking Session 1.
Chapter 3.   Interactive design of buildings,  Control of large systems through graphical interfaces,  Virtual-reality systems  Computer games. Applications.
CSC461 Lecture 11: Interactive Programs Contents and Objectives Picking Writing modes – XOR/Copy Rubberbanding Display list.
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.
WORKING WITH CALLBACKS Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico Angel: Interactive.
Interaction with Graphics System
Input and Interaction Chapter 3. CS 480/680Chapter 3 -- Input and Interaction2 n Introduction: -We now turn to the development of interactive graphics.
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.
Input and Interaction Lecture No. 4.
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.
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Programming with OpenGL Part 1: Background Ed Angel Professor of Computer Science, Electrical.
Computing & Information Sciences Kansas State University Lecture 20 of 42CIS 636/736: (Introduction to) Computer Graphics Lecture 21 of 42 William H. Hsu.
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.
Interactive Computer Graphics CS 418 MP1: Dancing I TA: Zhicheng Yan Sushma S Kini Mary Pietrowicz Slides Taken from: “An Interactive Introduction to OpenGL.
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: Programming, Problem Solving, and Visual Communication Steve Cunningham California State University Stanislaus and Grinnell College.
Computer Graphics I, Fall 2010 Working with Callbacks.
Input and Interaction Yuanfeng Zhou Shandong University Software College 1.
University of New Mexico
GLUT functions glutInit allows application to get command line arguments and initializes system gluInitDisplayMode requests properties for the window.
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.
1 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 Working with Callbacks.
Computer Graphics (Fall 2003) COMS 4160, Lecture 5: OpenGL 1 Ravi Ramamoorthi Many slides courtesy Greg Humphreys.
Review GLUT Callback Functions
Computer Graphics and Visualization (06 CS 65)
Computer Graphics - Chapter 3 Input and Interaction
Working with Callbacks
Better Interactive Programs
CSC461 Lecture 8: Input Devices
Introduction to Computer Graphics with WebGL
Input and Interaction Chapter 3.
Working with Callbacks
Better Interactive Programs
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:

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 Computer Graphics – A Top Down Approach with OpenGL, Addison Wesley, 2001

Fundamentals of Computer Graphics2 Input & Interaction Till now – no interaction 1.Introduction of devices for interaction 2.how devices “appear” in your program 3.client-server network & client-server graphics 4.development of a painting program First attempt: - 37 years! Project Sketchpad – Sutherland Different approach will be taken – we will use API, but OpenGL does not support it directly – due to portability of the renderer, interaction with OS etc.

Fundamentals of Computer Graphics3 Input Devices Two possible ways to see input devices: as a physical device – keyboard, mouse, trackball, etc. as a logical device – from a programmer perspective – with specified functionality, in graphics more complex the separation of physical and logical levels enable us to make programs more flexible, independent from the actual physical device

Fundamentals of Computer Graphics4 Physical Input Devices Physical input devices: pointing device – allows to indicate position & send signals/interrupts to the computer – relative/absolute positioning keyboard device – almost physical keyboard – returns character codes to a program

Fundamentals of Computer Graphics5 Physical Input Devices Absolute positioning: data tablets light pen joystick – variable-sensitivity device & haptic device spaceball – up-down, left-right, front-back & 3 independent twists

Fundamentals of Computer Graphics6 Logical Input Devices Some APIs (PHIGS, GKS, Direct xx) supports 6 classes of logical input devices – OpenGL does not take this approach String – logical device providing ASCII strings – keyboard Locator – provides a position in world coordinates – usually implemented via pointing device – mouse, trackball. OpenGL provides similar but conversion from screen coordinates to world coordinates must be made by a user Pick – returns identifier of an object – in OpenGL process called selection can be used to accomplish picking

Fundamentals of Computer Graphics7 Logical Input Devices Choice – allows the user to select on of a discrete number of options – in OpenGL various widgets provided by the window system can be used; widget is a graphical interactive device provided by window system or a toolkit (menu with n selections etc.) Dial – provides analog input to the user program – slidebars etc. Stroke – device returns an array of locations – different implementations – usually: mouse button down, transfer data to an array with different positions, release button – ends the transfer

Fundamentals of Computer Graphics8 Input Devices & Modes Two entities: a measure process – is what the device returns to the user program (string from a keyboard) a device trigger – is a physical input on the device which user can signal the computer (return – end of the process) Modes: request – value is returned on a request sample mode – actual value is given (no buffering) request_locator ( device_id, &measure); /* usual form */ sample_locator (device_id, &measure);

Fundamentals of Computer Graphics9 Input Devices & Modes Request versus Sample modes Generally sample & request modes are not sufficient for Human-Computer-Interface (HCI)

Fundamentals of Computer Graphics10 Input Devices & Modes Event mode working in environment with multiple input devices – each has its own trigger and running measure process each time when the device is triggered – the event is generated, the measure with the process identifier is placed in an event queue. The program can examine the front event in the queue and decides what to do – this is used for GKS, PHIGS etc.

Fundamentals of Computer Graphics11 Input Devices & Modes - Callback Callback another approach – association of a callback function with a specific type of event – mostly used in windowing system and client/server environments int main (...) {....glutMouseFunc(mouse); glutDisplayFunc(...);..} void mouse_callback_func(int button, int state, int x, int y) { if button ==GLUT_LEFT_BUTTON && state==GLUT_DOWN) drawSquare(x,y); /*users function*/ if button ==GLUT_MIDDLE_BUTTON && state==GLUT_DOWN) exit (); } /* window reshape principle */

Fundamentals of Computer Graphics12 Clients-Servers Our programs worked on single & isolated system so far, but it should also work in distributed computing and networks Distributed graphics, projection walls etc.

Fundamentals of Computer Graphics13 Display Lists Instructions are stored in a display memory – display file – display list Modes: - immediate – each element is processed and displayed - retained – objects are defined & stored in a display list on a server & redisplayed on the client request Display processor architecture Early graphics systems

Fundamentals of Computer Graphics14 Definition & Execution of Display Lists #define BOX 1 glNewList(Box, GL_COMPILE); /* sends to the server*/ glBegin(GL_POLYGON); glColor3f(1.0, 1.0, 1.0); glVertex2f(-1.0, -1.0); glVertex2f( 1.0, -1.0); glVertex2f( 1.0, 1.0); glVertex2f(-1.0, 1.0); glEnd( ); glEndList ( ); /* GL_COMPILE_AND_EXECUTE – immediate display */ Drawing – execution glCallList(BOX);

Fundamentals of Computer Graphics15 Display Lists & Transformations If model-view or projection matrices changed between execution of the display list – the drawn model will appear at different positions glMatrixModel(GL_PROJECTION); for (i=1; i<5; i++); { glLoadIdentity( ); gluOrtho2D(-2.0*i, 2.0*i, -2.0*i, 2.0*i ); glCallList(BOX); }

Fundamentals of Computer Graphics16 Display Lists & Push/Pop ! Color is changed whenever the list is executed Execution of the display list changes the state and attributes in general – may cause unexpected effects it is possible and recommended to store them in the stack at the beginning of the display list specification glPushAttrib(GL_ALL_ATTRIB_BITS); glPushMatrix( ); at the end of the display list specification glPopAttrib( ); glPopMatrix ( );

Fundamentals of Computer Graphics17 Characters, Fonts & Strings Study chapter on your own

Fundamentals of Computer Graphics18 Programming Event Driven Input Pointing device: passive move event – mouse moved without pressing a button move event - mouse moved with a button pressed, or button released (some systems counts the pushing & releasing of a button as only a single event) glutMouseFunc(mouse_callback_func) /* registration */ void mouse_callback_func(int button, int state, int x, int y); { if (button==GLUT_LEFT_BUTTON && state==GLUT_DOWN) exit ( ); } /* the left button pressed will be omitted no action will be taken as no corresponding action is specified */

Fundamentals of Computer Graphics19 Programming Event Driven Input int main (int argc, char **argv); { glutInit(&argc, argv); glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); glutCreateWindow(“square”);/* create a window with name square */ myinit( ); glutReshapeFunc(myReshape); /* generated if window size changed*/ glutMouseFunc(mouse); /* activated if status or position of a mouse changed */ glutDisplayFunc(display); /* GLUT call back requires it strictly – in case of no action */ /* void display ( ) { } must be specified – empty function */ glutMainLoop( ); }

Fundamentals of Computer Graphics20 Programming Event Driven Input Keyboards events: glutKeyBoardFunc ( keyboard); /* registration */ void keyboard (unsigned char key, int x, int y); {if (key == ‘q’ || key == ‘Q’) exit ( ); /* exits the program */ } Special functions: glutPostDisplay ( ) /* if window iconified redrawing is postoned */ Multiple Window management: id = glutCreateWindow(“second window”); /* int id*/ glutSetWindow (id) ; /* sets the window into which object will be rendered */

Fundamentals of Computer Graphics21 Menus & Picking Study chapter 3.6 – 3.7 on your own

Fundamentals of Computer Graphics22 Menu Pop-up menus glutCreateMenu(demo_menu); glutAddmenuEntry(“quit”,1); glutAddmenuEntry(“increase square size”,2); glutAddmenuEntry(“decrease square size”,3); glutAttachmenu(GLUT_RIGHT_BUTTON); void demo_menu(int id); { if (id ==1) exit ( ); else if (id ==2) size = size * 2; else if (id ==3) size = size / 2; glutPostRedisplay( ); /* glutDisplayFunc is called-redisplay without menu */ }

Fundamentals of Computer Graphics23 Animation Study chapter 3.9 on your own

Fundamentals of Computer Graphics24 Animation For animation – double buffering glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE); Buffers: front – content visible on the display back – where the rendering is made to the display function must be added glutSwapBuffers ( );

Fundamentals of Computer Graphics25 Conclusion Study on your own: Chapter – 3, text, strings & character drawing Chapter 3.8 – simple Paint Program, Chapter 3.9 – Animating Interactive Program Chapter 3.10 – Design of Interactive Programs Make some experiments with display list construction and discuss efficiency of its use for complex objects