Introduction to OpenGL

Similar documents
Precept 2 Aleksey Boyko February 18, 2011

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


API for creating a display window and using keyboard/mouse interations. See RayWindow.cpp to see how these are used for Assignment3

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

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

Computer graphics MN1

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

GL_COLOR_BUFFER_BIT, GL_PROJECTION, GL_MODELVIEW

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

Outline. Other Graphics Technology. OpenGL Background and History. Platform Specifics. The Drawing Process

Graphics and Computation Introduction to OpenGL

Transformation, Input and Interaction. Hanyang University

1 (Practice 1) Introduction to OpenGL

Computer Graphics Course 2005

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

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

Lecture 4 of 41. Lab 1a: OpenGL Basics

Basic Graphics Programming

C OMPUTER G RAPHICS Thursday

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

Computer Graphics. OpenGL

Computer Graphics. Transformations. CSC 470 Computer Graphics 1

Lectures OpenGL Introduction

OpenGL. What it is: Client-server model Network transparent. Computer Graphics

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

Modeling Transform. Chapter 4 Geometric Transformations. Overview. Instancing. Specify transformation for objects 李同益

Understand how real-world lighting conditions are approximated by OpenGL

3D Graphics and API with OpenGL

Programming using OpenGL: A first Introduction

Lecture 3 Advanced Computer Graphics (CS & SE )

Basic Graphics Programming

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

OpenGL/GLUT Intro. Week 1, Fri Jan 12

Computer graphics MN1

Getting Started. Overview (1): Getting Started (1): Getting Started (2): Getting Started (3): COSC 4431/5331 Computer Graphics.

Drawing Primitives. OpenGL basics

Computer graphics MN1

COMPUTER GRAPHICS LAB # 3

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

Introduction to OpenGL Transformations, Viewing and Lighting. Ali Bigdelou

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

Advanced Computer Graphics (CS & SE )

Using OpenGL with CUDA

Matrix-Rechnung I ' z =... Universität Frankfurt

Lighting. Chapter 5. Chapter Objectives. After reading this chapter, you'll be able to do the following:

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

OpenGL Transformations

Introduction to Computer Graphics with OpenGL/GLUT

Introduction to OpenGL: Part 2

Lecture 3. Understanding of OPenGL programming

Computer Graphics. Making Pictures. Computer Graphics CSC470 1

Order of Transformations

Display Lists in OpenGL

20 GLuint objects; 36 Scale += 0.1; 37 break; 38 case GLUT_KEY_DOWN:

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

Spring 2013, CS 112 Programming Assignment 2 Submission Due: April 26, 2013

Lecture 2 2D transformations Introduction to OpenGL

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

2 Transformations and Homogeneous Coordinates

Introduction to OpenGL

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

Computer Graphics (Basic OpenGL)

Interaction. CSCI 480 Computer Graphics Lecture 3

Chapter 13 Selection and Feedback

OpenGL Tutorial. Ceng 477 Introduction to Computer Graphics

Computer Graphics Introduction to OpenGL

Scientific Visualization Basics

Computer Graphics Primitive Attributes

An Introduction to. Graphics Programming

Graphics Programming

Computer graphic -- Programming with OpenGL 2

Introduction to OpenGL. Prof. Dr.-Ing. Lars Linsen

OpenGL. 1 OpenGL OpenGL 1.2 3D. (euske) 1. Client-Server Model OpenGL

Interaction Computer Graphics I Lecture 3

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

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

Introduction to OpenGL

Visualizing Molecular Dynamics

OpenGL refresher. Advanced Computer Graphics 2012

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

Pearce Outline. OpenGL Background and History. Other Graphics Technology. Platform Specifics. The Drawing Process

QUESTION 1 [10] 2 COS340-A October/November 2009

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

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

Computer Graphics. Chapter 10 Three-Dimensional Viewing

OpenGL. Jimmy Johansson Norrköping Visualization and Interaction Studio Linköping University

Programming with OpenGL Part 1: Background

2/3/16. Interaction. Triangles (Clarification) Choice of Programming Language. Buffer Objects. The CPU-GPU bus. CSCI 420 Computer Graphics Lecture 3

An Interactive Introduction to OpenGL Programming

Interaction. CSCI 420 Computer Graphics Lecture 3

Lecture 5: Viewing. CSE Computer Graphics (Fall 2010)

CS 4204 Computer Graphics

Source code: #include <iostream>

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

CIS 636 Interactive Computer Graphics CIS 736 Computer Graphics Spring 2011

12. Selection. - The objects selected are specified by hit records in the selection buffer. E.R. Bachmann & P.L. McDowell MV 4202 Page 1 of 13

RECITATION - 1. Ceng477 Fall

Image Rendering. Rendering can be divided into three sub-problems. Image Formation The hidden surface problem visibility determination steps

CS Computer Graphics: OpenGL, Continued

Transcription:

Introduction to OpenGL Tutorial 1: Create a window and draw a 2D square Introduction: The aim of the first tutorial is to introduce you to the magic world of graphics based on the OpenGL and GLUT APIs. During this laboratory you will learn how to create simple 2D graphics in just a few lines of Microsoft Visual C coding. This tutorial will be used a template so that next programs will be based on. The program consists of only two functions: draw() and main(). The draw() function constructs a square object in twodimensions while the main() function displays the generated object on a window. The following program opens a window and draws a white square in a black background. Create a new workspace (call it OpenGLTutorial1) and type the following source code and see what happens. Enjoy! Implementation: // First Tutorial // Edited by Fotis Liarokapis // All rights reserved #include <GL/glut.h> // import GLUT library void draw(void) // Clears the color buffer bit glclear( GL_COLOR_BUFFER_BIT); // Draws a cube by specifying four 2D vertices glbegin(gl_polygon); glvertex2f(-0.5, -0.5); glvertex2f(-0.5, 0.5); glvertex2f( 0.5, 0.5); glvertex2f( 0.5, -0.5); glend(); // Forces execution of OpenGL functions in finite time glflush(); // Main function int main(int argc, char **argv) 1

// Initialise GLUT library glutinit(&argc, argv); // Creates a window on the screen glutcreatewindow ("OpenGL Tutorial 1"); // The display function is called each time there is a display callback glutdisplayfunc(draw); // Causes the program to enter an event-processing loop glutmainloop(); return 0; Expected Output: Functions Used: void glclear(glbitfield mask) The glclear function clears buffers to preset values including: color buffer GL_COLOR_BUFFER_BIT, depth buffer GL_DEPTH_BUFFER_BIT, accumulation buffer GL_ACCUM_BUFFER_BIT, stencil buffer GL_STENCIL_BUFFER_BIT. void glbegin(glenum mode) This function specifies the beginning of an object of various type modes including GL_POINTS, GL_LINES, and GL_POLYGON. void glvertex2f(glfloat x, GLfloat y) Specifies a two-dimensional vector. 2

void glend() This function specifies the end of a list and it is always used in conjunction with glbegin(). void glflush(void) Function that forces previously issued OpenGL commands to begin execution. void glutinit(int argc, char **argv) This command takes the arguments from main() in order to initialise GLUT. Note that glutinit() should be called before any OpenGL functions. void glutcreatewindow (*char title) This command creates a window in the screen that contains a title given by the argument. void glutdisplayfunc(void (*func)) This function is called each time there is a display callback. void glutmainloop() This command causes the program to enter an eventprocessing loop and must be always used at the end of the main() function. Tutorial 2: Initialisations in OpenGL Introduction: The second tutorial will teach you how to initialise state variables and GLUT in order to create a more complex graphics application. This tutorial will consist of three functions (draw() and main() as before) and an initialisation function (called initialisation()). The source code for this is provided below. Create a new workspace (call it OpenGLTutorial2) and type the following source code. Implementation: // Second OpenGL Tutorial // Edited by Fotis Liarokapis // All rights reserved #include <GL/glut.h> // import GLUT library // Draw function void draw(void) // Clears the color buffer bit glclear( GL_COLOR_BUFFER_BIT); 3

// Set the color to red glcolor3f(1.0, 0.0, 0.0); // Draws a cube by specifying four 3D vertices glbegin(gl_polygon); glvertex3f(-0.5, -0.5, 0.0); glvertex3f(-0.5, 0.5, 0.0); glvertex3f( 0.5, 0.5, 0.0); glvertex3f( 0.5, -0.5, 0.0); glend(); // Forces execution of OpenGL functions in finite time glflush(); // Initialise function void initialise() // Clears the color pixels to white glclearcolor(1.0, 1.0, 1.0, 0.0); // Applies matrix operations to the projection matrix stack glmatrixmode(gl_projection); // Replaces the current matrix with the identity matrix glloadidentity(); // Multiplies the current matrix by an orthographic matrix glortho(-5.0, 5.0, -5.0, 5.0, -1.0, 1.0); // Main function int main(int argc, char **argv) // Initialise GLUT library glutinit(&argc, argv); // Initialise the display mode glutinitdisplaymode(glut_single GLUT_RGB); // Initialise the window position glutinitwindowposition(300, 300); // Initialise the window size glutinitwindowsize(500, 500); 4

// Creates a window on the screen glutcreatewindow ("OpenGL Tutorial 2"); // The display function is called each time there is a display callback glutdisplayfunc(draw); // Call the initialise function initialise(); // Causes the program to enter an event-processing loop glutmainloop(); return 0; Expected Output: 5

Functions Used: void glcolor3f(glfloat red, GLfloat green, GLfloat blue) This function define the color used by specifying the red, green and blue (RGB) components. void glclearcolor(glclampf red, GLclampf green, GLclampf blue, GLclampf alpha) This function specifies the clear values for the color buffers. void glmatrixmode(glenum mode) The glmatrixmode function specifies which matrix is the current matrix (GL_MODELVIEW Applies subsequent matrix operations to the modelview matrix stack, GL_PROJECTION Applies subsequent matrix operations to the projection matrix stack, GL_TEXTURE Applies subsequent matrix operations to the texture matrix stack). void glloadidentity(void) The glloadidentity function replaces the current matrix with the identity matrix. void glortho(gldouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble znear, GLdouble zfar) The glortho function multiplies the current matrix by an orthographic matrix. void glutinitdisplaymode(unsigned int mode) Function that requests a display with the properties in mode. The values of mode can be combined using options like the color model (GLUT_RGB, GLUT_INDEX) and buffering of color buffers like (GLUT_SINGLE, GLUT_DOUBLE). void glutinitwindowposition(int x, int y) Function that specifies the top-left corner of the window (in pixels) starting from the top-left corner of the screen. void glutinitwindowsize(int width, int height) Function that specifies the initial height and width (in pixels) of the window on the screen. Tutorial 3: Rotation, simple menu and reading from keyboard Introduction: In the third tutorial you will learn three things: how to rotate a graphical object on a window, how to create a menu in the command window and how to read input values from the keyboard. The rotation operations are provided by OpenGL API. The menu in the command window can be done in standard C while the reading from the keyboard operation is provided by the GLUT API. For these operations three more functions have been added: spinscene(),keyboard() and menu(). The spinscene() function performs simple mathematical operations to calculate the rotation angle. The Keyboard() function defines the keyboard keys that will be used and the menu() function prints a help menu 6

on the command window. To see how this works in practice create a new workspace (call it OpenGLTutorial3) and type in the following source code. Implementation: // Third OpenGL Tutorial // Edited by Fotis Liarokapis // All rights reserved #include <stdio.h> #include <stdlib.h> #include <GL/glut.h> // import standard C library // import standard C library // import GLUT library static GLfloat spin = 0.0; // global variable to determine the spin // Spin the scene void spinscene(void) // increment spin by a factor spin += 1; // Spin for ever if (spin > 360.0) spin = spin - 360.0; // Marks the normal plane of current window as needing to be redisplayed glutpostredisplay(); // Draw function void draw(void) // Clears the color buffer bit glclear( GL_COLOR_BUFFER_BIT); // Push the current matrix stack glpushmatrix(); // Set the color to blue glcolor3f(0.0, 0.0, 1.0); // Multiply the current matrix by a rotation matrix 7

