31/1/2006Based on: Angel (4th Edition) & Akeine-Möller & Haines (2nd Edition)1 CSC345: Advanced Graphics & Virtual Environments Lecture 3: Introduction.

Slides:



Advertisements
Similar presentations
CS 450: COMPUTER GRAPHICS GLUT INPUT FUNCTIONS SPRING 2015 DR. MICHAEL J. REALE.
Advertisements

Chapter 3: Input and Interaction Instructor: Shih-Shinh Huang 1.
CSC461 Lecture 10: Widgets and Picking Objectives Introduce menus in GLUT Picking –Select objects from the display –Three methods Put things together.
OpenGL (I). What is OpenGL (OGL)? OGL is a 3D graphics & modeling library Can also use it to draw 2D objects.
CSC 461: Lecture 51 CSC461 Lecture 5: Simple OpenGL Program Objectives: Discuss a simple program Discuss a simple program Introduce the OpenGL program.
InteractionHofstra University1 Graphics Programming Input and Interaction.
30/1/2006Based on: Angel (4th Edition) & Akeine-Möller & Haines (2nd Edition)1 CSC345: Advanced Graphics & Virtual Environments Lecture 1: Introduction.
InteractionHofstra University1 Graphics Programming Input and Interaction.
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.
CS 480/680 Computer Graphics Programming with Open GL Part 8: Working with Callbacks Dr. Frederick C Harris, Jr. Fall 2011.
Demetriou/Loizidou – ACSC330 – Chapter 3 Input and Interaction Dr. Giorgos A. Demetriou Dr. Stephania Loizidou Himona Computer Science Frederick Institute.
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.
COMPUTER GRAPHICS Hochiminh city University of Technology Faculty of Computer Science and Engineering CHAPTER 03: Input & Interaction.
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Chapter 3: Input and Interaction.
More on Drawing in OpenGL: Examples CSC 2141 Introduction to Computer Graphics.
1 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 Programming with OpenGL Part 1: Background.
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Programming with OpenGL Part 3: Three Dimensions Ed Angel Professor of Computer Science,
WORKING WITH CALLBACKS Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico Angel: Interactive.
Fundamentals of Computer Graphics Part 3 prof.ing.Václav Skala, CSc. University of West Bohemia Plzeň, Czech Republic ©2002 Prepared with Angel,E.: Interactive.
Interaction with Graphics System
CS 450: COMPUTER GRAPHICS REVIEW: GLUT INPUT FUNCTIONS SPRING 2015 DR. MICHAEL J. REALE.
Input and Interaction Chapter 3. CS 480/680 2Chapter 3 -- Input and Interaction Introduction: Introduction: We now turn to the development of interactive.
1Computer Graphics Input and Interaction Lecture 8 John Shearer Culture Lab – space 2
CAP 4703 Computer Graphic Methods Prof. Roy Levow Lecture 3.
CSE 470: Computer Graphics. 10/15/ Defining a Vertex A 2D vertex: glVertex2f(GLfloat x, GLfloat y); 2D vertexfloating pointopenGL parameter type.
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.
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.
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 I, Fall 2010 Working with Callbacks.
Input and Interaction Yuanfeng Zhou Shandong University Software College 1.
1 Graphics CSCI 343, Fall 2015 Lecture 6 Viewing, Animation, User Interface.
1 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 OpenGL Transformations.
University of New Mexico
Input and Interaction Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico.
Pop-Up Menus Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Friday, September 26, 2003.
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 4E © Addison-Wesley 2005 Input and Interaction Ed Angel Professor of Computer Science, Electrical and Computer Engineering,
31/1/2006Based on: Angel (4th Edition) & Akeine-Möller & Haines (2nd Edition)1 CSC345: Advanced Graphics & Virtual Environments Lecture 2: Introduction.
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
C O M P U T E R G R A P H I C S Guoying Zhao 1 / 86 C O M P U T E R G R A P H I C S Guoying Zhao 1 / 86 Computer Graphics Programming with OpenGL II.
Review GLUT Callback Functions
Programming with OpenGL Part 0: 3D API
Working with Callbacks
Introduction to the Mouse
Input and Interaction Ed Angel
Computer Graphics Lecture 33
CS5500 Computer Graphics March 2, 2006.
CSC461 Lecture 8: Input Devices
The User Interface Lecture 2 Mon, Aug 27, 2007.
גרפיקה ממוחשבת: מבוא ל-OpenGL
Input and Interactions
Working with Callbacks
Computer Graphics, Lee Byung-Gook, Dongseo Univ.
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
Input and Interaction Ed Angel Professor Emeritus of Computer Science,
Presentation transcript:

