chapter 2 using opengl chih-kuo yeh. addison wesley opengl superbible 4 th edition jun 2007 author:...
Post on 19-Dec-2015
227 views
TRANSCRIPT
![Page 1: Chapter 2 Using OpenGL Chih-Kuo Yeh. Addison Wesley OpenGL SuperBible 4 th Edition Jun 2007 Author: Richard S. Wright, Jr. Benjamin Lipchak Nicholas](https://reader035.vdocuments.us/reader035/viewer/2022062308/56649d2f5503460f94a06d85/html5/thumbnails/1.jpg)
Chapter 2
Using OpenGL
Chih-Kuo Yeh
![Page 2: Chapter 2 Using OpenGL Chih-Kuo Yeh. Addison Wesley OpenGL SuperBible 4 th Edition Jun 2007 Author: Richard S. Wright, Jr. Benjamin Lipchak Nicholas](https://reader035.vdocuments.us/reader035/viewer/2022062308/56649d2f5503460f94a06d85/html5/thumbnails/2.jpg)
Textbook
Addison Wesley OpenGL SuperBible 4th Edition Jun 2007
Author:Richard S. Wright,
Jr.Benjamin LipchakNicholas Haemel
![Page 3: Chapter 2 Using OpenGL Chih-Kuo Yeh. Addison Wesley OpenGL SuperBible 4 th Edition Jun 2007 Author: Richard S. Wright, Jr. Benjamin Lipchak Nicholas](https://reader035.vdocuments.us/reader035/viewer/2022062308/56649d2f5503460f94a06d85/html5/thumbnails/3.jpg)
3
OpenGL and GLUT Overview
What is OpenGL & what can it do for me?
OpenGL in windowing systemsWhy GLUTA GLUT program template
![Page 4: Chapter 2 Using OpenGL Chih-Kuo Yeh. Addison Wesley OpenGL SuperBible 4 th Edition Jun 2007 Author: Richard S. Wright, Jr. Benjamin Lipchak Nicholas](https://reader035.vdocuments.us/reader035/viewer/2022062308/56649d2f5503460f94a06d85/html5/thumbnails/4.jpg)
4
What Is OpenGL?
Graphics rendering API high-quality color images composed of
geometric and image primitives window system independent operating system independent
![Page 5: Chapter 2 Using OpenGL Chih-Kuo Yeh. Addison Wesley OpenGL SuperBible 4 th Edition Jun 2007 Author: Richard S. Wright, Jr. Benjamin Lipchak Nicholas](https://reader035.vdocuments.us/reader035/viewer/2022062308/56649d2f5503460f94a06d85/html5/thumbnails/5.jpg)
5 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009
SGI and GL
Silicon Graphics (SGI) revolutionized the graphics workstation by implementing the pipeline in hardware (1982)
To access the system, application programmers used a library called GL
With GL, it was relatively simple to program three dimensional interactive applications
1.0 (1992)
![Page 6: Chapter 2 Using OpenGL Chih-Kuo Yeh. Addison Wesley OpenGL SuperBible 4 th Edition Jun 2007 Author: Richard S. Wright, Jr. Benjamin Lipchak Nicholas](https://reader035.vdocuments.us/reader035/viewer/2022062308/56649d2f5503460f94a06d85/html5/thumbnails/6.jpg)
6 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009
OpenGL
The success of GL lead to OpenGL (1992), a platform-independent API that was Easy to use Close enough to the hardware to get
excellent performance Focus on rendering Omitted windowing and input to avoid
window system dependencies
![Page 7: Chapter 2 Using OpenGL Chih-Kuo Yeh. Addison Wesley OpenGL SuperBible 4 th Edition Jun 2007 Author: Richard S. Wright, Jr. Benjamin Lipchak Nicholas](https://reader035.vdocuments.us/reader035/viewer/2022062308/56649d2f5503460f94a06d85/html5/thumbnails/7.jpg)
7 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009
OpenGL Libraries
OpenGL core library OpenGL32 on Windows GL on most unix/linux systems (libGL.a)
OpenGL Utility Library (GLU) Provides functionality in OpenGL core
but avoids having to rewrite code Links with window system
GLX for X window systems WGL for Windows AGL for Macintosh
![Page 8: Chapter 2 Using OpenGL Chih-Kuo Yeh. Addison Wesley OpenGL SuperBible 4 th Edition Jun 2007 Author: Richard S. Wright, Jr. Benjamin Lipchak Nicholas](https://reader035.vdocuments.us/reader035/viewer/2022062308/56649d2f5503460f94a06d85/html5/thumbnails/8.jpg)
8
OpenGL as a Renderer
Geometric primitives points, lines and polygons
Image Primitives images and bitmaps separate pipeline for images and
geometry▪ linked through texture mapping
Rendering depends on state colors, materials, light sources, etc.
![Page 9: Chapter 2 Using OpenGL Chih-Kuo Yeh. Addison Wesley OpenGL SuperBible 4 th Edition Jun 2007 Author: Richard S. Wright, Jr. Benjamin Lipchak Nicholas](https://reader035.vdocuments.us/reader035/viewer/2022062308/56649d2f5503460f94a06d85/html5/thumbnails/9.jpg)
9
Related APIs
AGL, GLX, WGL glue between OpenGL and windowing systems
GLU (OpenGL Utility Library) part of OpenGL NURBS, tessellators, quadric shapes, etc.
GLUT (OpenGL Utility Toolkit) portable windowing API not officially part of OpenGL
![Page 10: Chapter 2 Using OpenGL Chih-Kuo Yeh. Addison Wesley OpenGL SuperBible 4 th Edition Jun 2007 Author: Richard S. Wright, Jr. Benjamin Lipchak Nicholas](https://reader035.vdocuments.us/reader035/viewer/2022062308/56649d2f5503460f94a06d85/html5/thumbnails/10.jpg)
10
OpenGL and Related APIs
GLUT
GLU
GL
GLX, AGLor WGL
X, Win32, Mac O/S
software and/or hardware
application program
OpenGL Motifwidget or similar
![Page 11: Chapter 2 Using OpenGL Chih-Kuo Yeh. Addison Wesley OpenGL SuperBible 4 th Edition Jun 2007 Author: Richard S. Wright, Jr. Benjamin Lipchak Nicholas](https://reader035.vdocuments.us/reader035/viewer/2022062308/56649d2f5503460f94a06d85/html5/thumbnails/11.jpg)
11
OpenGL Architecture
DisplayList
PolynomialEvaluator
Per VertexOperations &PrimitiveAssembly
RasterizationPer FragmentOperations
FrameBuffer
TextureMemory
CPU
PixelOperations
![Page 12: Chapter 2 Using OpenGL Chih-Kuo Yeh. Addison Wesley OpenGL SuperBible 4 th Edition Jun 2007 Author: Richard S. Wright, Jr. Benjamin Lipchak Nicholas](https://reader035.vdocuments.us/reader035/viewer/2022062308/56649d2f5503460f94a06d85/html5/thumbnails/12.jpg)
12
Preliminaries
Headers Files #ifdef WIN32 #include <windows.h> // Must have for Windows platform builds #include "glee.h" // OpenGL Extension "autoloader" #include <gl\gl.h> // Microsoft OpenGL headers (version 1.1 by
themselves) #include <gl\glu.h> // OpenGL Utilities #include "glut.h" // Glut (Free-Glut on Windows) #endif
LibrariesEnumerated Types
OpenGL defines numerous types for compatibility▪ GLfloat, GLint, GLenum, etc.
![Page 13: Chapter 2 Using OpenGL Chih-Kuo Yeh. Addison Wesley OpenGL SuperBible 4 th Edition Jun 2007 Author: Richard S. Wright, Jr. Benjamin Lipchak Nicholas](https://reader035.vdocuments.us/reader035/viewer/2022062308/56649d2f5503460f94a06d85/html5/thumbnails/13.jpg)
13 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009
Notes on compilation
See website and ftp for examplesUnix/linux
Include files usually in …/include/GL Compile with –lglut –lglu –lgl loader flags May have to add –L flag for X libraries Mesa implementation included with most
linux distributions Check web for latest versions of Mesa
and glut
![Page 14: Chapter 2 Using OpenGL Chih-Kuo Yeh. Addison Wesley OpenGL SuperBible 4 th Edition Jun 2007 Author: Richard S. Wright, Jr. Benjamin Lipchak Nicholas](https://reader035.vdocuments.us/reader035/viewer/2022062308/56649d2f5503460f94a06d85/html5/thumbnails/14.jpg)
14 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009
Compilation on Windows
Visual C++ Get glut.h, glut32.lib and glut32.dll from
web Create a console application Add opengl32.lib, glu32.lib, glut32.lib to
project settings (under link tab)Borland C similarCygwin (linux under Windows)
Can use gcc and similar makefile to linux Use –lopengl32 –lglu32 –lglut32 flags
![Page 15: Chapter 2 Using OpenGL Chih-Kuo Yeh. Addison Wesley OpenGL SuperBible 4 th Edition Jun 2007 Author: Richard S. Wright, Jr. Benjamin Lipchak Nicholas](https://reader035.vdocuments.us/reader035/viewer/2022062308/56649d2f5503460f94a06d85/html5/thumbnails/15.jpg)
15
GLUT Basics
Application Structure Configure and open window Initialize OpenGL state Register input callback functions▪ render▪ resize▪ input: keyboard, mouse, etc.
Enter event processing loop
![Page 16: Chapter 2 Using OpenGL Chih-Kuo Yeh. Addison Wesley OpenGL SuperBible 4 th Edition Jun 2007 Author: Richard S. Wright, Jr. Benjamin Lipchak Nicholas](https://reader035.vdocuments.us/reader035/viewer/2022062308/56649d2f5503460f94a06d85/html5/thumbnails/16.jpg)
Your First Program
![Page 17: Chapter 2 Using OpenGL Chih-Kuo Yeh. Addison Wesley OpenGL SuperBible 4 th Edition Jun 2007 Author: Richard S. Wright, Jr. Benjamin Lipchak Nicholas](https://reader035.vdocuments.us/reader035/viewer/2022062308/56649d2f5503460f94a06d85/html5/thumbnails/17.jpg)
17
simple.cpp
1. #include “../../shared/gltools.h” // OpenGL toolkit2. void RenderScene(void)3. {4. glClear(GL_COLOR_BUFFER_BIT);5. glFlush();6. }7. void SetupRC(void)8. {9. glClearColor(0.0f, 0.0f, 1.0f, 1.0f);10.}11.int main(int argc, char* argv[])12.{13. glutInit(&argc, argv);14. glutInitDisplayMode(GLUT_SINGLE | GLUT_RGBA);15. glutCreateWindow(“Simple”);16. glutDisplayFunc(RenderScene);17. SetupRC();18. glutMainLoop();19. return 0;20.}
![Page 18: Chapter 2 Using OpenGL Chih-Kuo Yeh. Addison Wesley OpenGL SuperBible 4 th Edition Jun 2007 Author: Richard S. Wright, Jr. Benjamin Lipchak Nicholas](https://reader035.vdocuments.us/reader035/viewer/2022062308/56649d2f5503460f94a06d85/html5/thumbnails/18.jpg)
VC 2005 Compiler
![Page 19: Chapter 2 Using OpenGL Chih-Kuo Yeh. Addison Wesley OpenGL SuperBible 4 th Edition Jun 2007 Author: Richard S. Wright, Jr. Benjamin Lipchak Nicholas](https://reader035.vdocuments.us/reader035/viewer/2022062308/56649d2f5503460f94a06d85/html5/thumbnails/19.jpg)
VC 2005 Compiler
![Page 20: Chapter 2 Using OpenGL Chih-Kuo Yeh. Addison Wesley OpenGL SuperBible 4 th Edition Jun 2007 Author: Richard S. Wright, Jr. Benjamin Lipchak Nicholas](https://reader035.vdocuments.us/reader035/viewer/2022062308/56649d2f5503460f94a06d85/html5/thumbnails/20.jpg)
Sample Program
![Page 21: Chapter 2 Using OpenGL Chih-Kuo Yeh. Addison Wesley OpenGL SuperBible 4 th Edition Jun 2007 Author: Richard S. Wright, Jr. Benjamin Lipchak Nicholas](https://reader035.vdocuments.us/reader035/viewer/2022062308/56649d2f5503460f94a06d85/html5/thumbnails/21.jpg)
21
GLUT Callback Functions
Routine to call when something happens window resize or redraw user input animation
“Register” callbacks with GLUTglutDisplayFunc( display );glutIdleFunc( idle );glutKeyboardFunc( keyboard );
![Page 22: Chapter 2 Using OpenGL Chih-Kuo Yeh. Addison Wesley OpenGL SuperBible 4 th Edition Jun 2007 Author: Richard S. Wright, Jr. Benjamin Lipchak Nicholas](https://reader035.vdocuments.us/reader035/viewer/2022062308/56649d2f5503460f94a06d85/html5/thumbnails/22.jpg)
void glClearColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha);
![Page 23: Chapter 2 Using OpenGL Chih-Kuo Yeh. Addison Wesley OpenGL SuperBible 4 th Edition Jun 2007 Author: Richard S. Wright, Jr. Benjamin Lipchak Nicholas](https://reader035.vdocuments.us/reader035/viewer/2022062308/56649d2f5503460f94a06d85/html5/thumbnails/23.jpg)
Some Common Composite Colors
![Page 24: Chapter 2 Using OpenGL Chih-Kuo Yeh. Addison Wesley OpenGL SuperBible 4 th Edition Jun 2007 Author: Richard S. Wright, Jr. Benjamin Lipchak Nicholas](https://reader035.vdocuments.us/reader035/viewer/2022062308/56649d2f5503460f94a06d85/html5/thumbnails/24.jpg)
Clearing the Color Buffer
glClear(GL_COLOR_BUFFER_BIT);glFlush();
![Page 25: Chapter 2 Using OpenGL Chih-Kuo Yeh. Addison Wesley OpenGL SuperBible 4 th Edition Jun 2007 Author: Richard S. Wright, Jr. Benjamin Lipchak Nicholas](https://reader035.vdocuments.us/reader035/viewer/2022062308/56649d2f5503460f94a06d85/html5/thumbnails/25.jpg)
Drawing Shapes with OpenGL
![Page 26: Chapter 2 Using OpenGL Chih-Kuo Yeh. Addison Wesley OpenGL SuperBible 4 th Edition Jun 2007 Author: Richard S. Wright, Jr. Benjamin Lipchak Nicholas](https://reader035.vdocuments.us/reader035/viewer/2022062308/56649d2f5503460f94a06d85/html5/thumbnails/26.jpg)
glrect.cpp
int main(int argc, char* argv[]){
glutInit(&argc, argv);glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);glutCreateWindow("GLRect");glutDisplayFunc(RenderScene);glutReshapeFunc(ChangeSize);SetupRC();glutMainLoop(); return 0;
}
![Page 27: Chapter 2 Using OpenGL Chih-Kuo Yeh. Addison Wesley OpenGL SuperBible 4 th Edition Jun 2007 Author: Richard S. Wright, Jr. Benjamin Lipchak Nicholas](https://reader035.vdocuments.us/reader035/viewer/2022062308/56649d2f5503460f94a06d85/html5/thumbnails/27.jpg)
Rendering Callback
Do all of your drawing herevoid RenderScene(void){glClear(GL_COLOR_BUFFER_BIT);glColor3f(1.0f, 0.0f, 0.0f);glRectf(-25.0f, 25.0f, 25.0f, -25.0f)
glFlush();}
![Page 28: Chapter 2 Using OpenGL Chih-Kuo Yeh. Addison Wesley OpenGL SuperBible 4 th Edition Jun 2007 Author: Richard S. Wright, Jr. Benjamin Lipchak Nicholas](https://reader035.vdocuments.us/reader035/viewer/2022062308/56649d2f5503460f94a06d85/html5/thumbnails/28.jpg)
Reshape Callback
void ChangeSize(int w, int h){
GLfloat aspectRatio;if(h == 0)
h = 1;glViewport(0, 0, w, h);glMatrixMode(GL_PROJECTION);glLoadIdentity();aspectRatio = (GLfloat)w / (GLfloat)h;if (w <= h)
glOrtho (-100.0, 100.0, -100 / aspectRatio, 100.0 / aspectRatio, 1.0, -1.0);else
glOrtho (-100.0 * aspectRatio, 100.0 * aspectRatio, -100.0, 100.0, 1.0, -1.0);glMatrixMode(GL_MODELVIEW);glLoadIdentity();
}
![Page 29: Chapter 2 Using OpenGL Chih-Kuo Yeh. Addison Wesley OpenGL SuperBible 4 th Edition Jun 2007 Author: Richard S. Wright, Jr. Benjamin Lipchak Nicholas](https://reader035.vdocuments.us/reader035/viewer/2022062308/56649d2f5503460f94a06d85/html5/thumbnails/29.jpg)
![Page 30: Chapter 2 Using OpenGL Chih-Kuo Yeh. Addison Wesley OpenGL SuperBible 4 th Edition Jun 2007 Author: Richard S. Wright, Jr. Benjamin Lipchak Nicholas](https://reader035.vdocuments.us/reader035/viewer/2022062308/56649d2f5503460f94a06d85/html5/thumbnails/30.jpg)
Drawing a Rectangle
void glColor3f(GLfloat red, GLfloat green, GLfloat blue);
void glRectf(GLfloat x1, GLfloat y1, GLfloat x2, GLfloat y2);
![Page 31: Chapter 2 Using OpenGL Chih-Kuo Yeh. Addison Wesley OpenGL SuperBible 4 th Edition Jun 2007 Author: Richard S. Wright, Jr. Benjamin Lipchak Nicholas](https://reader035.vdocuments.us/reader035/viewer/2022062308/56649d2f5503460f94a06d85/html5/thumbnails/31.jpg)
31
OpenGL Command Formats
glVertex3fv( v )
Number ofcomponents
2 - (x,y) 3 - (x,y,z)4 - (x,y,z,w)
Data Typeb - byteub - unsigned bytes - shortus - unsigned shorti - intui - unsigned intf - floatd - double
Vector
omit “v” forscalar form
glVertex2f( x, y )
![Page 32: Chapter 2 Using OpenGL Chih-Kuo Yeh. Addison Wesley OpenGL SuperBible 4 th Edition Jun 2007 Author: Richard S. Wright, Jr. Benjamin Lipchak Nicholas](https://reader035.vdocuments.us/reader035/viewer/2022062308/56649d2f5503460f94a06d85/html5/thumbnails/32.jpg)
OpenGL Variable Types
![Page 33: Chapter 2 Using OpenGL Chih-Kuo Yeh. Addison Wesley OpenGL SuperBible 4 th Edition Jun 2007 Author: Richard S. Wright, Jr. Benjamin Lipchak Nicholas](https://reader035.vdocuments.us/reader035/viewer/2022062308/56649d2f5503460f94a06d85/html5/thumbnails/33.jpg)
Setting the Viewport and Clipping Volume
![Page 34: Chapter 2 Using OpenGL Chih-Kuo Yeh. Addison Wesley OpenGL SuperBible 4 th Edition Jun 2007 Author: Richard S. Wright, Jr. Benjamin Lipchak Nicholas](https://reader035.vdocuments.us/reader035/viewer/2022062308/56649d2f5503460f94a06d85/html5/thumbnails/34.jpg)
Defining the Viewport
void glViewport(GLint x, GLint y, GLsizei width, GLsizei height);
![Page 35: Chapter 2 Using OpenGL Chih-Kuo Yeh. Addison Wesley OpenGL SuperBible 4 th Edition Jun 2007 Author: Richard S. Wright, Jr. Benjamin Lipchak Nicholas](https://reader035.vdocuments.us/reader035/viewer/2022062308/56649d2f5503460f94a06d85/html5/thumbnails/35.jpg)
Defining the Clipped Viewing Volume
void glOrtho(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble near, GLdouble far );
![Page 36: Chapter 2 Using OpenGL Chih-Kuo Yeh. Addison Wesley OpenGL SuperBible 4 th Edition Jun 2007 Author: Richard S. Wright, Jr. Benjamin Lipchak Nicholas](https://reader035.vdocuments.us/reader035/viewer/2022062308/56649d2f5503460f94a06d85/html5/thumbnails/36.jpg)
Keeping a Square Square
![Page 37: Chapter 2 Using OpenGL Chih-Kuo Yeh. Addison Wesley OpenGL SuperBible 4 th Edition Jun 2007 Author: Richard S. Wright, Jr. Benjamin Lipchak Nicholas](https://reader035.vdocuments.us/reader035/viewer/2022062308/56649d2f5503460f94a06d85/html5/thumbnails/37.jpg)
Keeping a Square Square
aspectRatio = (GLfloat)w / (GLfloat)h;if (w <= h)
glOrtho (-100.0, 100.0, -100 / aspectRatio, 100.0 / aspectRatio, 1.0, -1.0);else
glOrtho (-100.0 * aspectRatio, 100.0 * aspectRatio, -100.0, 100.0, 1.0, -1.0);
![Page 38: Chapter 2 Using OpenGL Chih-Kuo Yeh. Addison Wesley OpenGL SuperBible 4 th Edition Jun 2007 Author: Richard S. Wright, Jr. Benjamin Lipchak Nicholas](https://reader035.vdocuments.us/reader035/viewer/2022062308/56649d2f5503460f94a06d85/html5/thumbnails/38.jpg)
Animation with OpenGL and GLUT
![Page 39: Chapter 2 Using OpenGL Chih-Kuo Yeh. Addison Wesley OpenGL SuperBible 4 th Edition Jun 2007 Author: Richard S. Wright, Jr. Benjamin Lipchak Nicholas](https://reader035.vdocuments.us/reader035/viewer/2022062308/56649d2f5503460f94a06d85/html5/thumbnails/39.jpg)
bounce.cpp
int main(int argc, char* argv[]){
glutInit(&argc, argv);glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA);glutInitWindowSize(800,600);glutCreateWindow("Bounce");glutDisplayFunc(RenderScene);glutReshapeFunc(ChangeSize);glutTimerFunc(33, TimerFunction, 1);SetupRC();glutMainLoop();return 0;
}
![Page 40: Chapter 2 Using OpenGL Chih-Kuo Yeh. Addison Wesley OpenGL SuperBible 4 th Edition Jun 2007 Author: Richard S. Wright, Jr. Benjamin Lipchak Nicholas](https://reader035.vdocuments.us/reader035/viewer/2022062308/56649d2f5503460f94a06d85/html5/thumbnails/40.jpg)
Rendering Callback
GLfloat x = 0.0f;GLfloat y = 0.0f;GLfloat rsize = 25;GLfloat xstep = 1.0f;GLfloat ystep = 1.0f;GLfloat windowWidth;GLfloat windowHeight;
void RenderScene(void){
glClear(GL_COLOR_BUFFER_BIT);glColor3f(1.0f, 0.0f, 0.0f);glRectf(x, y, x + rsize, y - rsize);glutSwapBuffers();
}
![Page 41: Chapter 2 Using OpenGL Chih-Kuo Yeh. Addison Wesley OpenGL SuperBible 4 th Edition Jun 2007 Author: Richard S. Wright, Jr. Benjamin Lipchak Nicholas](https://reader035.vdocuments.us/reader035/viewer/2022062308/56649d2f5503460f94a06d85/html5/thumbnails/41.jpg)
Timer Callback
void TimerFunction(int value){
if(x > windowWidth-rsize || x < -windowWidth)xstep = -xstep;
if(y > windowHeight || y < -windowHeight + rsize)ystep = -ystep;
x += xstep;y += ystep;
if(x > (windowWidth-rsize + xstep))x = windowWidth-rsize-1;
else if(x < -(windowWidth + xstep))x = -windowWidth -1;
if(y > (windowHeight + ystep))y = windowHeight-1;
else if(y < -(windowHeight - rsize + ystep))y = -windowHeight + rsize - 1;
glutPostRedisplay();glutTimerFunc(33,TimerFunction, 1);
}
![Page 42: Chapter 2 Using OpenGL Chih-Kuo Yeh. Addison Wesley OpenGL SuperBible 4 th Edition Jun 2007 Author: Richard S. Wright, Jr. Benjamin Lipchak Nicholas](https://reader035.vdocuments.us/reader035/viewer/2022062308/56649d2f5503460f94a06d85/html5/thumbnails/42.jpg)
Time function
glutTimerFunc(unsigned int millis, void (GLUTCALLBACK *func)(int value), int value);
Registers a timer callback to be triggered in a specified number of milliseconds.
![Page 43: Chapter 2 Using OpenGL Chih-Kuo Yeh. Addison Wesley OpenGL SuperBible 4 th Edition Jun 2007 Author: Richard S. Wright, Jr. Benjamin Lipchak Nicholas](https://reader035.vdocuments.us/reader035/viewer/2022062308/56649d2f5503460f94a06d85/html5/thumbnails/43.jpg)
Double Buffering
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA);
glutSwapBuffers();
![Page 44: Chapter 2 Using OpenGL Chih-Kuo Yeh. Addison Wesley OpenGL SuperBible 4 th Edition Jun 2007 Author: Richard S. Wright, Jr. Benjamin Lipchak Nicholas](https://reader035.vdocuments.us/reader035/viewer/2022062308/56649d2f5503460f94a06d85/html5/thumbnails/44.jpg)
User Input Callbacks
Process user input glutKeyboardFunc( keyboard );
void keyboard( unsigned char key, int x, int y ) { switch( key ) { case ‘q’ : case ‘Q’ : exit( EXIT_SUCCESS ); break; case ‘r’ : case ‘R’ : rotate = GL_TRUE; glutPostRedisplay(); break; } }
![Page 45: Chapter 2 Using OpenGL Chih-Kuo Yeh. Addison Wesley OpenGL SuperBible 4 th Edition Jun 2007 Author: Richard S. Wright, Jr. Benjamin Lipchak Nicholas](https://reader035.vdocuments.us/reader035/viewer/2022062308/56649d2f5503460f94a06d85/html5/thumbnails/45.jpg)
45 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009
The mouse callback
glutMouseFunc(mymouse) void mymouse(GLint button, GLint state, GLint x, GLint y)
Returns which button (GLUT_LEFT_BUTTON, GLUT_MIDDLE_BUTTON, GLUT_RIGHT_BUTTON) caused event
state of that button (GLUT_UP, GLUT_DOWN)
Position in window