glrotatef(spin, 0.0, 0.0, 1.0); // Draws a cube by specifying four 3D vertices glbegin(gl_polygon); glvertex3f(-0.5, -0.5, 0.0); glvertex3f(-0.5, 0.5, 0.0); glvertex3f( 0.5, 0.5, 0.0); glvertex3f( 0.5, -0.5, 0.0); glend(); // Pops the current matrix stack glpopmatrix(); // Swaps the buffers glutswapbuffers(); // Initialise function void initialise() // Clears the color pixels to white glclearcolor(1.0, 1.0, 1.0, 0.0); // Reshapes the window void reshape(int w, int h) // Sets the viewport glviewport (0, 0, (GLsizei) w, (GLsizei) h); // Applies matrix operations to the projection matrix stack glmatrixmode(gl_projection); // Replaces the current matrix with the identity matrix glloadidentity(); // Multiplies the current matrix by an orthographic matrix glortho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0); // Applies matrix operations to the modelview matrix stack glmatrixmode(gl_modelview); // Replaces the current matrix with the identity matrix glloadidentity(); 8

// Function that reads input from the keyboard void Keyboard(unsigned char key, int A, int B) switch(key) // Start rotation case '1': // Sets the global idle callback glutidlefunc(spinscene); break; // Stop rotation case '2': // Sets the global idle callback glutidlefunc(null); break; // Escapes from the program by pressing 'Esc' case 27: // Terminates the program exit(0); break; default: break; // Function that prints a menu on the command window void menu(void) printf("------------ OPTIONS -------------\n"); printf("press 1 to start rotation\n"); printf("press 2 to start rotation\n"); printf("press Esc to terminate the program\n"); printf("----------------------------------\n"); // Main function int main(int argc, char **argv) menu(); // Initialise GLUT library glutinit(&argc, argv); 9

// Initialise the display mode glutinitdisplaymode(glut_double GLUT_RGB); // Initialise the window position glutinitwindowposition(300, 300); // Initialise the window size glutinitwindowsize(500, 500); // Creates a window on the screen glutcreatewindow ("OpenGL Tutorial 3"); // Call the initialise function initialise(); // The display function is called each time there is a display callback glutdisplayfunc(draw); // The reshape function reshapes the scene glutreshapefunc(reshape); // Function that reads input from the keyboard glutkeyboardfunc(keyboard); // Causes the program to enter an event-processing loop glutmainloop(); return 0; Expected Output: 10

Functions Used: void glutpostredisplay() Requests the display callback to be executed. void glpushmatrix(void) This function push the current matrix stack. void glrotatef(glfloat angle, GLfloat x, GLfloat y, GLfloat z) This function is used for rotation operations. The parameters are the angle which defines the angle of rotation, in degrees and x, y, z which define the coordinates of a vector. void glpopmatrix(void) This function pop the current matrix stack. void glutswapbuffers() Function that swaps the front and back buffers. void glviewport(glint x, GLint y, GLsizei width, GLsizei height) The glviewport function sets the viewport. The x, y parameters specify the lower-left corner of the viewport rectangle, in pixels. The default is (0,0). The width, height parameters 11

