More on GLUT Programming Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Monday, September 15, 2003.

Slides:



Advertisements
Similar presentations
Chapter 3: Editing and Debugging SAS Programs. Some useful tips of using Program Editor Add line number: In the Command Box, type num, enter. Save SAS.
Advertisements

Data: Programming Design and Modularization IS 101Y/CMSC 101 Computational Thinking and Design Thursday, September 26, 2013 Marie desJardins University.
1 3D modelling with OpenGL Brian Farrimond Robina Hetherington.
Copyright © 2008 Pearson Addison-Wesley. All rights reserved. Chapter 12 Separate Compilation Namespaces Simple Make Files (Ignore all class references.
ICM Week 2. Structure - statements and blocks of code Any single statement ends with semicolon ; When we want to bunch a few statements together we use.
Logo Lesson 5 TBE Fall 2004 Farah Fisher. Prerequisites  Given a shape, use basic Logo commands and/or a procedure to draw the shape, with and.
Based on slides created by Edward Angel
CSC461 Lecture 9: GLUT Callbacks Objectives Introduce double buffering for smooth animations Programming event input with GLUT.
CS 480/680 Computer Graphics Programming with Open GL Part 8: Working with Callbacks Dr. Frederick C Harris, Jr. Fall 2011.
Programming with OpenGL and GLUT
Using Graphics Libraries Lecture 3 Mon, Sep 1, 2003.
Mouse-Based Viewing & Navigation Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Monday, November 3, 2003.
Data Objects (revisited) Recall that values are stored in data objects, and that each data object holds one value of a particular type. Data objects may.
Basic OpenGL Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Wednesday, September 10, 2003.
Polygon Lists & 3-D File Formats Glenn G. Chappell U. of Alaska Fairbanks CS 481/681 Lecture Notes Monday, February 18, 2002.
Events and Coordinates Lecture 5 Fri, Sep 5, 2003.
1 Working with Callbacks Yuanfeng Zhou Shandong University.
WORKING WITH CALLBACKS Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico Angel: Interactive.
Lecture 5: Interaction 1  Principles of Interactive Graphics  CMSCD2012  Dr David England, Room 711,  ex 2271 
Data Structures for Scenes, The Basics of Scene Graphs Glenn G. Chappell U. of Alaska Fairbanks CS 481/681 Lecture Notes Friday,
1Computer Graphics Input and Interaction Lecture 8 John Shearer Culture Lab – space 2
Lecture 3 OpenGL.
Computer Graphics I, Fall 2010 Input and Interaction.
CS 450: COMPUTER GRAPHICS PORTRAIT OF AN OPENGL PROGRAM SPRING 2015 DR. MICHAEL J. REALE.
KeyListener and Keyboard Events Another type of listener listens for keyboard entry – the KeyListener which generates KeyEvents –to implement KeyListener,
Homogeneous Form, Introduction to 3-D Graphics Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Monday, October 20,
Shadows via Projection Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Wednesday, November 5, 2003.
EVENT-DRIVEN PROGRAMMING. โปรแกรมและอุปกรณ์ส่วนมากที่ใช้ใน ชีวิตประจำวัน จะตอบสนองกับเหตุการณ์ที่ เกิดขึ้น ตัวอย่างของเหตุการณ์ อาทิ การเคลื่อน หรือ คลิกเมาส์
CS 480/680 Computer Graphics Programming with Open GL Part 7: Input and Interaction Dr. Frederick C Harris, Jr. Fall 2011.
1 Κατανεμημένες Διαδικτυακές Εφαρμογές Πολυμέσων Γιάννης Πετράκης.
Working with the VB IDE. Running a Program u Clicking the”start” tool begins the program u The “break” tool pauses a program in mid-execution u The “end”
VR & TRANSF Glenn G. Chappell U. of Alaska Fairbanks CS 481/681 Lecture Notes Monday, February 23, 2004.
More on Drawable Objects, Hierarchical Objects Glenn G. Chappell U. of Alaska Fairbanks CS 481/681 Lecture Notes Wednesday, January.
Interactive Computer Graphics CS 418 MP1: Dancing I TA: Zhicheng Yan Sushma S Kini Mary Pietrowicz Slides Taken from: “An Interactive Introduction to OpenGL.
CMP-MX21: Lecture 4 Selections Steve Hordley. Overview 1. The if-else selection in JAVA 2. More useful JAVA operators 4. Other selection constructs in.
More on Environment Mapping Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Wednesday, December 10, 2003.
Build-A-Button Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Wednesday, October 8, 2003.
Slide 1 Project 1 Task 2 T&N3311 PJ1 Information & Communications Technology HD in Telecommunications and Networking Task 2 Briefing The Design of a Computer.
Program 2 due 02/01  Be sure to document your program  program level doc  your name  what the program does  each function  describe the arguments.
1 Input and Interaction. 2 Objectives Introduce the basic input devices ­Physical Devices ­Logical Devices ­Input Modes Event-driven input Introduce double.
Computer Graphics: Programming, Problem Solving, and Visual Communication Steve Cunningham California State University Stanislaus and Grinnell College.
Computer Graphics I, Fall 2010 Working with Callbacks.
Advanced Viewing Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Friday, October 31, 2003.
University of New Mexico
Pop-Up Menus Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Friday, September 26, 2003.
CSD 340 (Blum)1 Starting JavaScript Homage to the Homage to the Square.
Programming Fundamentals. Overview of Previous Lecture Phases of C++ Environment Program statement Vs Preprocessor directive Whitespaces Comments.
GLUT functions glutInit allows application to get command line arguments and initializes system gluInitDisplayMode requests properties for the window.
SCRIPT PROGRAMMING WITH FLASH Introductory Level 1.
Programming Fundamentals. Topics to be covered Today Recursion Inline Functions Scope and Storage Class A simple class Constructor Destructor.
1 Project 2: Using Variables and Expressions. 222 Project 2 Overview For this project you will work with three programs Circle Paint Ideal_Weight What.
Session 7 Introduction to Inheritance. Accumulator Example a simple calculator app classes needed: –AdderApp - contains main –AddingFrame - GUI –CloseableFrame.
Data: Programming Design and Modularization IS 101Y/CMSC 101 Computational Thinking and Design Thursday, September 25, 2014 Carolyn Seaman Susan Martin.
1 Scope Lifetime Functions (the Sequel) Chapter 8.
Searching CSE 103 Lecture 20 Wednesday, October 16, 2002 prepared by Doug Hogan.
OpenGL in FLTK  .
Introduction to Input/Interaction Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Friday, September 19, 2003.
Selection Mode, Introduction to Widgets Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Monday, October 6, 2003.
Introduction to Exceptions in Java CS201, SW Development Methods.
1 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 Working with Callbacks.
PYGAME.
Introduction to the Mouse
CSC461 Lecture 8: Input Devices
The User Interface Lecture 2 Mon, Aug 27, 2007.
Advanced Menuing, Introduction to Picking
Display Lists & Text Glenn G. Chappell
More on Widgets, Misc. Topics
Input and Interaction Ed Angel
Input and Interaction Ed Angel
Preview of 3-D Graphics Glenn G. Chappell
Presentation transcript:

More on GLUT Programming Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Monday, September 15, 2003

15 Sep 2003CS 3812 Review: Introduction to GLUT [1/2] GLUT is a package, separate from OpenGL, that we use in this class to: Allow OS-independent CG programs. Simplify certain OpenGL operations. Introduce simple event-driven GUI programming. GLUT is not intended for professional quality, production code. However, the concepts we cover when learning GLUT (event-driven programming ideas) are relevant to programming with any GUI package.

15 Sep 2003CS 3813 Review: Introduction to GLUT [2/2] GLUT programs are organized differently from most programs you have seen before. GLUT handles overall flow of control. You write callback functions to handle events: Display needed. Keypress. Idle (nothing interesting has happened). Etc … When an event happens, GLUT calls the appropriate function. Thus, it is important that your function properly handles the event it is to be called for.

15 Sep 2003CS 3814 Review: intro2d.cpp We discussed intro2d.cpp, a simple OpenGL/GLUT program. Five functions: main, init, display, keyboard, idle. Functions main & init do initialization. Function display does drawing … … and only drawing, and nothing else does drawing. Remember THE RULES. Today, we look at keyboard & idle.

15 Sep 2003CS 3815 intro2d.cpp : Function keyboard void keyboard(unsigned char key, int x, int y) { switch (key) { case ESCKEY: // ESC: Quit exit(0); break; } GLUT calls the keyboard function whenever an ASCII keypress happens. Use the GLUT “special” function for non-ASCII (like arrow keys). The ASCII value of the keypress is in key. Mouse position is in x, y. Your keyboard (or special) function will usually be one big switch. Why did I put in the (unnecessary) break ?

15 Sep 2003CS 3816 intro2d.cpp : Function idle // Print OpenGL errors, if there are any (for debugging) if (GLenum err = glGetError()) { cerr << "OpenGL ERROR: " << gluErrorString(err) << endl; } GLUT calls the idle function whenever nothing else needs doing. It is useful for making time-dependent changes to the scene. Here, we check for OpenGL errors, and print a message if there is an error. This is a rather atypical use of the idle function. We will see a more “normal” use of idle in a few minutes.

15 Sep 2003CS 3817 Making a Changing Display: Overview All the programs you have seen so far in this class have had a static display. Now, we look at how to make the display change: Based on keyboard input. Using the keyboard (or special) function. Automatically. Using the idle function. We will add these new features to intro2d.cpp. We’re jumping ahead of the text a bit here.

15 Sep 2003CS 3818 Making a Changing Display: Keyboard Input [1/3] Suppose we wish to have the display change when a key is pressed. Keypress events are handled by the GLUT keyboard function. Actually, keyboard for ASCII keys, special for non-ASCII. So the keyboard function needs to do what is necessary to see that the display is updated. But, the keyboard function is not allowed to call the display function. That’s in THE RULES. Thus, the keyboard function needs to: Make sure that GLUT will call the display function. Make sure that, when the display function is called, it knows to re-draw the window in a different manner.

15 Sep 2003CS 3819 Making a Changing Display: Keyboard Input [2/3] The keyboard function needs to make sure that GLUT will call the display function. The keyboard function needs to post a redisplay event. This is done by calling glutPostRedisplay. Function glutPostRedisplay takes no parameters. The keyboard function needs to make sure that, when the display function is called, it knows to re-draw the window in a different manner. Since the display function takes no parameters, we can only communicate the change to the display function via a global variable.

15 Sep 2003CS Making a Changing Display: Keyboard Input [3/3] Now we put it all together. To add keypress-based display changes to a GLUT program: A global variable is needed to hold the current state of whatever part of the display is to change. Declare the variable. Initialize this variable to an appropriate value somewhere. In its declaration? In the init function? In the display function: Use the value of this variable. Draw whatever should be drawn, according to the current value of the variable. Do not change the variable in the display function. In the keyboard function, when the appropriate key is pressed: Change the value of the variable. Call “ glutPostRedisplay(); ”. Do not call the display function.

15 Sep 2003CS EXAMPLE 1 Modify intro2d.cpp to allow a keypress to change the display. Modified the program so that hitting the space bar toggled the color: red to blue and vice-versa.

15 Sep 2003CS Making a Changing Display: Automatic Changing Suppose we simply want the display to change automatically, regardless of any input. This is what the idle function is for. Recall: GLUT calls the idle function, repeatedly, when no other event is happening. Thus, this is handled just like keyboard input, except: We modify the idle function instead of the keyboard function. We do not need to worry about the ASCII value of a key.

15 Sep 2003CS EXAMPLE 2 Modify intro2d.cpp to change the display automatically. Modified the program so that the square moves to the right. Further modified it so that the square bounces off the sides of the window.