31/1/2006Based on: Angel (4th Edition) & Akeine-Möller & Haines (2nd Edition)1 CSC345: Advanced Graphics & Virtual Environments Lecture 3: Introduction to C & OpenGL (3) Patrick Olivier 2 nd floor in the Devonshire Building

6/2/2006Based on: Angel (4th Edition) & Akeine-Möller & Haines (2nd Edition)2 Graphical input devices mouse trackball light pen data tablet joy stick space ball

6/2/2006Based on: Angel (4th Edition) & Akeine-Möller & Haines (2nd Edition)3 Callbacks  Programming interface for event-driven input  Define a callback function for each type of event the graphics system recognizes  Callback function executed when event occurs  GLUT examples: glutDisplayFunc / glutMouseFunc glutReshapeFunc / glutKeyboardFunc glutIdleFunc / glutMotionFunc glutPassiveMotionFunc

6/2/2006Based on: Angel (4th Edition) & Akeine-Möller & Haines (2nd Edition)4 Animating a display  When we redraw the display through the display callback, we usually start by clearing the window glClear() …then draw the altered display  Problem: the drawing of information in the frame buffer is decoupled from the display of its contents  Hence we can see partially drawn display See the program single_double.c for an example with a rotating cube  Need to “double buffer”…

6/2/2006Based on: Angel (4th Edition) & Akeine-Möller & Haines (2nd Edition)5 Double buffering  Instead of one color buffer, we use two Front Buffer: displayed but not written to Back Buffer: written to but not displayed  Program requests a double buffer in main.c glutInitDisplayMode(GL_RGB | GL_DOUBLE) …at end of the display callback buffers are swapped void mydisplay() { glClear(GL_COLOR_BUFFER_BIT|….) /* draw graphics here */ glutSwapBuffers() }

6/2/2006Based on: Angel (4th Edition) & Akeine-Möller & Haines (2nd Edition)6 Using global variables…  The form of all GLUT callbacks is fixed: void mydisplay() void mymouse(GLint button, GLint state, GLint x, GLint y)  It’s not nice but we must use global variables to pass information to callbacks float t; /* global variable*/ void mydisplay() { /* draw something that depends on t }

6/2/2006Based on: Angel (4th Edition) & Akeine-Möller & Haines (2nd Edition)7 Mouse callback glutMouseFunc(mymouse ) void mymouse(GLint button, GLint state, GLint x, GLint y )  GLUT_LEFT_BUTTON / GLUT_MIDDLE_BUTTON / GLUT_RIGHT_BUTTON that caused event  state of that button ( GLUT_UP / GLUT_DOWN )  position in window  example: to terminate a program: void mouse(int btn, int state, int x, int y) { if(btn==GLUT_RIGHT_BUTTON && state==GLUT_DOWN) exit(0);}

6/2/2006Based on: Angel (4th Edition) & Akeine-Möller & Haines (2nd Edition)8 Coordinates and window size  Position in the screen window is usually measured in pixels with the origin at the top-left corner (refresh done top to bottom)  OpenGL world coordinate system origin at the bottom left – invert y coordinate returned by callback by height of window: y = h – y;  To invert the y position we need the window height: Height can change during program execution Track with a global variable New height returned to reshape callback (next few slides) Can also use query functions:  glGetIntv  glGetFloatv …to obtain any value that is part of the state

6/2/2006Based on: Angel (4th Edition) & Akeine-Möller & Haines (2nd Edition)9 Example: mouse callback void mymouse(int btn, int state, int x, int y) { if(btn==GLUT_RIGHT_BUTTON && state==GLUT_DOWN) exit(0); if(btn==GLUT_LEFT_BUTTON && state==GLUT_DOWN) drawSquare(x, y); } void drawSquare(int x, int y) { y=w-y; /* invert y position */ glColor3ub( (char) rand()%256, (char) rand )%256, (char) rand()%256); /* a random color */ glBegin(GL_POLYGON); glVertex2f(x+size, y+size); glVertex2f(x-size, y+size); glVertex2f(x-size, y-size); glVertex2f(x+size, y-size); glEnd(); }