spesify the width and height of the viewport. When an OpenGL context is first attached to a window, width and height are set to the dimensions of that window. void glutidlefunc(void (*f) (void)) The function f() is executed whenever no other events are to be handled. Used when we want to perform animations. void glutkeyboardfunc(void *f(unsigned char key, int x, int y)) Function that identifies the function f() that is called when any key is pressed on the keyboard. Tutorial 4: Lighting, shading and widget menu Introduction: Using the following example you will learn how to set a light source and then light a graphical object. Also you will learn hot to perform basic shading to 3D objects. Finally, using GLUT API you will be able to create cool menus in just a few minutes. To see how this works in practice create a new workspace (call it OpenGLTutorial4) and type in the following source code. Enjoy! Implementation: // Fourth OpenGL Tutorial 4 // Edited by Fotis Liarokapis // All rights reserved #include <GL/glut.h> #include <stdio.h> #include <stdlib.h> static int spin = 0.0; // import GLUT library // import standard C library // import standard C library // global variable to determine the spin // Spin the scene void spinscene(void) // increment spin by a factor spin += 1; // Spin for ever if (spin > 360.0) spin = spin - 360.0; // Marks the normal plane of current window as needing to be redisplayed glutpostredisplay(); 12

// Draw function void draw(void) // Define the position of the light source GLfloat position[] = 0.0, 0.0, 1.5, 1.0 ; // Clears the color buffer bit and depth buffer bit glclear (GL_COLOR_BUFFER_BIT GL_DEPTH_BUFFER_BIT ); // Push the current matrix stack glpushmatrix(); // Defines a viewing transformation glulookat (0.0, 0.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0); // Push the current matrix stack glpushmatrix(); // Multiply the current matrix by a rotation matrix glrotated((gldouble) spin, 1.0, 0.0, 0.0); // Set the light source parameters gllightfv(gl_light0, GL_POSITION, position); // Multiply the current matrix by a translation matrix gltranslated (0.0, 0.0, 1.5); // Disable lighting conditions gldisable(gl_lighting); // Set the color to yellow glcolor3f(1.0, 1.0, 0.0); // Draw a sphere glutsolidsphere(0.1, 20, 10); // Enable lighting glenable(gl_lighting); // Pops the current matrix stack glpopmatrix(); // Draw a torus on the screen 13

glutsolidtorus(0.3, 0.9, 8, 15); // Pops the current matrix stack glpopmatrix(); // Swaps the buffers glutswapbuffers(); // Initialise function void initialise() // Clears the color pixels to white glclearcolor(0.0, 0.0, 0.0, 0.0); // Selects smooth shading glshademodel(gl_smooth); // Enable lighting operations glenable(gl_lighting); // Enable an OpenGL light glenable(gl_light0); // Enable depth test glenable(gl_depth_test); // Reshapes the window void reshape(int w, int h) // Sets the viewport glviewport (0, 0, (GLsizei) w, (GLsizei) h); // Applies matrix operations to the projection matrix stack glmatrixmode(gl_projection); // Replaces the current matrix with the identity matrix glloadidentity(); // Sets up a perspective projection matrix gluperspective(40.0, (GLfloat) w/(glfloat) h, 1.0, 20.0); // Applies matrix operations to the modelview matrix stack 14

glmatrixmode(gl_modelview); // Replaces the current matrix with the identity matrix glloadidentity(); // Function that reads input from the keyboard void Keyboard(unsigned char key, int A, int B) switch(key) // Start rotation case '1': glutidlefunc(spinscene); // Sets the global idle callback break; // Stop rotation case '2': glutidlefunc(null); // Sets the global idle callback break; // Escapes from the program by pressing 'Esc' case 27: exit(0); // Terminates the program break; default: break; // Function that creates a menu used from a mouse void mousemenu(int value) if(value == 1) glutidlefunc(spinscene); if(value == 2) glutidlefunc(null); if(value == 3) exit(0); // Function that prints a menu on the command window void menu(void) printf("------------ OPTIONS -------------\n"); printf("press 1 to start rotation\n"); printf("press 2 to start rotation\n"); printf("press Esc to terminate the program\n"); printf("----------------------------------\n"); 15

