CAP 4703 Computer Graphic Methods Prof. Roy Levow Lecture 3.

Slides:



Advertisements
Similar presentations
OpenGL CMSC340 3D Character Design & Animation. What is OpenGL? A low-level graphics library specification designed for use with the C and C++ provides…
Advertisements

Better Interactive Programs
1 Computer Graphics Chapter 2 Input Devices. RM[2]-2 Input Devices Logical Input Devices  Categorized based on functional characteristics.  Each device.
Computer Graphics using OpenGL, 3 rd Edition F. S. Hill, Jr. and S. Kelley Chapter 3 Additional Drawing Tools Ureerat Suksawatchon Department of Computer.
Informationsteknologi Monday, November 12, 2007Computer Graphics - Class 71 Today’s class Viewing transformation Menus Mandelbrot set and pixel drawing.
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.
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Better Interactive Programs Ed Angel Professor of Computer Science, Electrical and Computer.
InteractionHofstra University1 Graphics Programming Input and Interaction.
31/1/2006Based on: Angel (4th Edition) & Akeine-Möller & Haines (2nd Edition)1 CSC345: Advanced Graphics & Virtual Environments Lecture 3: 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.
Informationsteknologi Tuesday, November 6, 2007Computer Graphics - Class 41 Today’s class Input and interaction.
CS 480/680 Computer Graphics Programming with Open GL Part 8: Working with Callbacks Dr. Frederick C Harris, Jr. Fall 2011.
Using Graphics Libraries Lecture 3 Mon, Sep 1, 2003.
19/4/ :32 Graphics II Syllabus Selection and Picking Session 1.
CSC461 Lecture 11: Interactive Programs Contents and Objectives Picking Writing modes – XOR/Copy Rubberbanding Display list.
1 Working with Callbacks Yuanfeng Zhou Shandong University.
More on Drawing in OpenGL: Examples CSC 2141 Introduction to Computer Graphics.
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
Lecture 5: Interaction 1  Principles of Interactive Graphics  CMSCD2012  Dr David England, Room 711,  ex 2271 
School of Computer Science University of Seoul. 1. Interaction 2. Input Devices 3. Clients and Servers 4. Display Lists 5. Programming Event-Driven Input.
Korea University Korea University Computer Graphics Laboratory Computer Graphics Laboratory Jung Lee, Chapter 13.
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
Input and Interaction Lecture No. 4.
CSE 470: Computer Graphics. 10/15/ Defining a Vertex A 2D vertex: glVertex2f(GLfloat x, GLfloat y); 2D vertexfloating pointopenGL parameter type.
FLTK Help Session By Richard Yu Gu CS 638 -Graphics Fall, 1999.
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.
Ch 2 Graphics Programming page 1 CSC 367 Coordinate Systems (2.1.2) Device coordinates, or screen coordinates (pixels) put limitations on programmers and.
Computing & Information Sciences Kansas State University Lecture 20 of 42CIS 636/736: (Introduction to) Computer Graphics Lecture 21 of 42 William H. Hsu.
CS 480/680 Computer Graphics Programming with Open GL Part 7: Input and Interaction Dr. Frederick C Harris, Jr. Fall 2011.
1 Better Interactive Programs. 2 Objectives Learn to build more sophisticated interactive programs using ­Picking Select objects from the display Three.
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.
1 Graphics CSCI 343, Fall 2015 Lecture 6 Viewing, Animation, User Interface.
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.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
Lecture 7 Midterm Review. OpenGL Libraries gl: Basic OpenGL library, e.g. primitives. glu: OpenGL Utility library, a set of functions to create texture.
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,
Introduction to Graphics Programming. Graphics API.
1 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 Working with Callbacks.
CSC Graphics Programming Budditha Hettige Department of Statistics and Computer Science.
Working with Callbacks
Introduction to the Mouse
Better Interactive Programs
Computer Graphics Lecture 33
CSC461 Lecture 8: Input Devices
Introduction to Computer Graphics with WebGL
Advanced Menuing, Introduction to Picking
Input and Interaction Chapter 3.
Working with Callbacks
Better Interactive Programs
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:

