cs 4204 computer graphics
play

CS 4204 Computer Graphics Window based Window based programming - PowerPoint PPT Presentation

CS 4204 Computer Graphics Window based Window based programming and GLUT programming and GLUT Yong Cao Yong Cao Virginia Tech Virginia Tech References: References: Interactive Computer Graphics, Fourth Edition, Ed Angle Interactive


  1. CS 4204 Computer Graphics Window based Window based programming and GLUT programming and GLUT Yong Cao Yong Cao Virginia Tech Virginia Tech References: References: Interactive Computer Graphics, Fourth Edition, Ed Angle Interactive Computer Graphics, Fourth Edition, Ed Angle

  2. Objectives Introduce the basic input devices Introduce the basic input devices Introduce the basic input devices • Physical Devices Physical Devices • • Physical Devices • Input Modes Input Modes • • Input Modes Event- -driven input driven input Event Event-driven input Introduce double buffering for smooth Introduce double buffering for smooth Introduce double buffering for smooth animations animations animations Programming event input with GLUT Programming event input with GLUT Programming event input with GLUT

  3. Project Sketchpad Ivan Sutherland (MIT 1963) established the Ivan Sutherland (MIT 1963) established the Ivan Sutherland (MIT 1963) established the basic interactive paradigm that characterizes basic interactive paradigm that characterizes basic interactive paradigm that characterizes interactive computer graphics: interactive computer graphics: interactive computer graphics: • User sees an User sees an object object on the display on the display • • User sees an object on the display • User points to ( User points to ( picks picks ) the object with an input device ) the object with an input device • • User points to ( picks ) the object with an input device (light pen, mouse, trackball) (light pen, mouse, trackball) (light pen, mouse, trackball) • Object changes (moves, rotates, morphs) Object changes (moves, rotates, morphs) • • Object changes (moves, rotates, morphs) • Repeat Repeat • • Repeat

  4. Graphical Input Devices can be described either by Devices can be described either by Devices can be described either by • Physical properties Physical properties • • Physical properties – Mouse – Mouse – Mouse – Keyboard Keyboard – – Keyboard – – Trackball Trackball – Trackball • Logical Properties Logical Properties • • Logical Properties – What is returned to program via API What is returned to program via API – – What is returned to program via API • A position • A position • A position • An object identifier An object identifier • • An object identifier Modes Modes Modes • • How and when input is obtained How and when input is obtained • How and when input is obtained – Request or event – Request or event – Request or event

  5. Physical Devices mouse trackball light pen data tablet joy stick space ball

  6. Input Modes Input devices contain a trigger trigger which can be used which can be used Input devices contain a Input devices contain a trigger which can be used to send a signal to the operating system to send a signal to the operating system to send a signal to the operating system • Button on mouse • Button on mouse • Button on mouse • Pressing or releasing a key • Pressing or releasing a key • Pressing or releasing a key When triggered, input devices return information When triggered, input devices return information When triggered, input devices return information (their measure measure ) to the system ) to the system (their (their measure ) to the system • Mouse returns position information Mouse returns position information • • Mouse returns position information • Keyboard returns ASCII code Keyboard returns ASCII code • • Keyboard returns ASCII code

  7. Request Mode Input provided to program only when user Input provided to program only when user Input provided to program only when user triggers the device triggers the device triggers the device Typical of keyboard input Typical of keyboard input Typical of keyboard input • Can erase (backspace), edit, correct until enter Can erase (backspace), edit, correct until enter • • Can erase (backspace), edit, correct until enter (return) key (the trigger) is depressed (return) key (the trigger) is depressed (return) key (the trigger) is depressed

  8. Event Mode Most systems have more than one input Most systems have more than one input Most systems have more than one input device, each of which can be triggered at an device, each of which can be triggered at an device, each of which can be triggered at an arbitrary time by a user arbitrary time by a user arbitrary time by a user Each trigger generates an event event whose whose Each trigger generates an Each trigger generates an event whose measure is put in an event queue event queue which can which can measure is put in an measure is put in an event queue which can be examined by the user program be examined by the user program be examined by the user program

  9. Event Types Window: resize, expose, iconify iconify Window: resize, expose, Window: resize, expose, iconify Mouse: click one or more buttons Mouse: click one or more buttons Mouse: click one or more buttons Motion: move mouse Motion: move mouse Motion: move mouse Keyboard: press or release a key Keyboard: press or release a key Keyboard: press or release a key Idle: nonevent Idle: nonevent Idle: nonevent • Define what should be done if no other event is in Define what should be done if no other event is in • • Define what should be done if no other event is in queue queue queue

  10. Callbacks Programming interface for event- -driven driven Programming interface for event Programming interface for event-driven input input input Define a callback function callback function for each type of for each type of Define a Define a callback function for each type of event the graphics system recognizes event the graphics system recognizes event the graphics system recognizes This user- -supplied function is executed supplied function is executed This user This user-supplied function is executed when the event occurs when the event occurs when the event occurs GLUT example: glutMouseFunc(mymouse GLUT example: GLUT example: glutMouseFunc(mymouse) glutMouseFunc(mymouse) ) mouse callback function

  11. GLUT callbacks GLUT recognizes a subset of the events GLUT recognizes a subset of the events GLUT recognizes a subset of the events recognized by any particular window system recognized by any particular window system recognized by any particular window system (Windows, X, Macintosh) (Windows, X, Macintosh) (Windows, X, Macintosh) glutDisplayFunc • glutDisplayFunc glutDisplayFunc • • glutMouseFunc • glutMouseFunc glutMouseFunc • • glutReshapeFunc • glutReshapeFunc glutReshapeFunc • • glutKeyboardFunc • glutKeyboardFunc glutKeyboardFunc • • glutIdleFunc • glutIdleFunc glutIdleFunc • • glutMotionFunc, , glutPassiveMotionFunc glutPassiveMotionFunc • glutMotionFunc glutMotionFunc, glutPassiveMotionFunc • •

  12. GLUT Event Loop glutMainLoop(); (); glutMainLoop glutMainLoop(); which puts the program in an infinite event which puts the program in an infinite event which puts the program in an infinite event loop loop loop In each pass through the event loop, GLUT In each pass through the event loop, GLUT In each pass through the event loop, GLUT • looks at the events in the queue looks at the events in the queue • • looks at the events in the queue • for each event in the queue, GLUT executes the for each event in the queue, GLUT executes the • • for each event in the queue, GLUT executes the appropriate callback function if one is defined appropriate callback function if one is defined appropriate callback function if one is defined • if no callback is defined for the event, the event is if no callback is defined for the event, the event is • • if no callback is defined for the event, the event is ignored ignored ignored

  13. The display callback The display callback is executed whenever GLUT The display callback is executed whenever GLUT The display callback is executed whenever GLUT determines that the window should be refreshed, determines that the window should be refreshed, determines that the window should be refreshed, for example for example for example • When the window is first opened When the window is first opened • • When the window is first opened • When the window is reshaped When the window is reshaped • • When the window is reshaped • When a window is exposed When a window is exposed • • When a window is exposed • When the user program decides it wants to change the display When the user program decides it wants to change the display • • When the user program decides it wants to change the display glutDisplayFunc(mydisplay) ) • glutDisplayFunc(mydisplay • glutDisplayFunc(mydisplay) identifies the function to be identifies the function to be identifies the function to be • executed executed executed • Every GLUT program must have a display callback Every GLUT program must have a display callback • • Every GLUT program must have a display callback

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend