Introduction to OpenGL: Part 2

Similar documents
C++ is Fun Part 13 at Turbine/Warner Bros.! Russell Hanson

Lecture 3. Understanding of OPenGL programming

To Do. Computer Graphics (Fall 2008) Course Outline. Course Outline. Methodology for Lecture. Demo: Surreal (HW 3)

COMPUTER GRAPHICS LAB # 3

CS559: Computer Graphics. Lecture 12: OpenGL Li Zhang Spring 2008

Duc Nguyen CSE 420 Computer Graphics 10/10/2018 Homework 1

Using OpenGL with CUDA

Announcements OpenGL. Computer Graphics. Autumn 2009 CS4815

by modifying the glutinitwindowsize() function you can change the screen size to whatever you please.

Announcements OpenGL. Computer Graphics. Spring CS4815


Bob s Concise Introduction to Doxygen

Drawing Primitives. OpenGL basics

Basic Graphics Programming

Programming with OpenGL Part 3: Three Dimensions

Lectures OpenGL Introduction

UNIT 7 LIGHTING AND SHADING. 1. Explain phong lighting model. Indicate the advantages and disadvantages. (Jun2012) 10M

Abel J. P. Gomes LAB. 1. INTRODUCTION TO OpenGL

Teacher Assistant : Tamir Grossinger Reception hours: by - Building 37 / office -102 Assignments: 4 programing using

Introduction to Computer Graphics with OpenGL/GLUT

Basic Graphics Programming

Programming using OpenGL: A first Introduction

11/1/13. Basic Graphics Programming. Teaching Assistant. What is OpenGL. Course Producer. Where is OpenGL used. Graphics library (API)

Books, OpenGL, GLUT, GLUI, CUDA, OpenCL, OpenCV, PointClouds, and G3D

CMSC 425: Lecture 4 More about OpenGL and GLUT Tuesday, Feb 5, 2013

COS340A Assignment 1 I Pillemer Student# March 25 th 2007 p1/15

Programming with OpenGL Part 2: Complete Programs Computer Graphics I, Fall

GL_COLOR_BUFFER_BIT, GL_PROJECTION, GL_MODELVIEW

Computer Graphics. Making Pictures. Computer Graphics CSC470 1

Display Lists in OpenGL

Computer Graphics. OpenGL

Exercise 1 Introduction to OpenGL

Books, OpenGL, GLUT, CUDA, OpenCL, OpenCV, PointClouds, G3D, and Qt

6. Make use of glviewport() to display two sine curves on the same screen, one on the

Assignment 1. Simple Graphics program using OpenGL

Graphics Programming

Computer Graphics Course 2005

CS559: Computer Graphics. Lecture 12: OpenGL Transformation Li Zhang Spring 2008

Computer Graphics. Bing-Yu Chen National Taiwan University

Lecture 2 CISC440/640 Spring Department of Computer and Information Science

Cameras (and eye) Ideal Pinhole. Real Pinhole. Real + lens. Depth of field

Computer Graphics Primitive Attributes

OpenGL/GLUT Intro. Week 1, Fri Jan 12

CS Computer Graphics: OpenGL, Continued

CS Computer Graphics: OpenGL, Continued

1/12/11. Basic Graphics Programming. What is OpenGL. OpenGL is cross-platform. How does OpenGL work. How does OpenGL work (continued) The result

Computer Graphics (Basic OpenGL)

// double buffering and RGB glutinitdisplaymode(glut_double GLUT_RGBA); // your own initializations

2 Transformations and Homogeneous Coordinates

Computer graphics MN1

Precept 2 Aleksey Boyko February 18, 2011

CS 4731 Lecture 3: Introduction to OpenGL and GLUT: Part II. Emmanuel Agu

CS 543 Lecture 1 (Part 3) Prof Emmanuel Agu. Computer Science Dept. Worcester Polytechnic Institute (WPI)

Introduction to OpenGL

Graphics Programming. August 31, Programming of the Sierpinski gasket. Programming with OpenGL and C/C++

CS 432 Interactive Computer Graphics

Computer Graphics Introduction to OpenGL

Graphics Programming. 1. The Sierpinski Gasket. Chapter 2. Introduction:

OpenGL refresher. Advanced Computer Graphics 2012

CS 4204 Computer Graphics

2. OpenGL -I. 2.1 What is OpenGL? Things OpenGL can do: -23-

Input and Interaction. 1. Interaction. Chapter 3. Introduction: - We now turn to the development of interactive graphics programs.

Andrew Yenalavitch Homework 1 CSE Fall 2014

Interaction Computer Graphics I Lecture 3

RECITATION - 1. Ceng477 Fall

Interaction. CSCI 480 Computer Graphics Lecture 3

CS Computer Graphics: Intro to OpenGL

CS Computer Graphics: Intro to OpenGL

CS 543 Lecture 1 (Part II): Intro to OpenGL and GLUT (Part I) Emmanuel Agu

Lecture 2 2D transformations Introduction to OpenGL

CSE4030 Introduction to Computer Graphics

Fourier Series. Given a periodic function, x(t), (-T <t <T): + b n sin n t T. a n cos n t T. 2 a 0 + Z T. a n = 1 T. x(t) cos n t T. b n = 1 T.

Introduction to MS Visual C/C++

3D computer graphics: geometric modeling of objects in the computer and rendering them

OpenGL JOGL. OpenGL & JOGL. Shaoting Zhang, or Tony. September 12, 2007

FAKULTI TEKNOLOGI MAKLUMAT DAN KOMUNIKASI BITM INTERACTIVE COMPUTER GRAPHICS LAB SESSION 4. C++ - OpenGL

Hierarchical Modeling: Tree of Transformations, Display Lists and Functions, Matrix and Attribute Stacks,

ERKELEY DAVIS IRVINE LOS ANGELES RIVERSIDE SAN DIEGO SAN FRANCISCO EECS 104. Fundamentals of Computer Graphics. OpenGL

Overview of Graphics Systems Hearn & Baker Chapter 2. Some slides are taken from Robert Thomsons notes.

(21) OpenGL GUI. OpenGL GUI 1 UNIX MAGAZINE UNIX. SGI (Silicon Graphics Inc.) Windows PC GUI. UNIX Windows GUI. Java. 1 prefposition() X X

1.2 Basic Graphics Programming

Programming with OpenGL Part 1: Background

Input and Interaction

CSC Graphics Programming. Budditha Hettige Department of Statistics and Computer Science

Ulf Assarsson Department of Computer Engineering Chalmers University of Technology

VR-programming tools (procedural) More VRML later in this course! (declarative)

Computer Graphics, Chapt 08

Computer Graphics 1 Computer Graphics 1

Computer Graphics (CS 543) Lecture 1 (Part 2): Introduction to OpenGL/GLUT (Part 1)

PART-I: Lab for MCS-051 (Advanced Internet Technologies)

Computer graphics MN1

BOUNCING BALL IMRAN IHSAN ASSISTANT PROFESSOR

C OMPUTER G RAPHICS Thursday

Lectures Display List

OpenGL Introduction Computer Graphics and Visualization

... Print PROGRAMS\Final Project final\planes\planeshoot.c 1

Chapter 13 Selection and Feedback

CS418 OpenGL & GLUT Programming Tutorial (I) Presented by : Wei-Wen Feng 1/30/2008

Introduction to OpenGL

Lecture 4 of 41. Lab 1a: OpenGL Basics

Transcription:

Introduction to OpenGL: Part 2

Introduction to OpenGL: Part 2 A more complex example recursive refinement

Introduction to OpenGL: Part 2 A more complex example recursive refinement Can OpenGL draw continuous curves?

Introduction to OpenGL: Part 2 A more complex example recursive refinement Can OpenGL draw continuous curves? Yes, by segmenting the curve into a large number of straight-line segments.