CAP 4703 Computer Graphic Methods Prof. Roy Levow Lecture 3

Input and Interaction  User interaction is an important aspect of many graphic applications  Best supported through a standard API –Programmer avoids nasty implementaiton details  GLUT provides support for OpenGL

Input Devices  API supports logical devices –Defined by capabilities rather than physical design  Different physical devices may provide same capabilities –Mouse, Trackball, possibly Light Pen

Types of Input Devices  Pointing device –Mouse, Trackball –Data tablet reports position of stylus on tablet surfacd –Light pen reports position of pen on screen –Reports position in image  Keyboard device –Character stream

Types of Input Devices (cont)  Joystick –Reports x-y displacement –Usually treated as direction vector  Space ball –Fixed ball on stick –Senses x, y, x pressure as well as 3-axis rotational pressure

Logical Input Devices  String device –Provides character strings as input  Locator Device –Provides position in world coordinates  Pick device –Returns a reference to an object –Usually implemented with a locator

Logical Input Devices (cont)  Choice device –Selection from a discrete number of objects –Usually impemented with a window widget: menu, button, etc.  Dial device –Provides digitized analog input  Stroke device –Returns array of locations –Often the track of a locator device

Measure and Trigger  Measure of a device is the data it provides to the program  Trigger is the action that causes the data to be sent

Input Modes  Request mode –Program requests data from device –Requires trigger but input may not be accepted by program until a later time of the programmer’s choice  Sample mode –Input is immediate –No trigger is needed

Input Modes (cont)  Event mode –Supports asynchronous interaction –Events are queued for event handler

Clients and Servers  Servers perform tasks for clients –Client requests –Server responds  A windowed system is a server –Provides display and input services to a program using the display

Display Lists  Display list or display file –Instructions to display processor to generate image –Stored in memory  Immediate mode –Display server generates image and does not retain commands  Retained mode –Display list is stored on graphics server –Can be used to regenerate images

Definition & Execution of Display Lists  Generated like geometric objects  Bounded by –glNewList(item, GL_COMPILE) –glEndList()  Imaging commands are generated and sent to display server but not displayed  Displayed immedaitely if second parameter is GL_COMPILE_AND_EXECUTE

Executing Display Lists  Display list with –glCallList(item)  Each time list is displayed, current model-view and projection matrices are applied, possibly changing image  Display list is more efficient than regenerating image

Executing Display Lists (cont)  Attributes changed in a display list alter state and remain in effect after list is displayed –This may be a problem  Solution involves using OpenGL attribute and matrix stacks. Push current values before executing list and pop them after

Attribute and Matrix Stacks  Save with glPushAttrib(GL_ALL_ATTRIB_BITS);glPushMatrix();  Restore with glPopAttrib();glPopMatrix(); (skipping sectin 3.4.2)

Event-Driven Programming  Programmer provides functions to be executed when an event occurs  Functions are registered with system and called when event occurs –Implementation may be based on  functions with standard names as in Java  callback functions registered with system as in OpenGL  function has standard prototype to deliver event data

Mouse Event Callback  Function name may be freely chosen  Function prototype void mouse(int button, int state, int x, int y)  Declared constants for button and state like GLUT_LEFT_BUTTONGLUT_DOWN

Mouse Event Callback  Function registration glutMouseFunc(mouse)

Adding Events  Example program from section Example program Example program  main() has two added elements –glutReshapeFunc()  Called when window is reshaped –glutMouseFunc()  Called when mouse button is pressed or released

Program Functions  Mouse –Draw a square at the current location using default parameters when left button is pressed –Exit when middle button is pressed  What about windows?  Init –sets view –clear to black

