Computer Graphics (Basic OpenGL, Input and Interaction)



Similar documents
Graphics Pipeline in a Nutshell

The mouse callback. Positioning. Working with Callbacks. Obtaining the window size. Objectives

Input and Interaction. Project Sketchpad. Graphical Input. Physical Devices. Objectives

Computer Graphics Labs

Computer Graphics Labs

Input and Interaction

Input and Interaction. CS 432 Interactive Computer Graphics Prof. David E. Breen Department of Computer Science

Graphics Input Primitives. 5. Input Devices Introduction to OpenGL. String Choice/Selection Valuator

An Introduction to. Graphics Programming

CMSC 427 Computer Graphics 1

Chapter 1 Introduction to OpenGL

OpenGL & Delphi. Max Kleiner. 1/22

CMSC 427 Computer Graphics 1

Keyboard Mouse and Menus

Methodology for Lecture. Review of Last Demo

Univers Virtuels. OpenGL : Modélisation / Visualisation. Alexis NEDELEC. Centre Européen de Réalité Virtuelle Ecole Nationale d Ingénieurs de Brest

Lecture 3: Coordinate Systems and Transformations

An Introduction to 3D Computer Graphics, Stereoscopic Image, and Animation in OpenGL and C/C++ Fore June

CS 4204 Computer Graphics

Aston University. School of Engineering & Applied Science

Input and Interaction. Objectives

CS 378: Computer Game Technology

Blender Notes. Introduction to Digital Modelling and Animation in Design Blender Tutorial - week 9 The Game Engine

Petrel TIPS&TRICKS from SCM

Einführung Computergraphik (WS 2014/15)

Tutorial: Biped Character in 3D Studio Max 7, Easy Animation

2: Introducing image synthesis. Some orientation how did we get here? Graphics system architecture Overview of OpenGL / GLU / GLUT

Lecture Notes, CEng 477

Lesson 4. Temporal Management of Layers

Image Processing and Computer Graphics. Rendering Pipeline. Matthias Teschner. Computer Science Department University of Freiburg

Monash University Clayton s School of Information Technology CSE3313 Computer Graphics Sample Exam Questions 2007

Transformations in the pipeline

Tutorial 13: Object Animation

4BA6 - Topic 4 Dr. Steven Collins. Chap. 5 3D Viewing and Projections

How To Teach Computer Graphics

The Keyboard One of the first peripherals to be used with a computer and is still the primary input device for text and numbers.

Silverlight for Windows Embedded Graphics and Rendering Pipeline 1

Visualization of 2D Domains

Lesson 10: Video-Out Interface

Practical Data Visualization and Virtual Reality. Virtual Reality VR Software and Programming. Karljohan Lundin Palmerius

Computer Graphics Through OpenGL: From Theory to Experiments

Jawaharlal Nehru Engineering College

EasyC. Programming Tips

Debugging with TotalView

Basic controls of Rhinoceros 3D software

Understand the Sketcher workbench of CATIA V5.

Below is a diagram explaining the data packet and the timing related to the mouse clock while receiving a byte from the PS-2 mouse:

Computer Graphics. Computer graphics deals with all aspects of creating images with a computer

CREATING A 3D VISUALISATION OF YOUR PLANS IN PLANSXPRESS AND CORTONA VRML CLIENT

Auto Clicker Tutorial

SketchUp Instructions

Canterbury Maps Quick Start - Drawing and Printing Tools

Computer Graphics. Anders Hast

13-1. This chapter explains how to use different objects.

Adobe Illustrator CS5 Part 1: Introduction to Illustrator

CSE 564: Visualization. GPU Programming (First Steps) GPU Generations. Klaus Mueller. Computer Science Department Stony Brook University

Procedure for updating Firmware of EZ4 W or ICC50 W

1 Introduction. 2 Project Browser. 3 FlowStone Editor

PC GRAPHICS CARD INSTALLATION GUIDE & USER MANUAL. AGP version: GC- K2A-64 PCI version: GC- K2P-64

A. OPENING POINT CLOUDS. (Notepad++ Text editor) (Cloud Compare Point cloud and mesh editor) (MeshLab Point cloud and mesh editor)

HANDLING SUSPEND MODE ON A USB MOUSE

OpenGL Shading Language Course. Chapter 5 Appendix. By Jacobo Rodriguez Villar jacobo.rodriguez@typhoonlabs.com

VMS A1 Client Software. User Manual (V2.0)

Introduction to Computer Graphics

