chapter 3

Objectives


Project Sketchpad


3.2- Graphical Input

Physical Devices

Incremental (Relative) Physical Devices

Logical Devices

Graphical Logical Devices

Input Modes

Request Mode Input

Event Mode Input

Event Types

Callbacks

GLUT callbacks(GLUT_3 Specification.pdf)

GLUT Event Loop

The display callback

Posting redisplays

Animating a Display

Double Buffering

Using the idle callback

Using globals


3.5 - Working with Callbacks

Objectives

The mouse callback

glutMouseFunc(mymouse)

void mymouse(GLint button, GLint state, GLint x, GLint y)

Positioning

Obtaining the window size

Terminating a program

Using the mouse position

Drawing squares at cursor location

void mymouse(int btn, int state, int x, int y) {

if(btn==GLUT_RIGHT_BUTTON && state==GLUT_DOWN) exit(0);
if(btn==GLUT_LEFT_BUTTON && state==GLUT_DOWN) drawSquare(x, y); }

void drawSquare(int x, int y) {

y=w-y; /* invert y position */
glColor3ub( (char) rand()%256, (char) rand )%256, (char) rand()%256);
/* a random color */
glBegin(GL_POLYGON);

glVertex2f(x+size, y+size);
glVertex2f(x-size, y+size);
glVertex2f(x-size, y-size);
glVertex2f(x+size, y-size);

glEnd(); }

Using the motion callback

Using the keyboard

glutKeyboardFunc(mykey)

void mykey(unsigned char key, int x, int y)

Special and Modifier Keys

Reshaping the window

Reshape possiblities

The Reshape callback

glutReshapeFunc(myreshape)

void myreshape( int w, int h)

Example Reshape


Toolkits and Widgets

Menus

Defining a simple menu

Menu actions

Other functions in GLUT


3.7 - Better Interactive Programs

Objectives

Picking

Three Approaches

Hit Lists (skip)

Rendering Modes

Selection Mode Functions

Using Selection Mode

Selection Mode and Picking


Using another buffer and colors for picking

Writing Modes

XOR write


Rubberbanding

Rubberband Lines

XOR in OpenGL

Immediate and Retained Modes


Display Lists(see code list.c; )

Display List Functions

Creating a display list

GLuint id;
void init( void ) {

id = glGenLists( 1 );
glNewList(id, GL_COMPILE );
/* other OpenGL routines */
glEndList(); }

Call a created list

void display( void ) {

glCallList( id ); }

3.4 (briefly) Display Lists and State

Hierarchy and Display Lists



In class Activity link