300 likes | 383 Views
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 describe what the function does document anything you may forget in a week. Indexed Color. Needed for frame buffers with a limited depth
E N D
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 • describe what the function does • document anything you may forget in a week
Indexed Color • Needed for frame buffers with a limited depth • 8 bits of color = 2**8 colors = 256 colors • default is dividing bits into rbg assignments • load color map with a pallette of 256 colors • LUT
Viewing • Camera and objects are specified independently. • For a 2D world - define viewing or clipping rectangle. • Objects inside will be seen. • Objects outside will not be seen. • For a 3D world - define a viewing volume. • Orthographic projection.
Matrix Modes • Pipeline graphics dependent on concatenating a number of transformation matrices. Vertices Transformer Clipper Projector Rasterizer Pixels • Matrices • model-view • projection
Clients and Servers • Graphics server • Workstation with raster display , keyboard, and pointing device • Provides input and output services for network • Client • OpenGL application programs
Display Lists • From display processor • A special purpose computer • Host computer sent instructions to the display processor • Instructions stored in display memory as a display file or a display list • Immediate mode • Program defines a primitive • Primitive sent to server for display • No memory of primitive exists
Display Lists • Retained mode graphics • Define object once • Put description in a display list • Display list stored on the server • Redisplayed by a single function call • Advantage • Reduced network traffic • Disadvantage • Memory required on the server • Creating the display list has overhead
Display Lists • Creation of a display list - use glNewList, glEndList to encapsulate the list. • Each list has an int identifier which can be invoked with the command glCallList(identifier); • Save attributes with the matrix and attribute stacks (remember from 202: push onto a stack and pop off of a stack).
Interaction • According to Webster’s • To act upon each other • Two way communication • GLUT toolkit for windowing • GLUT recognizes only a small subset of the events recognized by X
Input • Input devices • Logical devices • From the perspective of the application program • Physical devices • Hardware and how it works
Input Modes • Mode defined by the relationship between the trigger and the measuring process. • Trigger (physical input that user signals computer). • Measure (what is returned to the program). • Request mode. • Measure returned when triggered. Trigger measure request program. Process trigger process measure.
Input Modes • Sample mode • Measure returned when triggered Measure sample program Process measure • Event mode • Device triggered • Event generated • Device measure placed on the event queue • Event type tied to function called CALLBACK
Input Modes Trigger measure event await program. Process trigger process measure queue event. • Event mode. • Device triggered. • Event generated. • Device measure placed on the event queue. • CALLBACK registered with the windowing system. Event type tied to function called a callback.
Using the Pointing Device Mouse Triggered Events • Move event • Move the mouse with the buttons depressed • Passive move event • Move the mouse without pressing a button • Mouse event • When one of the buttons is either released or pressed
Specify the Mouse Callback Function • Inmain() • With glutMouseFunc(mouse_callback_func) • void mouse_callback_func(int button, int state, int x, int, y) • The callback function specifies what actions are related to the specified event
Window Event • Generated when the window is resized • Redraw all the objects in the window • How to handle the aspect ratio • Do we change the sizes or attributes of the new primitives if the size of the new window is different from that of the old
Keyboard Events • Generated when the mouse is in the window and one of the keys is depressed • Returns the ascii code for the key and the x and y coordinates of the mouse • void keyboard(unsigned char key, int x, imt y)
Display Callback • Invoked when GLUT determines the window should be redisplayed • Upon opening it initially
Idle Function • Idle callback invoked when there are no other events. • Generates graphical primitives through a display function while nothing else is happening. • Event processing happens between calls to the idle function. • Do not spend too much time in the idle function. • Idle does not actually rerender the frame. • To rerender callglutPostRedisplay();from within the idle callback.
Menus • GLUT provides popup menus • glutCreateMenu(menu_callback_name); • Menu_callback_name is the name of the function. The argument to that function is the identifier passed to the callback when the entry isselected
Adding a Menu glutCreateMenu (menu_callback_name); glutAddMenuEntry("quit",1); glutAttachMenu (GLUT_RIGHT_BUTTON);
Adding a menu callback menu_callback_name(int id) { if (id == . . . }
Animation • Double buffering eliminates flicker.
Callback Advice From the Creator of GLUT, Mark Kilgard • Don’t change state that will affect the way a window will be drawn a display callback. • If you need to redisplay a window, instead of rendering in whatever callback you happen to be in, call glutPostRedisplay. • If you use an idle callback to control animation, use a visibility callback to determine when the window is fully obscured or iconified.
More Callback Advice • The backspace, Esc, and Del keys generate ASCII characters, so detect key presses for these keys using the glutKeyboardFunc callback.
Design of InteractivePrograms • A smooth display (no flicker or artifacts of the refresh process) • A variety of interactive devices on the display • A variety of methods for entering and displaying information • An easy to use interface that does not require substantial effort to learn • Feedback to the user • Tolerance for user errors • A design incorporation for consideration of both the visual and motor properties of the human
Limitations of Geometric Rendering • Designing widgets • example of popup menu • refreshing the display where the menu was • no primitives but uses scan line image data • operations described in terms of the frame buffer or in terms of bit-block transferoperation
Limitations of GeometricRendering • Rubberbanding • a technique for displaying line segments in a changing manner. • Endpoint is selected • Before second endpoint is selected a line segment is drawn automatically to where the present position of the mouse is • As the mouse moves the old segment must be erased and a new one drawn.
Homework • Read chapter 4 • Program 2 due 02/01/05