1 / 19

CD2012 Principles of Interactive Graphics Lecture 05

CD2012 Principles of Interactive Graphics Lecture 05. Interactions Abir Hussain www.cms.livjm.ac.uk/cmsahus1. Previous Lecture. Graphics hardware: display devices, hard copy devices, and interactive input devices. Display devices: CRT, plasma screen, LED and LCD.

decker
Télécharger la présentation

CD2012 Principles of Interactive Graphics Lecture 05

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CD2012Principles of Interactive GraphicsLecture 05 Interactions Abir Hussain www.cms.livjm.ac.uk/cmsahus1

  2. Previous Lecture • Graphics hardware: display devices, hard copy devices, and interactive input devices. • Display devices: CRT, plasma screen, LED and LCD. • Hard copy devices: printers and plotters • Interactive input devices: mouse and joystick. CD2012-05

  3. Today’s lecture and lab CD2012-05

  4. Introduction • Interactive graphics application allows the user to control the flow of a program • by natural human motions such as pointing and clicking the mouse or pressing various keys on the keyboard. • Recall, every interactive graphics program has the same model: • Initialise the application data and graphics environment • Create the contents of the display • Paint the contents of the display on a window • Set-up functions to handle input event • Start an infinite loop to handle input events CD2012-05

  5. General event handling model • When a user presses or releases a mouse button, moves the mouse or presses a key in the keyboard an event occurs. • A graphics program registers certain functions as event handling functions. • The Program then goes into an infinite loop waiting for events • when an event arrives a notification system decides how it should be handled. CD2012-05

  6. General event handling model • The event structure is then passed to the function that was registered for that event. • Then, the function exits and returns control to the main loop. CD2012-05

  7. What is a callback function?

  8. Recall • The basic mechanism for handling input events is to register callback functions to handle specific events. • These events could be • Window events: moving, hiding or resizing a window • Input device events: mouse, keyboard, tracker etc • Timer events that are generated by a clock in the application CD2012-05

  9. Windows event handling • The function glutDisplayFunc(display) reacts to events from the Window system to draw (or re-draw) the contents of the window. • As an example, in MS Windows if the window has been • Minimised/Maximised • Hidden/Shown relative to other windows  CD2012-05

  10. Windows event handling • The function glutReshapeFunc(reshape) reacts to events when the Window is resized. • The callback function (e.g. reshape) takes as arguments, the new width and height of the window. • Every window system has similar functions to handle these events. CD2012-05

  11. Mouse interaction • The function glutMouseFunc(myMouse) registers the function myMouse () as the function to be executed when a mouse event occurs. • The callback function myMouse() should be designed to take four parameters: void myMouse (int button, int state, int x, int y); CD2012-05

  12. Mouse interaction • In this case, the button value could be • GLUT_LEFT_BUTTON, GLUT_MIDDLE_BUTTON, GLUT_RIGHT_BUTTON. • The value of the state could be • GLUT_DOWN and GLUT_UP. • While x and y represent the position of the mouse at the time of the event. CD2012-05

  13. Mouse interaction • Windows systems also support event handlers for mouse motion, e.g. • glutMotionFunc(motion) • glutPassiveMotionFunc(passive) • The first registers motion() to handle moving the mouse with a button pressed • The second registers passive() to handle moving the mouse with a button released. • By managing the input state, we can support the behaviour of most user interface objects. CD2012-05

  14. Keyboard interaction • When pressing a key on the keyboard, this would queue a keyboard events. • The callback function myKeyboard() is register with such events through glutkeyboardFunc(myKeyboard). • This function has the following prototype:   • void myKeyboard(unsigned int key, int x, int y) CD2012-05

  15. Text and fonts • There are two forms of text which are stroke and raster. • In stroke text, we define line segments or curves that outline each character. • In raster text, characters are defined as rectangles of bits called bit blocks. • Each block defines a single character by the pattern of 0 and 1 bits in the block. CD2012-05

  16. Text and fonts • The GLUT provides a few bitmap and stroke character sets. As an example:   • GlutBitmapCharacter(GLUT_BITMAP_8_BY_13, c) • Where c is the number of ASCII characters that we wish to be placed on the display. CD2012-05

  17. Timer general events • While the main event loop is running the program can only respond to external events. • If we want something to happen between events we have to register handlers to run either • When the program is idle • Or in response to timer generated events CD2012-05

  18. Timer general events • glutIdleFunc() will register a function to run whenever the program is not handling other events. • However, this function should return quickly or the program may be unable to respond to other events • We can register a function to be called every few milliseconds by glutTimerFunc. CD2012-05

  19. Summary • Windows event handling • Mouse interactions • glutMouseFunc(myMouse) • Keyboard interactions • glutkeyboardFunc(myKeyboard). • Text and fonts • GlutBitmapCharacter(GLUT_BITMAP_8_BY_13, c) CD2012-05

More Related