4 GraphicsSystem
4 GraphicsSystem
software
that takes user input and passes it to applications that displays graphical output for applications
Application Model
Application Program
Graphics System
(2D/3D graphics, UI toolkit, input manager window system)
Application
Model (world):
the database & objects to be displayed may be geometry/attributes may be abstract data (e.g. fractal description) responsible for mapping the model to primitives supported by graphics package responsible for mapping user input to model changes
April 14, 2012 3
Program:
Set of primitives Primitive attributes Graphics output Input handling Window management
2D Primitive possibilities
geometrical objects (point, line, circle, polygon, ...) mathematical curves text primitives fill patterns bitmapped images/textures
3D primitive possibilities
geometrical objects (line, polygon, polyhedron, sphere, ) mathematical surfaces light sources camera/eye points hierarchy placeholders object boundaries
Primitive attributes
Graphics output
scan-conversion: used to map graphics commands (sets of primitives/attributes) to pixel values to be placed in frame buffer rendering of objects into screen space providing a view of the application model
Input handling
receive input from physical devices map this input to logical devices for applications apps register interest in events or devices event-driven programming
render_from_database(); while(1){ wait for input switch(input){ case 1: call_routine1(); case 2: call_routine2(); } render_from_database(); }
Window management
manage screen space mediate between application programs provide logical output canvases each app. believes it has an entire screen with its own coordinate system
10
Abstraction; Device-independence
logical input devices logical output devices (!) provide abstraction from hardware for app. produce application portability
11
OpenGL
mid-level, device-independent, portable graphics subroutine package developed primarily by SGI 2D/3D graphics, lower-level primitives (polygons) does not include low-level I/O management basis for higher-level libraries/toolkits
12
13
A short outline of input devices and the implementation of a graphical user interface is given:
Physical input devices used in graphics Virtual devices Polling is compared to event processing UI toolkits are introduced by generalizing event processing
14
Physical Devices
Actual, physical input devices include:
Dials (Potentiometers) Selectors Pushbuttons Switches Keyboards (collections of pushbuttons called \keys") Trackballs (relative motion) Mice (relative motion) Joysticks (relative motion, direction) Tablets (absolute position) Etc.
April 14, 2012 15
Virtual Devices
Devices can be classified according to the kind of value they return:
Button: Return a Boolean value; can be depressed or released. Key: Return a "character"; that is, one of a given set of code values. String: Return a sequence of characters. Selector: Return an integral value (in a given range). Choice: Return an option (menu, callback, ...) Valuator: Return a real value (in a given range). Locator: Return a position in (2D/3D) space (eg. several ganged valuators). Stroke: Return a sequence of positions. Pick: Return a scene component.
April 14, 2012 16
Device Association
To obtain device independence:
Design an application in terms of virtual (abstract) devices. Implement virtual devices using physical devices e.g. Valuator Mouse-X >
one can make do with other possibilities: e.g. Valuator number entered on keyboard >
17
device continually offers input to the queue application may request selections and services from the queue (or the queue may interrupt the ap plication).
19
Application Structure
Events may or may not be interruptive. If not interruptive, they may be read in a
blocking non-blocking
fashion.
204481 Foundation of Computer Graphics
April 14, 2012 20
Value of input device constantly checked in a tight loop Wait for a change in status
Generally, polling is inecient and should be avoided, particularly in time-sharing systems. In sampling, value of an input device is read and then the program proceeds.
Upon change in status of device, this process places a record into an event queue. Application can request read-out of queue:
Number of events 1st waiting event Highest priority event 1st event of some category All events Specify which events should be placed in queue Clear and reset the queue Etc.
April 14, 2012 22
Queue reading may be blocking or nonblocking Processing may be through callbacks Events may be processed interruptively Events can be associated with more than devices Events can be restricted to particular areas of the screen, based on the cursor position.
April 14, 2012 23
A mouse button or keyboard key is depressed. A mouse button or keyboard key is released. The cursor enters a window. The cursor has moved more than a certain amount. An Expose event is triggered under X when a window becomes visible. A Configure event is triggered when a window is resized. A timer event may occur after a certain interval.
April 14, 2012 24
Instead of switch, use table lookup. Each table entry associates an event with a callback function. When event occurs, corresponding callback is invoked. Provide an API to make and delete table entries. Divide screen into parcels, and assign different callbacks to different parcels (X Windows does thi s). Event manager does most or all of the administration.
April 14, 2012 25
Widgets (1/2)
Modular UI functionality is provided through a set of widgets: Widgets are parcels of the screen that can respond to events. A widget has a graphical representation that suggests its function. Widgets may respond to events with a change in appearance, as well as issuing callbacks.
26
Widgets (2/2)
Event-process definition for parent may apply to child, and child may add additional event-process definitions Event-process definition for parent may be redefined within child
Widgets may have multiple parts, and in fact may be composed of other
widgets in a heirarchy.
Source :
Pradondet Nilagupta Dept. of Computer Engineering Kasetsart University
204481 Foundation of Computer Graphics
April 14, 2012 28