Introduction to OpenGL: Part 2 A more complex example recursive refinement Can OpenGL draw continuous curves? Yes, by segmenting the curve into a large number of straight-line segments. The following code draws a simple outline of a square, using 4 lines. The square is centered at the origin, and has a radius of 1. (It is a crude approximation to a circle.)

Introduction to OpenGL: Part 2 A more complex example recursive refinement Can OpenGL draw continuous curves? Yes, by segmenting the curve into a large number of straight-line segments. The following code draws a simple outline of a square, using 4 lines. The square is centered at the origin, and has a radius of 1. (It is a crude approximation to a circle.) The program then recursively finds the center of each of the lines, and normalizes the distance from the origin to 1, making successively better approximations to a square.

Introduction to OpenGL: Part 2 A more complex example recursive refinement Can OpenGL draw continuous curves? Yes, by segmenting the curve into a large number of straight-line segments. The following code draws a simple outline of a square, using 4 lines. The square is centered at the origin, and has a radius of 1. (It is a crude approximation to a circle.) The program then recursively finds the center of each of the lines, and normalizes the distance from the origin to 1, making successively better approximations to a square. The program also parses a simple command line argument (an integer) which it uses to set the level of recursion.

Introduction to OpenGL: Part 2 A more complex example recursive refinement Can OpenGL draw continuous curves? Yes, by segmenting the curve into a large number of straight-line segments. The following code draws a simple outline of a square, using 4 lines. The square is centered at the origin, and has a radius of 1. (It is a crude approximation to a circle.) The program then recursively finds the center of each of the lines, and normalizes the distance from the origin to 1, making successively better approximations to a square. The program also parses a simple command line argument (an integer) which it uses to set the level of recursion. (The C language has I/O functions which are quite different from JAVA or C++.)

Introduction to OpenGL: Part 2 A more complex example recursive refinement Can OpenGL draw continuous curves? Yes, by segmenting the curve into a large number of straight-line segments. The following code draws a simple outline of a square, using 4 lines. The square is centered at the origin, and has a radius of 1. (It is a crude approximation to a circle.) The program then recursively finds the center of each of the lines, and normalizes the distance from the origin to 1, making successively better approximations to a square. The program also parses a simple command line argument (an integer) which it uses to set the level of recursion. (The C language has I/O functions which are quite different from JAVA or C++.) 1 1

/* recursive_circle.c * This is a simple, introductory OpenGL program. * It draws a circle on a white background by recursively * subdividing the sides of a square and renormalizing * the distance from the origin. */ #include <stdio.h> #include <stdlib.h> #include <math.h> #include <GL/glut.h> int n=0; \\ the number of levels of recursion

/* recursive_circle.c * This is a simple, introductory OpenGL program. * It draws a circle on a white background by recursively * subdividing the sides of a square and renormalizing * the distance from the origin. */ #include <stdio.h> #include <stdlib.h> #include <math.h> #include <GL/glut.h> int n=0; \\ the number of levels of recursion void init (void) { /* select clearing color as white */ glclearcolor (1.0, 1.0, 1.0, 0.0); /* initialize viewing values */ glmatrixmode(gl_projection); glloadidentity(); glortho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0); } 2

// the recursive function void drawside(float x0,float y0,float x1,float y1,int n) { float xm, ym, norm; if (n <= 0) { // the stopping condition glbegin(gl_lines); // drawing only done here glvertex3f(x0,y0,0.0); glvertex3f(x1,y1,0.0); glend(); }

// the recursive function void drawside(float x0,float y0,float x1,float y1,int n) { float xm, ym, norm; if (n <= 0) { glbegin(gl_lines); glvertex3f(x0,y0,0.0); glvertex3f(x1,y1,0.0); glend(); } else{ n--; xm = 0.5*(x0 + x1); ym = 0.5*(y0 + y1); // the stopping condition // drawing only done here // the recursion // decriment counter // calculate midpoints