User Guide. March Moovly.com. Discover all Moovly Features and learn how to create videos like a Pro!

Creating a Logo in CorelDRAW

Introduction to CATIA V5

Programming the VEX Robot

How To Run A Factory I/O On A Microsoft Gpu 2.5 (Sdk) On A Computer Or Microsoft Powerbook 2.3 (Powerpoint) On An Android Computer Or Macbook 2 (Powerstation) On

Instructions for Importing (migrating) Data

Android and OpenGL. Android Smartphone Programming. Matthias Keil. University of Freiburg

A Tutorial for 3D Point Cloud Editor

Realtime 3D Computer Graphics Virtual Reality

Open icon. The Select Layer To Add dialog opens. Click here to display

How To Program An Nxt Mindstorms On A Computer Or Tablet Computer

Sources: On the Web: Slides will be available on:

Pro/E Design Animation Tutorial*

Graphic Design. Background: The part of an artwork that appears to be farthest from the viewer, or in the distance of the scene.

Given a point cloud, polygon, or sampled parametric curve, we can use transformations for several purposes:

While Loops and Animations

School of Electrical and Information Engineering. The Remote Laboratory System. Electrical and Information Engineering Project 2006.

Introduzione ad OpenGL

Creating Hyperlinks & Buttons InDesign CS6

Scripting in Unity3D (vers. 4.2)

PN-L702B LCD MONITOR TOUCH PANEL DRIVER OPERATION MANUAL. Version 2.1

Petrel TIPS&TRICKS from SCM

Software Vulnerabilities

GeoGebra. 10 lessons. Gerrit Stols

SMART Board Tips & Tricks (version 9.0) Getting Started. SMART Tools vs. SMART Notebook software

CATIA Basic Concepts TABLE OF CONTENTS

2013 Getting Started Guide

KaleidaGraph Quick Start Guide

Infor ERP BaanIV / Baan 5.0 / LN 6.1. User's Guide for Worktop 2.4

Advanced Programming with LEGO NXT MindStorms

Blender 3D: Noob to Pro/Die Another Way

How to set up a scoring algorithm and automatic triggers for Qualtrics measures

CATIA Drafting TABLE OF CONTENTS

Transcription:

Computer Graphics (Basic OpenGL, Input and Interaction) Thilo Kielmann Fall 2008 Vrije Universiteit, Amsterdam kielmann@cs.vu.nl http://www.cs.vu.nl/ graphics/ Computer Graphics (Basic OpenGL, Input and Interaction), ((55)) c 2000 2008, Thilo Kielmann 1 Outline for today 3D graphics Input devices Programming event-driven input Picking Animating interactive programs 3D graphics

