Cd2012 principles of interactive graphics lecture 05
Sponsored Links
This presentation is the property of its rightful owner.
1 / 19

CD2012 Principles of Interactive Graphics Lecture 05 PowerPoint PPT Presentation

  • Uploaded on
  • Presentation posted in: General

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

Download Presentation

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.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript

CD2012Principles of Interactive GraphicsLecture 05


Abir Hussain

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.


Today’s lecture and lab



  • 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


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.


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.


What is a callback function?


  • 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


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 


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.


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);


Mouse interaction

  • In this case, the button value could be


  • 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.


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.


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)


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.


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.


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


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.



  • Windows event handling

  • Mouse interactions

    • glutMouseFunc(myMouse)

  • Keyboard interactions

    • glutkeyboardFunc(myKeyboard).

  • Text and fonts

    • GlutBitmapCharacter(GLUT_BITMAP_8_BY_13, c)


  • Login