The User Interface Lecture 2 Mon, Aug 27, 2007.

Slides:



Advertisements
Similar presentations
OpenGL Open a Win32 Console Application in Microsoft Visual C++.
Advertisements

OpenGL CMSC340 3D Character Design & Animation. What is OpenGL? A low-level graphics library specification designed for use with the C and C++ provides…
1 Computer Graphics Chapter 2 Input Devices. RM[2]-2 Input Devices Logical Input Devices  Categorized based on functional characteristics.  Each device.
TOPIC 3 INTRODUCTION TO OPENGL CGMB214: Introduction to Computer Graphics.
CS 4731 Lecture 2: Intro to 2D, 3D, OpenGL and GLUT (Part I) Emmanuel Agu.
OpenGL Basics Donghui Han. Assignment Grading Visual Studio Glut Files of four types needed: – Source code:.cpp,.h – Executable file:.exe (build in release.
Computer Graphics (Fall 2008) COMS 4160, Lecture 9: OpenGL 1
1 3D modelling with OpenGL Brian Farrimond Robina Hetherington.
OpenGL (I). What is OpenGL (OGL)? OGL is a 3D graphics & modeling library Can also use it to draw 2D objects.
InteractionHofstra University1 Graphics Programming Input and Interaction.
Computer Graphics (Fall 2005) COMS 4160, Lecture 10: OpenGL 1
31/1/2006Based on: Angel (4th Edition) & Akeine-Möller & Haines (2nd Edition)1 CSC345: Advanced Graphics & Virtual Environments Lecture 3: Introduction.
1 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 GLUT Callback Functions.
Based on slides created by Edward Angel
CSC461 Lecture 9: GLUT Callbacks Objectives Introduce double buffering for smooth animations Programming event input with GLUT.
Write a Simple Program with OpenGL & GLUT. Books and Web Books OpenGL Programming Guide (Red-book) OpenGL Reference Manual (Blue-book) OpenGL Super Bible.
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.
Events and Coordinates Lecture 5 Fri, Sep 5, 2003.
Introduction to OpenGL and GLUT GLUT. What is OpenGL? An application programming interface (API) A (low-level) Graphics rendering API Generate high-quality.
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.
Interaction with Graphics System
University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2010 Tamara Munzner GLUT, Transformations.
Lecture 5: Interaction 1  Principles of Interactive Graphics  CMSCD2012  Dr David England, Room 711,  ex 2271 
Lecture 3 OpenGL.
1 Input and Interaction. 2 Input Devices Physical input devices Keyboard devices and pointing devices Logical input devices.
Computer Graphics I, Fall 2010 Input and Interaction.
Write a Simple Program with OpenGL & GLUT. Books OpenGL Programming Guide (Red-book) OpenGL Reference Manual (Blue-book) OpenGL Super Bible
 “OpenGL (Open Graphics Library) is a standard specification defining a cross- language cross-platform API for writing applications that produce 2D and.
Managing Multiple Windows with OpenGL and GLUT
CS 480/680 Computer Graphics Programming with Open GL Part 7: Input and Interaction Dr. Frederick C Harris, Jr. Fall 2011.
Interactive Computer Graphics CS 418 MP1: Dancing I TA: Zhicheng Yan Sushma S Kini Mary Pietrowicz Slides Taken from: “An Interactive Introduction to OpenGL.
Introduction to OpenGL and GLUT. What’s OpenGL? An Application Programming Interface (API) A low-level graphics programming API – Contains over 250 functions.
1 Input and Interaction. 2 Objectives Introduce the basic input devices ­Physical Devices ­Logical Devices ­Input Modes Event-driven input Introduce double.
More on GLUT Programming Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Monday, September 15, 2003.
Computer Graphics I, Fall 2010 Working with Callbacks.
Pop-Up Menus Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Friday, September 26, 2003.
Mouse events, Advanced camera control George Georgiev Telerik Corporation
GLUT functions glutInit allows application to get command line arguments and initializes system gluInitDisplayMode requests properties for the window.
12/22/ :38 1 Comp 175C - Computer Graphics Dan Hebert Computer Graphics Comp 175 Chapter 3 Instructor: Dan Hebert.
1 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 Working with Callbacks.
CSC Graphics Programming Budditha Hettige Department of Statistics and Computer Science.
INTRODUCTION TO OPENGL
Basic Program with OpenGL and GLUT
Review GLUT Callback Functions
Working with Callbacks
Introduction to the Mouse
Computer Graphics Lecture 33
CS5500 Computer Graphics March 2, 2006.
OpenGL Event Driven Programming
CSC461 Lecture 8: Input Devices
Advanced Menuing, Introduction to Picking
OpenGL Basics OpenGL’s primary function – Rendering
Working with Callbacks
Rendering Pipeline, OpenGL/GLUT
Chapter 3 arrays of vertices vertex arrays display lists drawing text
Rendering Pipeline Week 2, Mon Jan 11
Isaac Gang University of Mary Hardin-Baylor
Fundamentals of Computer Graphics Part 3
Input and Interaction Ed Angel
University of New Mexico
Input and Interaction Ed Angel
Chapter 3 arrays of vertices vertex arrays display lists drawing text
Managing Multiple Windows with OpenGL and GLUT
OpenGL, GLUT, Transformations I Week 2, Wed Jan 16
Input and Interaction Ed Angel Professor Emeritus of Computer Science,
Chapter 3 arrays of vertices vertex arrays display lists drawing text
Preview of 3-D Graphics Glenn G. Chappell
Presentation transcript:

The User Interface Lecture 2 Mon, Aug 27, 2007

Callback Functions A callback function is a programmer-specified function that the library will call whenever necessary. Each callback function must be registered with glut. glut provides over 20 callbacks.

Callback Functions The glut library contains functions with names of the form glutNameFunc(name), where Name stands for some form of windows interaction (mouse, keyboard, etc.). The parameter is a user-defined function name(). For example, glutMouseFunc(mouse);

Callback Functions Then when the action is initiated by the user (mouse click, keystroke, etc.), the function name() is called to handle it.

OpenGL Callback Functions glutDisplayFunc(display); Called whenever the scene needs to be redrawn. Activated by calls to glutPostRedisplay(). glutReshapeFunc(reshape); Called whenever the window is resized. Activated by resizing the window.

OpenGL Callback Functions glutKeyboardFunc(keyboard) Called whenever an ASCII key is pressed. Activated by keystrokes (down only) of an ASCII key (letters, digits, punctuation). glutSpecialFunc(special) Called whenever a non-ASCII key is pressed. Activated by keystrokes (down only) of a non-ASCII key (function keys, arrow keys, etc.).

OpenGL Callback Functions glutMouseFunc(mouse) Called whenever the mouse is clicked (up or down). Activated by mouse clicks. Left or right button, button up or button down.

OpenGL Callback Functions glutMotionFunc(motion) Called whenever the mouse is moved while the mouse button is down. glutPassiveMotionFunc(passiveMotion) Called whenever the mouse is moved while the mouse button is up.

OpenGL Callback Functions glutIdleFunc(idle) Called whenever nothing else is happening. See the online reference manual.

OpenGL Callback Functions Typically, the callback functions end with a call to glutPostRedisplay() so that the scene will be redrawn. To force the scene to be redrawn continuously, include glutPostRedisplay() in the display() function. If the idle() function is used, and it calls glutPostRedisplay(), then this is not necessary.

The Main Loop Typically main() ends by calling glutMainLoop() This function runs “forever,” or until we exit the program. It calls the callback functions as necessary. It handles all drawing commands as they are generated.

The Main Loop main() display() Process keyboard and mouse events reshape() keyboard() special() mouse() idle() motion() passiveMotion()

The Main Loop main() display() Process keyboard and mouse events reshape() keyboard() special() mouse() idle() motion() passiveMotion()

The Main Loop main() display() Process keyboard and mouse events glutMainLoop() display() Process keyboard and mouse events reshape() keyboard() special() mouse() idle() motion() passiveMotion()

The Main Loop main() display() Process keyboard and mouse events reshape() keyboard() special() mouse() idle() motion() passiveMotion()

The Main Loop main() display() Process keyboard and mouse events glutPostRedisplay() display() Process keyboard and mouse events reshape() keyboard() special() mouse() idle() motion() passiveMotion()

The Main Loop main() display() Process keyboard and mouse events Window resize reshape() keyboard() special() mouse() idle() motion() passiveMotion()

The Main Loop main() display() Process keyboard and mouse events reshape() ASCII keystroke keyboard() special() mouse() idle() motion() passiveMotion()

The Main Loop main() display() Process keyboard and mouse events reshape() keyboard() Arrow/F key special() mouse() idle() motion() passiveMotion()

The Main Loop main() display() Process keyboard and mouse events reshape() keyboard() special() Mouse down/up mouse() idle() motion() passiveMotion()

The Main Loop main() display() Process keyboard and mouse events reshape() keyboard() special() mouse() idle() Mouse-down movement motion() passiveMotion()

The Main Loop main() display() Process keyboard and mouse events reshape() keyboard() Mouse-up movement special() mouse() idle() motion() passiveMotion()

The Main Loop main() display() Process keyboard and mouse events reshape() keyboard() special() No activity mouse() idle() motion() passiveMotion()

Example: Callback Functions Read Run

Other Initializations void init() { glClearColor(0.8, 0.8, 0.8, 0.0); // Light gray glEnable(GL_DEPTH_TEST); // Enable depth testing glDepthFunc(GL_LEQUAL); // Type of depth testing glClearDepth(1.0); // Depth buffer setup printInstructions(); : return; }

The keyboard() Function The prototype of the keyboard() function is void keyboard(unsigned char key, int x, int y); key – ASCII value of the key pressed. x, y – x and y window coordinates of the mouse. Caution – y is measured from the top down.

The keyboard() Function Typical structure of the keyboard() function: void keyboard(unsigned char key, int x, int y) { y = screenHeight – y; // y measured from bottom up switch (key) case '+': case '=': // Code to zoom in break; : case ESC: exit(0); } glPostRedisplay(); return;

void mouse(int button, int state, int x, int y); The mouse() Function The prototype of the mouse() function is void mouse(int button, int state, int x, int y); button – GLUT_LEFT_BUTTON or GLUT_RIGHT_BUTTON. state – GLUT_UP or GLUT_DOWN. x, y – x and y window coordinates of mouse. Caution – y is measured from the top down.

The mouse() Function Typical structure of the mouse() function: void mouse(int button, int state, int x, int y) { y = screenHeight – y; // y measured from bottom up if (button == GLUT_LEFT_BUTTON && state == GLUT_DOWN) // Perform left-button-down action } else : // Other actions glPostRedisplay(); return;

Callback Functions in Action Read Run