// the recursive function void drawside(float x0,float y0,float x1,float y1,int n) { float xm, ym, norm; if (n <= 0) { glbegin(gl_lines); glvertex3f(x0,y0,0.0); glvertex3f(x1,y1,0.0); glend(); } else{ n--; xm = 0.5*(x0 + x1); ym = 0.5*(y0 + y1); norm = sqrt(xm*xm +ym*ym); xm = xm/norm; ym = ym/norm; // the stopping condition // drawing only done here // the recursion // decriment counter // calculate midpoints // normalize line

// the recursive function void drawside(float x0,float y0,float x1,float y1,int n) { float xm, ym, norm; if (n <= 0) { glbegin(gl_lines); glvertex3f(x0,y0,0.0); glvertex3f(x1,y1,0.0); glend(); } else{ } n--; xm = 0.5*(x0 + x1); ym = 0.5*(y0 + y1); norm = sqrt(xm*xm +ym*ym); xm = xm/norm; ym = ym/norm; drawside(x0,y0,xm,ym,n); drawside(xm,ym,x1,y1,n); } // the stopping condition // drawing only done here // the recursion // decriment counter // calculate midpoints // normalize line 3

void display(void) { \\ the new display function

void display(void) \\ the new display function { float x0, y0; /* clear all pixels */ glclear (GL_COLOR_BUFFER_BIT); /* * set initial sides of square with unit "radius" * centered at (0.0, 0.0, 0.0). */ glcolor3f (1.0, 0.0, 0.0); x0 = 1.0/sqrt(2.0); y0 = x0;

void display(void) { float x0, y0; /* clear all pixels */ /* glclear (GL_COLOR_BUFFER_BIT); \\ the new display function * set initial sides of square with unit "radius" * centered at (0.0, 0.0, 0.0). */ glcolor3f (1.0, 0.0, 0.0); x0 = 1.0/sqrt(2.0); y0 = x0; drawside(x0,y0,-x0,y0,n);

void display(void) { float x0, y0; /* clear all pixels */ /* glclear (GL_COLOR_BUFFER_BIT); \\ the new display function * set initial sides of square with unit "radius" * centered at (0.0, 0.0, 0.0). */ glcolor3f (1.0, 0.0, 0.0); x0 = 1.0/sqrt(2.0); y0 = x0; drawside(x0,y0,-x0,y0,n); drawside(-x0,y0,-x0,-y0,n);

void display(void) { float x0, y0; /* clear all pixels */ /* glclear (GL_COLOR_BUFFER_BIT); \\ the new display function * set initial sides of square with unit "radius" * centered at (0.0, 0.0, 0.0). */ glcolor3f (1.0, 0.0, 0.0); x0 = 1.0/sqrt(2.0); y0 = x0; drawside(x0,y0,-x0,y0,n); drawside(-x0,y0,-x0,-y0,n); drawside(-x0,-y0,x0,-y0,n);

void display(void) { float x0, y0; /* clear all pixels */ /* glclear (GL_COLOR_BUFFER_BIT); \\ the new display function * set initial sides of square with unit "radius" * centered at (0.0, 0.0, 0.0). */ glcolor3f (1.0, 0.0, 0.0); x0 = 1.0/sqrt(2.0); y0 = x0; drawside(x0,y0,-x0,y0,n); drawside(-x0,y0,-x0,-y0,n); drawside(-x0,-y0,x0,-y0,n); drawside(x0,-y0,x0,y0,n);

void display(void) { float x0, y0; /* clear all pixels */ /* glclear (GL_COLOR_BUFFER_BIT); \\ the new display function * set initial sides of square with unit "radius" * centered at (0.0, 0.0, 0.0). */ glcolor3f (1.0, 0.0, 0.0); x0 = 1.0/sqrt(2.0); y0 = x0; drawside(x0,y0,-x0,y0,n); drawside(-x0,y0,-x0,-y0,n); drawside(-x0,-y0,x0,-y0,n); drawside(x0,-y0,x0,y0,n); } glflush (); 4

int main(int argc, char** argv) /* * Declare initial window size, position, and * display mode (single buffer and RGBA). * Open window with "circle" * in its title bar. * Call initialization routines. * Register callback function to display graphics. * Enter main loop and process events. */ {

int main(int argc, char** argv) /* * Declare initial window size, position, and * display mode (single buffer and RGBA). * Open window with "circle" * in its title bar. * Call initialization routines. * Register callback function to display graphics. * Enter main loop and process events. */ { if (argc == 2) sscanf(argv[1],"%i",&n);

int main(int argc, char** argv) /* * Declare initial window size, position, and * display mode (single buffer and RGBA). * Open window with "circle" * in its title bar. * Call initialization routines. * Register callback function to display graphics. * Enter main loop and process events. */ { if (argc == 2) sscanf(argv[1],"%i",&n); } glutinit(&argc, argv); glutinitdisplaymode (GLUT_SINGLE GLUT_RGB); glutinitwindowsize (400, 400); glutinitwindowposition (100, 100); glutcreatewindow ("circle"); init (); glutdisplayfunc(display); glutmainloop(); return 0; /* ANSI C requires main to return int. */ 5

Consider the following line of code: if (argc == 2) sscanf(argv[1],"%i",&n); The function sscanf(...) is one of the C input functions. There are several, which do formatted input.

Consider the following line of code: if (argc == 2) sscanf(argv[1],"%i",&n); The function sscanf(...) is one of the C input functions. There are several, which do formatted input. sscanf takes input from a character string and reads it according to the specified format.

Consider the following line of code: if (argc == 2) sscanf(argv[1],"%i",&n); The function sscanf(...) is one of the C input functions. There are several, which do formatted input. sscanf takes input from a character string and reads it according to the specified format. argv[1] is the character string corresponding to the first command line argument.

Consider the following line of code: if (argc == 2) sscanf(argv[1],"%i",&n); The function sscanf(...) is one of the C input functions. There are several, which do formatted input. sscanf takes input from a character string and reads it according to the specified format. argv[1] is the character string corresponding to the first command line argument. The constant character string "%i" is the format string, telling the function that the input string represents an integer.

Consider the following line of code: if (argc == 2) sscanf(argv[1],"%i",&n); The function sscanf(...) is one of the C input functions. There are several, which do formatted input. sscanf takes input from a character string and reads it according to the specified format. argv[1] is the character string corresponding to the first command line argument. The constant character string "%i" is the format string, telling the function that the input string represents an integer. The third argument, &n, is a pointer to the integer variable n which is the value of the integer which was read.

Consider the following line of code: if (argc == 2) sscanf(argv[1],"%i",&n); The function sscanf(...) is one of the C input functions. There are several, which do formatted input. sscanf takes input from a character string and reads it according to the specified format. argv[1] is the character string corresponding to the first command line argument. The constant character string "%i" is the format string, telling the function that the input string represents an integer. The third argument, &n, is a pointer to the integer variable n which is the value of the integer which was read. The man page for scanf gives descriptions of sscanf and related I/O functions. 6

Simple animation

Simple animation Animation is achieved by redrawing the screen repeatedly.

Simple animation Animation is achieved by redrawing the screen repeatedly. The GLUT interface to OpenGL has features to assist in animation. One is to double buffer the display memory.

Simple animation Animation is achieved by redrawing the screen repeatedly. The GLUT interface to OpenGL has features to assist in animation. One is to double buffer the display memory. With double buffering there are two separate framebuffers. One buffer is displayed while drawing operations are applied to the other buffer. After all drawing is complete, the buffers are simply swapped.

Simple animation Animation is achieved by redrawing the screen repeatedly. The GLUT interface to OpenGL has features to assist in animation. One is to double buffer the display memory. With double buffering there are two separate framebuffers. One buffer is displayed while drawing operations are applied to the other buffer. After all drawing is complete, the buffers are simply swapped. Without double buffering the contents of the framebuffer can be changed while being copied to the screen. This can cause serious artefacts.

Simple animation Animation is achieved by redrawing the screen repeatedly. The GLUT interface to OpenGL has features to assist in animation. One is to double buffer the display memory. With double buffering there are two separate framebuffers. One buffer is displayed while drawing operations are applied to the other buffer. After all drawing is complete, the buffers are simply swapped. Without double buffering the contents of the framebuffer can be changed while being copied to the screen. This can cause serious artefacts. Another animation-supporting feature of GLUT is glutpostdisplay a function which posts an event, causing the display to be redrawn.

Simple animation Animation is achieved by redrawing the screen repeatedly. The GLUT interface to OpenGL has features to assist in animation. One is to double buffer the display memory. With double buffering there are two separate framebuffers. One buffer is displayed while drawing operations are applied to the other buffer. After all drawing is complete, the buffers are simply swapped. Without double buffering the contents of the framebuffer can be changed while being copied to the screen. This can cause serious artefacts. Another animation-supporting feature of GLUT is glutpostdisplay a function which posts an event, causing the display to be redrawn. The following additions to the display and main functions show a very simple animation of the previous example, in which the color of the square is changed randomly.

Simple animation Animation is achieved by redrawing the screen repeatedly. The GLUT interface to OpenGL has features to assist in animation. One is to double buffer the display memory. With double buffering there are two separate framebuffers. One buffer is displayed while drawing operations are applied to the other buffer. After all drawing is complete, the buffers are simply swapped. Without double buffering the contents of the framebuffer can be changed while being copied to the screen. This can cause serious artefacts. Another animation-supporting feature of GLUT is glutpostdisplay a function which posts an event, causing the display to be redrawn. The following additions to the display and main functions show a very simple animation of the previous example, in which the color of the square is changed randomly. The random color change is accomplished with the following change to the function display():

Simple animation Animation is achieved by redrawing the screen repeatedly. The GLUT interface to OpenGL has features to assist in animation. One is to double buffer the display memory. With double buffering there are two separate framebuffers. One buffer is displayed while drawing operations are applied to the other buffer. After all drawing is complete, the buffers are simply swapped. Without double buffering the contents of the framebuffer can be changed while being copied to the screen. This can cause serious artefacts. Another animation-supporting feature of GLUT is glutpostdisplay a function which posts an event, causing the display to be redrawn. The following additions to the display and main functions show a very simple animation of the previous example, in which the color of the square is changed randomly. The random color change is accomplished with the following change to the function display(): glcolor3i (rand(), rand(), rand()); 7

The double buffering and the re-running of the display() function are effected by the following:

The double buffering and the re-running of the display() function are effected by the following: glutswapbuffers(); glutpostredisplay();

The double buffering and the re-running of the display() function are effected by the following: glutswapbuffers(); glutpostredisplay(); The C function

The double buffering and the re-running of the display() function are effected by the following: glutswapbuffers(); glutpostredisplay(); The C function usleep(100000);

The double buffering and the re-running of the display() function are effected by the following: glutswapbuffers(); glutpostredisplay(); The C function usleep(100000); suspends execution of the process for 100000 microseconds (0.1 seconds). 8

void display(void) { /* clear all pixels */ glclear (GL_COLOR_BUFFER_BIT); /* draw random color rectangle with corners at * (0.25, 0.25, 0.0) and (0.75, 0.75, 0.0) */

void display(void) { /* clear all pixels */ glclear (GL_COLOR_BUFFER_BIT); /* draw random color rectangle with corners at * (0.25, 0.25, 0.0) and (0.75, 0.75, 0.0) */ glcolor3i (rand(), rand(), rand());

void display(void) { /* clear all pixels */ glclear (GL_COLOR_BUFFER_BIT); /* draw random color rectangle with corners at * (0.25, 0.25, 0.0) and (0.75, 0.75, 0.0) */ glcolor3i (rand(), rand(), rand()); glbegin(gl_polygon); glvertex3f (0.25, 0.25, 0.0); glvertex3f (0.75, 0.25, 0.0); glvertex3f (0.75, 0.75, 0.0); glvertex3f (0.25, 0.75, 0.0); glend(); /* start processing buffered OpenGL routines */

void display(void) { /* clear all pixels */ glclear (GL_COLOR_BUFFER_BIT); /* draw random color rectangle with corners at * (0.25, 0.25, 0.0) and (0.75, 0.75, 0.0) */ glcolor3i (rand(), rand(), rand()); glbegin(gl_polygon); glvertex3f (0.25, 0.25, 0.0); glvertex3f (0.75, 0.25, 0.0); glvertex3f (0.75, 0.75, 0.0); glvertex3f (0.25, 0.75, 0.0); glend(); /* start processing buffered OpenGL routines */ glflush ();

void display(void) { /* clear all pixels */ glclear (GL_COLOR_BUFFER_BIT); /* draw random color rectangle with corners at * (0.25, 0.25, 0.0) and (0.75, 0.75, 0.0) */ glcolor3i (rand(), rand(), rand()); glbegin(gl_polygon); glvertex3f (0.25, 0.25, 0.0); glvertex3f (0.75, 0.25, 0.0); glvertex3f (0.75, 0.75, 0.0); glvertex3f (0.25, 0.75, 0.0); glend(); /* start processing buffered OpenGL routines */ glflush (); glutswapbuffers();

void display(void) { /* clear all pixels */ glclear (GL_COLOR_BUFFER_BIT); /* draw random color rectangle with corners at * (0.25, 0.25, 0.0) and (0.75, 0.75, 0.0) */ glcolor3i (rand(), rand(), rand()); glbegin(gl_polygon); glvertex3f (0.25, 0.25, 0.0); glvertex3f (0.75, 0.25, 0.0); glvertex3f (0.75, 0.75, 0.0); glvertex3f (0.25, 0.75, 0.0); glend(); /* start processing buffered OpenGL routines */ glflush (); glutswapbuffers(); usleep(100000);

void display(void) { /* clear all pixels */ glclear (GL_COLOR_BUFFER_BIT); /* draw random color rectangle with corners at * (0.25, 0.25, 0.0) and (0.75, 0.75, 0.0) */ glcolor3i (rand(), rand(), rand()); glbegin(gl_polygon); glvertex3f (0.25, 0.25, 0.0); glvertex3f (0.75, 0.25, 0.0); glvertex3f (0.75, 0.75, 0.0); glvertex3f (0.25, 0.75, 0.0); glend(); /* start processing buffered OpenGL routines */ glflush (); glutswapbuffers(); usleep(100000); glutpostredisplay(); } 9

int main(int argc, char** argv) /* * Declare initial window size, position, and * display mode (double buffer and RGBA). * Open window with "new_hello" in its title bar. * Call initialization routines. * Register callback function to display graphics. * Enter main loop and process events. */ { glutinit(&argc, argv);

int main(int argc, char** argv) /* * Declare initial window size, position, and * display mode (double buffer and RGBA). * Open window with "new_hello" in its title bar. * Call initialization routines. * Register callback function to display graphics. * Enter main loop and process events. */ { glutinit(&argc, argv); glutinitdisplaymode (GLUT DOUBLE GLUT RGB);

int main(int argc, char** argv) /* * Declare initial window size, position, and * display mode (double buffer and RGBA). * Open window with "new_hello" in its title bar. * Call initialization routines. * Register callback function to display graphics. * Enter main loop and process events. */ { glutinit(&argc, argv); glutinitdisplaymode (GLUT DOUBLE GLUT RGB); } glutinitwindowsize (250, 250); glutinitwindowposition (100, 100); glutcreatewindow ("new_hello"); init (); glutdisplayfunc(display); glutmainloop(); return 0; /* ANSI C requires main to return int. */ 10