Program Functions (cont)  drawSquare –Draws fixed size square in random color –Note inversion of y-coordinate  Translates window (mouse) to display  Reshape –A window event  parameters for GLsizei w, h –Resize view port and clipping to preserve aspect for square in window

Keyboard Events  Triggered when key is pressed only  Returns character and x, y mouse location when key is pressed

Display and Idle Callbacks  glutDisplayFunc(display) –Called whenever window needs to be redisplayed  glutPostRedisplay() –Redisplay only once each iteration of GLUT main loop –Avoids unnecessary redisplay

Menus  GLUT supports pop-up menus  Menu creation glutCreateMenu(demo_menu); glutAddMenuEntry("quit",1); glutAddMenuEntry("increase square size", 2); glutAddMenuEntry("decrease square size", 3); glutAttachMenu(GLUT_RIGHT_BUTTON);  Callback function has single int parameter for menu item

GLUT Menus (cont)  Also supports hierarchical menus sub_menu = glutCreateMenu(size_menu); glutAddMenuEntry("Increase square size", 2); glutAddMenuEntry("Decrease square size", 3); glutCreateMenu(top_menu); glutAddMenuEntry("Quit",1); glutAddSubMenu("Resize", sub_menu); glutAttachMenu(GLUT_RIGHT_BUTTON);

Picking  Selection –Adjust clipping region –Add items in region to hit list  Bounding rectangle or extent –Mark region –Add items in marked region to hit list  Use back buffer to display each item in different color –Identify selected items

OpenGL Selection Mode  Selection mode display allows picking –Selected item – hit –Stored on name stack  Key functions –Create array for stack void glSelectBuffer(GLsizei n, void glSelectBuffer(GLsizei n, // eg 512 GLunint *buff) –Initialize name stack void glInitNames()

OpenGL Selection Mode  Push name on stack void glPushName(GLunint name) void glPushName(GLunint name)  Pop top of stack void glPopName()  Replace top name void glLoadName(GLunint name)  Must initialize by pushing a useless value, say 0

Selection Mode  Values on stack at the time an item is drawn determine its name glLoadName(i);drawFigure(i);  If stack contains more than one value, name has multiple components – one for each value on the stack

Pick Matrix  Get current mouse location with glGetIntegerv (GL_VIEWPORT, viewport); // vp is GLint[4] viewport); // vp is GLint[4]  Set selection rectangle with gluPickMatrix(x, y, width, height, viewport) // x,y,w,h are GLdoubles

Example Pick Program ..\openglbk\picksquare.c..\openglbk\picksquare.c

Simple Paint Program  see newpaint.c newpaint.c

Animation  glutIdleFunction() specifies a callback function to use when the main loop is idle  The callback can draw an altered image each time it is called and call glutPostRedisplay() to display it  To disble the animation, register NULL as the Idle Function

Double Buffering  When redrawing an image, we want the new image to be displayed quickly enough that the redrawing operation will not be visible  Double Buffering creates the new image in a second buffer and displays it only on completion of drawing

Double Buffering (cont)  Enabled by setting –GLUT_DOUBLE IN glutInitDisplayMode()  Front buffer is displayed  Back buffer is the one into which we draw  Swap buffers –glutSwapBuffers()

Flicker  Clearing areas in an image can produce flicker  Double buffering can help with this  But we have to repeatedly draw things  Can set the drawing buffer with –glDrawBuffer(which)  GL_BACK, GL_FRONT_AND_BACK

Logic Operations  Drawing can be done in copy mode, also called replacement mode –pixels are set by drawing  or by performing one of 16 possible functions on 2 biits  in XOR mode –new pixel value is XORed with current pixel value

Logic Modes  OpenGL supports all 16 modes  Default is GL_COPY  Enable use of other modes with –glEnable(GL_COLOR_LOGIC_OP)  Set with –glLogicOP()  GL_COPY, GL_XOR, …  Redrawing in XOR mode erases  Can also change color, reverse with all 1’s