The GLUT API, GLUT Program Structure - Lecture Slides | CS 470, Study notes of Computer Graphics

Material Type: Notes; Professor: McGraw; Class: Introduction:Computer Graphics; Subject: Computer Science; University: West Virginia University; Term: Fall 2008;

Typology: Study notes

Pre 2010

Uploaded on 07/30/2009

koofers-user-wcs-2
koofers-user-wcs-2 🇺🇸

10 documents

1 / 14

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Computer Graphics
CS 470
Computer Science and Electrical Engineering Dept.
West Virginia University
August 25, 2008
CS 470 (West VirginiaUniversity) Computer Graphics August 25, 2008 1 / 14
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe

Partial preview of the text

Download The GLUT API, GLUT Program Structure - Lecture Slides | CS 470 and more Study notes Computer Graphics in PDF only on Docsity!

Computer Graphics

CS 470

Computer Science and Electrical Engineering Dept. West Virginia University

August 25, 2008

Outline

(^1) The GLUT API Initialization Window creation and management Callback function registration Font rendering Simple geometric objects

2 GLUT program structure

The GLUT API

Types of GLUT functions

GLUT is event-driven. We will register callback functions at startup and GLUT will call the functions as needed. GLUT functions: Initialization Window creation and management : OS independent Callback function registration : event driven Font rendering : using OpenGL Simple geometric objects : using OpenGL

All functions are named as glut*

The GLUT API Initialization

Functions

void glutInit(int *argcp, char **argv);

Must be called before the window is created. Command line options are system dependent.

void glutInitDisplayMode(unsigned int mode);

Configures the frame buffer, as determined by mode. The flags specified by mode can include color, depth, stencil buffer, and single/double buffering modes.

Others: glutInitWindowPosition glutInitWindowSize

The GLUT API Window creation and management

Functions

int glutCreateWindow(char *name);

The window name is displayed in the title bar.

void glutPostRedisplay(void);

Sets a flag indicating that the current window needs to be redrawn.

void glutSwapBuffers(void);

Swap front / back buffers when double buffering is enabled.(Usually implemented by just swapping pointers, not by copying buffer contents.)

Also, commands for setting / getting current window.

The GLUT API Callback function registration

Functions

These functions set the callback function for the current window.

void glutDisplayFunc(void (*func)(void));

The function pointed to by func will be called from within the event loop when the redisplay flag is set. The callback function typically contains the OpenGL drawing commands.

void glutIdleFunc(void (*func)(void));

The function pointed to by func will be called from within the event loop while windowing system events are not being handled. The callback function typically contains code which performs some animation (but not rendering).

Call glutPostRedisplay at the end of the callback function so that the results of the animation will be displayed.

The GLUT API Callback function registration

The event loop

void glutMainLoop(void);

This is event loop from which the registered callbacks are made. This function does not return.

The GLUT API Font rendering

Functions

void glutBitmapCharacter(void *font, int character);

Render the given character using the specified bitmapped font.

void glutStrokeCharacter(void *font, int character);

Render the given character using the specified stroke font.

Bitmap (Raster text): bitmapped font Stroke : Built from geometric primitives

GLUT program structure

Typical program structure

Initialize GLUT : glutInit* functions Create window : glutCreateWindow Register callbacks : glut*Func functions Initialize OpenGL state : Color buffer clear color, camera parameters Enter event loop : glutMainLoop

Look at the example from HW 1.

GLUT program structure

Next Class:

Read chapter 2. Review the OpenGL and glut online resources from the course homepage, especially the online red book, and glut documentation.