6/2/2006Based on: Angel (4th Edition) & Akeine-Möller & Haines (2nd Edition)10 Using the motion callback  The program so far only draws a square on the the “down click” event of the left mouse button.draws a square  We can draw squares (or anything else) continuously as long as a mouse button is depressed by using the motion callbackdraw squares glutMotionFunc(drawSquare)  We can draw squares without depressing a button using the passive motion callbackdraw squares glutPassiveMotionFunc(drawSquare)

6/2/2006Based on: Angel (4th Edition) & Akeine-Möller & Haines (2nd Edition)11 Keyboard input  ASCII code of key depressed and mouse location glutKeyboardFunc(mykey) void mykey(unsigned char key, int x, int y)  GLUT defines the special keys in glut.h F1: GLUT_KEY_F1 / Up arrow: GLUT_KEY_UP if(key == ‘GLUT_KEY_F1’ ……  Can also check of one of the modifiers: GLUT_ACTIVE_SHIFT/GLUT_ACTIVE_CTRL/GLUT_ACTIVE_ALT …is depressed using glutGetModifiers() Can emulate three-button mouse with one- or two-button mice

6/2/2006Based on: Angel (4th Edition) & Akeine-Möller & Haines (2nd Edition)12 Reshaping the window  Pull the corner of the window – what happens?what happens  Must redraw from application  Two possibilities Display part of world Force whole world to fit new window (aspect ratio)

6/2/2006Based on: Angel (4th Edition) & Akeine-Möller & Haines (2nd Edition)13 The reshape callback glutReshapeFunc(myreshape) void myreshape( int w, int h)  Returns width and height of new window (in pixels)  A redisplay is posted automatically at end of execution of the callback  GLUT has a default reshape callback but you probably want to define your own  The reshape callback is good place to put viewing functions as it’s invoked when window is first opened

6/2/2006Based on: Angel (4th Edition) & Akeine-Möller & Haines (2nd Edition)14 Example reshape functionreshape function void myreshape(int w, int h) { glViewport(0, 0, w, h); glMatrixMode(GL_PROJECTION); /* switch matrix mode */ glLoadIdentity(); if (w <= h) gluOrtho2D( -2.0, 2.0, -2.0 * (GLfloat) h / (GLfloat) w, 2.0 * (GLfloat) h / (GLfloat) w); else gluOrtho2D( -2.0 * (GLfloat) w / (GLfloat) h, 2.0 * (GLfloat) w / (GLfloat) h, -2.0, 2.0); glMatrixMode(GL_MODELVIEW); /* return modelview mode */ }

6/2/2006Based on: Angel (4th Edition) & Akeine-Möller & Haines (2nd Edition)15 GLUT and widgets  Most window systems provide a toolkit or library of functions for building user interfaces using special types of windows called widgets  Widget sets include tools such as: Menus / Slidebars / Dials /Input boxes  But toolkits tend to be platform dependent  GLUT provides a few widgets including menus GLUT supports pop-up menus A menu can have submenus

6/2/2006Based on: Angel (4th Edition) & Akeine-Möller & Haines (2nd Edition)16 Defining a simple menu…  In main.c do the following: Define entries for the menu Define action for each menu item (if selected) Attach menu to a mouse button  Menu callback: Menu callback menu_id = glutCreateMenu(mymenu); glutAddMenuEntry(“Clear Screen”, 1); glutAddMenuEntry(“Exit”, 2); glutAttachMenu(GLUT_RIGHT_BUTTON); void mymenu(int id) {if(id == 1) { glClear(); glFlush();} if(id == 2) exit(0); }

6/2/2006Based on: Angel (4th Edition) & Akeine-Möller & Haines (2nd Edition)17 Other GLUT functions…  Windows: Dynamic Windows (in-execution create and destroy) Subwindows Multiple Windows  Changing callbacks during execution  Timers  Portable fonts glutBitmapCharacter glutStrokeCharacter