// Main function int main(int argc, char **argv) menu(); // Initialise GLUT library glutinit(&argc, argv); // Initialise the display mode glutinitdisplaymode(glut_double GLUT_RGB GLUT_DEPTH); //glutinitdisplaymode (GLUT_SINGLE GLUT_RGB GLUT_DEPTH); // Initialise the window position glutinitwindowposition(300, 300); // Initialise the window size glutinitwindowsize(500, 500); // Creates a window on the screen glutcreatewindow ("OpenGL Tutorial 4"); // Create a widget menu glutcreatemenu(mousemenu); // Add a menu entry glutaddmenuentry("start Rotation", 1); // Add a menu entry glutaddmenuentry("stop Rotation", 2); // Add a menu entry glutaddmenuentry("quit", 3); // Attach menu to mouse right button glutattachmenu(glut_right_button); // Call the initialise function initialise(); // The display function is called each time there is a display callback glutdisplayfunc(draw); // The reshape function reshapes the scene glutreshapefunc(reshape); 16

// Function that reads input from the keyboard glutkeyboardfunc(keyboard); // Causes the program to enter an event-processing loop glutmainloop(); return 0; Expected Output: Functions Used: void glulookat(gldouble eyex, GLdouble eyey, GLdouble eyez, GLdouble centerx, GLdouble centery, GLdouble centerz, GLdouble upx, GLdouble upy, GLdouble upz) The glulookat function defines a viewing transformation. The parameters eyex, eyey, eyez define the position of the eye point. The centerx, centery, centerz define the position of the reference point. The upx, upy, upz define the direction of the up vector. void gllightfv(glenum light, GLenum pname, const GLfloat *params) Specifies the light-source parameters. The parameters include the light which is an OpenGL defined light. The pname which is a light source parameter for light. The following 17

values are accepted: GL_AMBIENT, GL_DIFFUSE, GL_SPECULAR, GL_POSITION, GL_SPOT_DIRECTION, GL_SPOT_EXPONENT, GL_SPOT_CUTOFF, GL_CONSTANT_ATTENUATION, GL_LINEAR_ATTENUATION, GL_QUADRATIC_ATTENUATION. And finally the params which is a pointer to the value or values to which parameter pname of light source light will be set. void gltranslated(gldouble x, GLdouble y, GLdouble z) This function multiplies the current matrix by a translation matrix. void glenable(glenum cap) Enables OpenGL capabilities. The parameter cap refers to a symbolic constant indicating an OpenGL capability (i.e. GL_LIGHTING, GL_DEPTH_TEST). void gldisable(glenum cap) Disables OpenGL capabilities. void glutsolidsphere(gldouble radious, Glint slices, Glint stacks) Creates polygonal approximations of a sphere, centred at the origin with the specified radius, through stacks lines of latitude and slices lines of longitude. void glutsolidtorus(gldouble inner, GLdouble outer, Glint sides, Glint slices) Function that defines a torus aligned with the z-axis by its inner and outer radius, sides divisions for radial sections, and slices around the torus. void glshademodel(glenum mode) The glshademodel function selects flat or smooth shading. The parameter mode is a symbolic value representing a shading technique. Accepted values are GL_FLAT and GL_SMOOTH. The default is GL_SMOOTH. void gluperspective(gldouble fovy,gldouble aspect, GLdouble znear, GLdouble zfar) The gluperspective function sets up a perspective projection matrix. The parameters include the fovy (the field of view angle, in degrees, in the y-direction), the aspect (the aspect ratio that determines the field of view in the x-direction), the znear (the distance from the viewer to the near clipping plane) and the zfar (the distance from the viewer to the far clipping plane). void glutcreatemenu(void (*f) (int value)) Command that creates a top-level menu that uses the callback f(), which is passed an integer value for the menu entry. A unique identifier is returned for the menu created. void glutaddmenuentry(char *name, int value) Function that adds an entry with name displayed to the current menu. The value is returned to the menu callback. void glutattachmenu(int button) This command attaches the current menu to a specified mouse button. This could be either GLUT_RIGHT_BUTTON, GLUT_MIDDLE_BUTTON, or GLUT_LEFT_BUTTON. Task: Add another light and add more user interaction 18

Add another light in the scene and set the color to yellow again. Place the new light in a different position and perform another rotation using different keys. Finally add the interactions to the widget menu. 19