Computer Graphics (Basic OpenGL, Input and Interaction), ((55)) c 2000 2008, Thilo Kielmann 2 Sierpinski Gasket by Triangle Bisection Computer Graphics (Basic OpenGL, Input and Interaction), ((55)) c 2000 2008, Thilo Kielmann 3 void triangle( point2 a, point2 b, point2 c){ glbegin(gl_triangles); glvertex2fv(a); glvertex2fv(b); glvertex2fv(c); glend(); Drawing a Triangle

Computer Graphics (Basic OpenGL, Input and Interaction), ((55)) c 2000 2008, Thilo Kielmann 4 Dividing Triangles void divide_triangle(point2 a, point2 b, point2 c, int m){ point2 v0, v1, v2; int j; if(m>0) { for(j=0; j<2; j++) v0[j]=(a[j]+b[j])/2; for(j=0; j<2; j++) v1[j]=(a[j]+c[j])/2; for(j=0; j<2; j++) v2[j]=(b[j]+c[j])/2; divide_triangle(a, v0, v1, m-1); divide_triangle(c, v1, v2, m-1); divide_triangle(b, v2, v0, m-1); else(triangle(a,b,c)); Computer Graphics (Basic OpenGL, Input and Interaction), ((55)) c 2000 2008, Thilo Kielmann 5 void display(void) { glclear(gl_color_buffer_bit); divide_triangle(v[0], v[1], v[2], n); glflush(); Display it

Computer Graphics (Basic OpenGL, Input and Interaction), ((55)) c 2000 2008, Thilo Kielmann 6 The 3-Dimensional Gasket Computer Graphics (Basic OpenGL, Input and Interaction), ((55)) c 2000 2008, Thilo Kielmann 7 void myinit(void){ myinit() for 3D gasket glclearcolor(1.0, 1.0, 1.0, 1.0); /* white background */ glmatrixmode(gl_projection); glloadidentity(); glortho(-500.0, 500.0, -500.0, 500.0, -500.0, 500.0); glmatrixmode(gl_modelview);

Computer Graphics (Basic OpenGL, Input and Interaction), ((55)) c 2000 2008, Thilo Kielmann 8 void triangle( point3 a, point3 b, point3 c){ glbegin(gl_triangles); glvertex3fv(a); glvertex3fv(b); glvertex3fv(c); glend(); Drawing a 3D-Triangle Computer Graphics (Basic OpenGL, Input and Interaction), ((55)) c 2000 2008, Thilo Kielmann 9 Dividing 3D-Triangles void divide_triangle(point3 a, point3 b, point3 c, int m){ point3 v0, v1, v2; int j; if(m>0){ for(j=0; j<3; j++) v0[j]=(a[j]+b[j])/2; for(j=0; j<3; j++) v1[j]=(a[j]+c[j])/2; for(j=0; j<3; j++) v2[j]=(b[j]+c[j])/2; divide_triangle(a, v0, v1, m-1); divide_triangle(c, v1, v2, m-1); divide_triangle(b, v2, v0, m-1); else(triangle(a,b,c));

Computer Graphics (Basic OpenGL, Input and Interaction), ((55)) c 2000 2008, Thilo Kielmann 10 void display(void){ /* be n the recursion level */ glclear(gl_color_buffer_bit); glcolor3f(1.0,0.0,0.0); divide_triangle(v[0],v[2],v[3], n); glcolor3f(0.0,1.0,0.0); divide_triangle(v[0],v[1],v[2], n); glcolor3f(0.0,0.0,1.0); divide_triangle(v[1],v[2],v[3], n); glcolor3f(0.0,0.0,0.0); divide_triangle(v[0],v[1],v[3], n); glflush(); display() for 3D with triangles Computer Graphics (Basic OpenGL, Input and Interaction), ((55)) c 2000 2008, Thilo Kielmann 11 Hidden Surface Removal

Computer Graphics (Basic OpenGL, Input and Interaction), ((55)) c 2000 2008, Thilo Kielmann 12 int main(int argc, char **argv) { if ( argc < 2 ) { printf("synopsis: %s <recursion depth>\n",argv[0]); else{ n=atoi(argv[1]); glutinit(&argc, argv); glutinitdisplaymode(glut_single GLUT_RGB GLUT_DEPTH ); glutinitwindowsize(500, 500); glutcreatewindow("3d Gasket, Triangles, hidden-surface removal"); glutdisplayfunc(display); glenable(gl_depth_test); myinit(); glutmainloop(); return 0; Let s add Hidden-Surface Removal Computer Graphics (Basic OpenGL, Input and Interaction), ((55)) c 2000 2008, Thilo Kielmann 13... and don t forget: void display(void){ glclear(gl_color_buffer_bit GL_DEPTH_BUFFER_BIT);... with without

Computer Graphics (Basic OpenGL, Input and Interaction), ((55)) c 2000 2008, Thilo Kielmann 14 Outline for today 3D graphics Input devices Programming event-driven input Picking Animating interactive programs Input devices Computer Graphics (Basic OpenGL, Input and Interaction), ((55)) c 2000 2008, Thilo Kielmann 15 Input and Interaction Interaction with the user requires input devices physical input devices input modes

Computer Graphics (Basic OpenGL, Input and Interaction), ((55)) c 2000 2008, Thilo Kielmann 16 Physical Input Devices pointing device (mouse, trackball) keyboard device (keyboard) Computer Graphics (Basic OpenGL, Input and Interaction), ((55)) c 2000 2008, Thilo Kielmann 17 Relative Positioning Device driver (or application) integrates mouse movement ticks (velocity) over time to compute new position.

Computer Graphics (Basic OpenGL, Input and Interaction), ((55)) c 2000 2008, Thilo Kielmann 18 Data tablet: Absolute Positioning Computer Graphics (Basic OpenGL, Input and Interaction), ((55)) c 2000 2008, Thilo Kielmann 19 Lightpen (Absolute Positioning) Problems: dark screen areas, ergonomics

Computer Graphics (Basic OpenGL, Input and Interaction), ((55)) c 2000 2008, Thilo Kielmann 20 Joystick and Spaceball Movement interpreted as velocity/acceleration provides mechanical resistance Computer Graphics (Basic OpenGL, Input and Interaction), ((55)) c 2000 2008, Thilo Kielmann 21 Measure and Trigger Measure: input data mouse position, typed string,... Trigger: signaling the application mouse button, return key,...

Computer Graphics (Basic OpenGL, Input and Interaction), ((55)) c 2000 2008, Thilo Kielmann 22 Request mode: Input Modes Sample mode: Event mode: Computer Graphics (Basic OpenGL, Input and Interaction), ((55)) c 2000 2008, Thilo Kielmann 23 Advantages of the Event Mode Program does not need to request/sample explicitly (no polling): No waste of CPU time while there is no input. No problem with location of polling statements in the code, and how often polling should occur... Multiple input devices (types of events) can be served, even without knowing how many (and which) are active.

Computer Graphics (Basic OpenGL, Input and Interaction), ((55)) c 2000 2008, Thilo Kielmann 24 Outline for today 3D graphics Input devices Programming event-driven input Picking Animating interactive programs Programming event-driven input Computer Graphics (Basic OpenGL, Input and Interaction), ((55)) c 2000 2008, Thilo Kielmann 25 #include <GL/glut.h> int main(int argc, char** argv){ glutinit(&argc,argv);... glutdisplayfunc(display); glutkeyboardfunc(keyboard); glutmousefunc(mouse);... glutmainloop(); /* enter event loop */ return 0; Handling Events: Callback Functions

Computer Graphics (Basic OpenGL, Input and Interaction), ((55)) c 2000 2008, Thilo Kielmann 26 Mouse callback: (colors.c) void mouse(int btn, int btn_state, int x, int y){ if (btn==glut_left_button && btn_state==glut_down){ state++; state = state%7; if (btn==glut_middle_button && btn_state==glut_down){ state = 0; if (btn==glut_right_button && btn_state==glut_down){ exit(0); glutpostredisplay(); Main program: glutmousefunc(mouse); Programming Event-driven Input Computer Graphics (Basic OpenGL, Input and Interaction), ((55)) c 2000 2008, Thilo Kielmann 27 void drawsquare(int x, int y) // (square.c) { y=wh-y; /* translate window to user coordinates */ glcolor3ub( (char) random()%256, (char) random()%256, (char) random()%256); glbegin(gl_polygon); glvertex2f(x+size, y+size); glvertex2f(x-size, y+size); glvertex2f(x-size, y-size); glvertex2f(x+size, y-size); glend(); glflush(); Register: glutmotionfunc(drawsquare); Example Square Drawing

Computer Graphics (Basic OpenGL, Input and Interaction), ((55)) c 2000 2008, Thilo Kielmann 28 Mouse-related Callbacks glutmousefunc button up/down glutmotionfunc movement with button pressed glutpassivemotionfunc movement without button pressed Computer Graphics (Basic OpenGL, Input and Interaction), ((55)) c 2000 2008, Thilo Kielmann 29 void myreshape(glsizei w, GLsizei h){ (square.c) /* adjust clipping box */ glmatrixmode(gl_projection); glloadidentity(); glortho(0.0, (GLdouble)w, 0.0, (GLdouble)h, -1.0, 1.0); glmatrixmode(gl_modelview); /* adjust viewport and clear */ glviewport(0,0,w,h); glclear(gl_color_buffer_bit); glflush(); /* set global size for use by drawing routine */ ww = w; wh = h; Main program: glutreshapefunc(myreshape); (Also called when window is displayed the first time.) Reshape Events

Computer Graphics (Basic OpenGL, Input and Interaction), ((55)) c 2000 2008, Thilo Kielmann 30 Keyboard Events void keyboard(unsigned char key, int x, int y){ if ( key == q key == Q key == 27 // ESC ) exit(0); glutkeyboardfunc(keyboard); Computer Graphics (Basic OpenGL, Input and Interaction), ((55)) c 2000 2008, Thilo Kielmann 31 Example for the square program: Menus

Computer Graphics (Basic OpenGL, Input and Interaction), ((55)) c 2000 2008, Thilo Kielmann 32 Sample Menu In the main program: sub menu = glutcreatemenu(size menu); // creates and selects current menu glutaddmenuentry("increase square size", 1); // add to current menu glutaddmenuentry("decrease square size", 2); glutcreatemenu(top menu); // create new current menu glutaddmenuentry("quit",1); glutaddsubmenu("resize", sub menu); // add sub menu to menu glutattachmenu(glut RIGHT BUTTON); // attach current menu to mouse button void size menu(int id){ if (id==1) size *= 2; if (id==2) size /= 2; void top menu(int id){ if (id==1) exit(0); Computer Graphics (Basic OpenGL, Input and Interaction), ((55)) c 2000 2008, Thilo Kielmann 33 Outline for today 3D graphics Input devices Programming event-driven input Picking Animating interactive programs Picking

Computer Graphics (Basic OpenGL, Input and Interaction), ((55)) c 2000 2008, Thilo Kielmann 34 Picking Selecting a displayed object by the picking device. Problem: getting back from 2D-screen coordinate to 3D-application coordinate: Computer Graphics (Basic OpenGL, Input and Interaction), ((55)) c 2000 2008, Thilo Kielmann 35 Picking with Lightpen (once upon a time) Lightpen generates interrupt when light ray comes along. Program knows the object currently being displayed.

Computer Graphics (Basic OpenGL, Input and Interaction), ((55)) c 2000 2008, Thilo Kielmann 36 Picking for Simple Applications (2D) Application computes (2D) bounding boxes for its objects. Computer Graphics (Basic OpenGL, Input and Interaction), ((55)) c 2000 2008, Thilo Kielmann 37 Picking 3D Objects with the Rendering Pipelines Transform Project Clip vertices Geometric Pipeline Problems: OpenGL application program Operations are hard to reverse (esp. in hardware). pixels Pixel Ops Pixel Pipeline The application abstracts from screen coordinates on purpose. The logical grouping of elementary operations (vertices) to application objects is unknown to OpenGL. Frame buffer

Computer Graphics (Basic OpenGL, Input and Interaction), ((55)) c 2000 2008, Thilo Kielmann 38 Picking with OpenGL s Selection Mode Idea: 1. When user clicks into the window, re-render the scene (walk through all objects). No graphical output is produced while doing so. (special selection mode) (a) Application indicates when an object starts and ends. (b) OpenGL checks which objects are close to the (mouse) position. 2. Application interprets which object to select. Computer Graphics (Basic OpenGL, Input and Interaction), ((55)) c 2000 2008, Thilo Kielmann 39 Render Mode vs. Selection Mode Default: glrendermode(gl RENDER) Rendering output goes to frame buffer. For picking: glrendermode(gl SELECT) Rendering output goes to (user-supplied) select buffer. Select buffer stores objects that hit the picking position.

Computer Graphics (Basic OpenGL, Input and Interaction), ((55)) c 2000 2008, Thilo Kielmann 40 void glinitnames(); // initialize name stack Identifying Objects: the Name Stack void glpushname(gluint name); // "names" are unsigned integers void glpopname(); void glloadname(gluint name); // overwrite top element // meaning: "here starts object name " With simple objects, only one stack element is enough. With complex objects (see Chapter 10), the whole stack trace needs to be captured and the application needs to decide later, what is to be selected. Computer Graphics (Basic OpenGL, Input and Interaction), ((55)) c 2000 2008, Thilo Kielmann 41 Example of a Complex Object Application needs to decide whether the lower-left arm, or the whole robot should be selected.

Computer Graphics (Basic OpenGL, Input and Interaction), ((55)) c 2000 2008, Thilo Kielmann 42 Checking Proximity to Mouse by Clipping Computer Graphics (Basic OpenGL, Input and Interaction), ((55)) c 2000 2008, Thilo Kielmann 43 Proximity Check 1. Use glupickmatrix to restrict clipping region to small area around the mouse position. (We apply a magnifying glass to the viewport.) 2. Re-render in selection mode Objects within the (small) clipping region generate a hit in the select buffer Use N N pixels area rather than single pixel to allow for human imprecision...

Computer Graphics (Basic OpenGL, Input and Interaction), ((55)) c 2000 2008, Thilo Kielmann 44 void display(){ // pick.c glclear(gl_color_buffer_bit); draw_objects(gl_render); glflush(); void drawobjects(glenum mode){ if (mode==gl_select) glloadname(1); // identify first rectangle glcolor3f(1.0,0.0,0.0); glrectf(-0.5,-0.5,1.0,1.0); if (mode==gl_select) glloadname(2); // identify second rectangle glcolor3f(0.0,0.0,1.0); glrectf(-1.0,-1.0,0.5,0.5); Putting the Pieces Together... Computer Graphics (Basic OpenGL, Input and Interaction), ((55)) c 2000 2008, Thilo Kielmann 45 void mouse(int button, int state, int x, int y){ GLuint selectbuf[size]; GLint hits; GLint viewport[4]; if (button == GLUT_LEFT_BUTTON && state == GLUT_DOWN) { glgetintegerv (GL_VIEWPORT, viewport); // get current viewport glselectbuffer (SIZE, selectbuf); glrendermode(gl_select); glinitnames(); glpushname(0); // init name stack Picking in the Mouse Callback (1) glmatrixmode (GL_PROJECTION); glpushmatrix (); // save old state glloadidentity (); /* create 5x5 pixel picking region near cursor location */ glupickmatrix ((GLdouble) x, (GLdouble) (viewport[3] - y), 5.0, 5.0, viewport); gluortho2d (-2.0, 2.0, -2.0, 2.0); // same as without picking

Computer Graphics (Basic OpenGL, Input and Interaction), ((55)) c 2000 2008, Thilo Kielmann 46 drawobjects(gl_select); glmatrixmode (GL_PROJECTION); glpopmatrix (); // restore old state glflush (); hits = glrendermode (GL_RENDER); // switch back and get // number of hits Picking in the Mouse Callback (2) processhits (hits, selectbuf); // still to be implemented glutpostredisplay(); // ask GLUT for re-displaying Computer Graphics (Basic OpenGL, Input and Interaction), ((55)) c 2000 2008, Thilo Kielmann 47 The Select Buffer Data Structure The select buffer is an array of GLuint values. The data of all hits (returned by glrendermode), is stored consecutively. Values for each hit: number of names n (the depth of the name stack) minimum depth for all vertices of this hit maximum depth for all vertices of this hit name 1 name 2... name n

Computer Graphics (Basic OpenGL, Input and Interaction), ((55)) c 2000 2008, Thilo Kielmann 48 void processhits (GLint hits, GLuint buffer[]){ unsigned int i, j; GLuint ii, jj, names, *ptr; Finally, processhits() printf ("hits = %d\n", hits); ptr = (GLuint *) buffer; for (i = 0; i < hits; i++) { /* for each hit */ names = *ptr; ptr+=3; for (j = 0; j < names; j++) { /* for each name */ if(*ptr==1) printf ("red rectangle\n"); else printf ("blue rectangle\n"); ptr++; Computer Graphics (Basic OpenGL, Input and Interaction), ((55)) c 2000 2008, Thilo Kielmann 49 Outline for today 3D graphics Input devices Programming event-driven input Picking Animating interactive programs Animating interactive programs

Computer Graphics (Basic OpenGL, Input and Interaction), ((55)) c 2000 2008, Thilo Kielmann 50 A rotating square: Animating Interactive Programs Computer Graphics (Basic OpenGL, Input and Interaction), ((55)) c 2000 2008, Thilo Kielmann 51 void display(){ glclear(gl_color_buffer_bit); glbegin(gl_polygon); thetar = theta*((2.0*3.14159)/360.0); /* convert degrees to radians */ glvertex2f( cos(thetar), sin(thetar)); glvertex2f(-sin(thetar), cos(thetar)); glvertex2f(-cos(thetar),-sin(thetar)); glvertex2f( sin(thetar),-cos(thetar)); glend(); Displaying the Rotating Square This is the poor man s solution : use glrotate() instead! (once we will have learned about it)

Computer Graphics (Basic OpenGL, Input and Interaction), ((55)) c 2000 2008, Thilo Kielmann 52 double time; void idle(){ // (single.c) double t = Wallclock(); // from glutil.h (VU-made) if ( t < time + 0.01 ) return; time = t; theta+=2; if ( theta>=360.0) theta -= 360.0; glutpostredisplay(); The Idle Function Computer Graphics (Basic OpenGL, Input and Interaction), ((55)) c 2000 2008, Thilo Kielmann 53 screen image is refreshed 50-85 times per second drawing into the frame buffer is not an atomic action (and takes longer than 1/50 sec) the flickering we see is from partially drawn images solution: double buffering front buffer is used for display back buffer is used for drawing Double Buffering

Computer Graphics (Basic OpenGL, Input and Interaction), ((55)) c 2000 2008, Thilo Kielmann 54 Double Buffering (OpenGL) initialize with: glutinitdisplay(glut RGB GLUT DOUBLE) add to display(): glutswapbuffers() (single double) Computer Graphics (Basic OpenGL, Input and Interaction), ((55)) c 2000 2008, Thilo Kielmann 55 What to remember: Hidden surface removal Summary Next lecture: Affine transformations (simple math) Programming event-driven input Picking Double buffering