Introduction to the Mouse

Slides:



Advertisements
Similar presentations
1 Computer Graphics Chapter 2 Input Devices. RM[2]-2 Input Devices Logical Input Devices  Categorized based on functional characteristics.  Each device.
Advertisements

Computer Graphics using OpenGL, 3 rd Edition F. S. Hill, Jr. and S. Kelley Chapter 3 Additional Drawing Tools Ureerat Suksawatchon Department of Computer.
OpenGL (I). What is OpenGL (OGL)? OGL is a 3D graphics & modeling library Can also use it to draw 2D objects.
Painterly Rendering CMPS Assignment 2. OpenGL OpenGL is a cross-language, cross- platform specification defining and API for 2D and 3D graphics.
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.
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.
Chi-Cheng Lin, Winona State University CS430 Computer Graphics Graphics Programming and OpenGL.
Course Overview, Introduction to CG Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Friday, September 5, 2003.
Mouse-Based Viewing & Navigation Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Monday, November 3, 2003.
Basic OpenGL Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Wednesday, September 10, 2003.
Events and Coordinates Lecture 5 Fri, Sep 5, 2003.
Linear Interpolation, Brief Introduction to OpenGL Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Monday, September.
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.
Interaction with Graphics System
Lecture 5: Interaction 1  Principles of Interactive Graphics  CMSCD2012  Dr David England, Room 711,  ex 2271 
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.
Write a Simple Program with OpenGL & GLUT. Books OpenGL Programming Guide (Red-book) OpenGL Reference Manual (Blue-book) OpenGL Super Bible
Homogeneous Form, Introduction to 3-D Graphics Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Monday, October 20,
More on Drawable Objects, Hierarchical Objects Glenn G. Chappell U. of Alaska Fairbanks CS 481/681 Lecture Notes Wednesday, January.
Build-A-Button Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Wednesday, October 8, 2003.
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.
Intro to OpenGL (Version 2) Geb Thomas. Setting Up GLUT You will need GLUT for opening windows We can use the version made by Nate Robins: –
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.
Advanced Viewing Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Friday, October 31, 2003.
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
Drawing and Coordinate Systems. Coordinate Systems Screen Coordinate system World Coordinate system World window Viewport Window to viewport mapping.
Programming with Visual Studio MFC and OpenGL. Outline Creating a project Adding OpenGL initialization code and libraries Creating a mouse event Drawing.
Selection Mode, Introduction to Widgets Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Monday, October 6, 2003.
Some Notes on 3-D Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Friday, October 24, 2003.
1 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 Working with Callbacks.
INTRODUCTION TO OPENGL
Introduction to 3-D Viewing Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Monday, October 27, 2003.
Basic Program with OpenGL and GLUT
Review GLUT Callback Functions
Computer Graphics and Visualization (06 CS 65)
PYGAME.
Lecture 09 Applets.
Working with Callbacks
INTERACTIVE TRANSPARENCY BUILDING A Character IN ANIMATION
Reference1. [OpenGL course slides by Rasmus Stenholt]
The User Interface Lecture 2 Mon, Aug 27, 2007.
Advanced Menuing, Introduction to Picking
OpenGL Basics OpenGL’s primary function – Rendering
Chapter 3 arrays of vertices vertex arrays display lists drawing text
Working with Callbacks
Project 1: Into Space! CG Concepts Needed
Coordinate Systems and Transforming the Coordinates
Chapter 3 arrays of vertices vertex arrays display lists drawing text
Projection in 3-D Glenn G. Chappell
Display Lists & Text Glenn G. Chappell
Introduction to OpenGL
More programming with "Processing"
More on Widgets, Misc. Topics
Fundamentals of Computer Graphics Part 3
2D Graphics Lecture 4 Fri, Aug 31, 2007.
Chapter 3 arrays of vertices vertex arrays display lists drawing text
CS297 Graphics with Java and OpenGL
Chapter 3 arrays of vertices vertex arrays display lists drawing text
Preview of 3-D Graphics Glenn G. Chappell
Presentation transcript:

Introduction to the Mouse Glenn G. Chappell CHAPPELLG@member.ams.org U. of Alaska Fairbanks CS 381 Lecture Notes Wednesday, September 24, 2003

Review: Display Lists A display list (or call list) is a way for OpenGL to save commands for later playback. Display lists are compiled and then executed. Display list storage & format is implementation-dependent and handled internally by OpenGL. We compile a display list in four steps: Generate a “name” (actually an integer) for the list. (glGenLists). Tell OpenGL that we are creating a display list (glNewList). Make the OpenGL function calls that we want to store in the display list. Only OpenGL commands are stored in the list! Tell OpenGL that we are finished creating the list (glEndList). We execute a display list with a single function call. We pass its name to glCallList. 24 Sep 2003 CS 381

Review: Text [1/2] In CG, text comes in two varieties: Bitmap Outline/stroke Both are available, in a limited form, in GLUT. 24 Sep 2003 CS 381

Review: Text [2/2] GLUT bitmap text is made using the OpenGL bitmap primitive glBitmap. Bitmaps (and other raster images) are drawn at the raster position. The left-hand point of the baseline is drawn at this position. The baseline is often the bottom of the image. We can move it up, to allow for descenders in text. Set the raster position using glRasterPos*. Parameters of glRasterPos* are handled like those of glVertex*. We draw a character at the current raster position using glutBitmapCharacter. The raster position is advanced. 24 Sep 2003 CS 381

The Mouse: Overview We now begin a discussion of event-driven programming using the mouse (or other 2-D pointing device). We will cover: Basic mouse handling via “mouse” & “motion” callbacks. Today Mouse-based pop-up menus. Friday “Picking”. Starting on Monday. But first: Mouse-handling is heavily dependent on pixel coordinates, so we need to know how to deal with these. Therefore, we discuss GLUT’s “reshape” callback. 24 Sep 2003 CS 381

Reshape Callback: What It Does The GLUT reshape callback function is called: When the window is first created, before any other callback. Later, whenever the window size/shape changes. Not when the window is merely moved. GLUT has a built-in reshape function. But it might not do what you want. Registering a callback replaces the built-in function with your own. Reshape has 2 parameters: New width of window, in pixels. New height of window, in pixels. If you need information on the window size somewhere else, save it in the reshape function. Maybe you can get it by other means, but why bother? 24 Sep 2003 CS 381

Reshape Callback: Setting the Viewport The first thing you usually do in a reshape function is void reshape(int w, int h) { glViewport(0, 0, w, h); Function glViewport sets the viewport. Parameters: Left side (pixels from left side of window). Bottom (pixels from bottom of window). Width (in pixels). Height (in pixels). So the above call sets the viewport to the entire windows. 24 Sep 2003 CS 381

Reshape Callback: Setting the Projection The next thing you do in a reshape function is usually to set the projection. For now, gluOrtho2D is generally what you want to use. Later we’ll want perspective. Recall: You can think of this as setting up a coordinate system in the viewport. glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluOrtho2D(left, right, bottom, top); glMatrixMode(GL_MODELVIEW); 24 Sep 2003 CS 381

Reshape Callback: Working in Pixels Suppose you want the coordinate system to be in pixels? This might be convenient when dealing with the mouse. void reshape(int w, int h) { glViewport(0, 0, w, h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluOrtho2D(0, w, 0, h); glMatrixMode(GL_MODELVIEW); } 24 Sep 2003 CS 381

Mouse-Related Callbacks: Mouse & Motion Functions GLUT has two main mouse-handling callbacks. The mouse function. This is called when any of the mouse buttons (GLUT assumes 3) is pressed or released. … unless the mouse event is intended for some other program. The motion function. This is called (possibly repeatedly) whenever the mouse moves while any of the buttons is pressed. An exception: GLUT includes mouse-controlled pop-up menus. A menu can be “attached” to a mouse button, so that the menu pops up when the button is pressed. If this is done, then the above callbacks are not called when this button is down. We will discuss menus on Friday. Now the details … 24 Sep 2003 CS 381

Mouse-Related Callbacks: Mouse Function The mouse function is called when a mouse button is pressed or released. Registered with glutMouseFunc(mouse); // can use different name Declared as void mouse(int button, int state, int x, int y) button will be one of GLUT_LEFT_BUTTON GLUT_MIDDLE_BUTTON (GLUT started under Unix/X-Windows) GLUT_RIGHT_BUTTON state will be one of GLUT_DOWN (button press) GLUT_UP (button release) x and y are the mouse position, in pixels. x is from left side of window, y is from top (not bottom). 24 Sep 2003 CS 381

Mouse-Related Callbacks: Motion Function The motion function is called if the mouse is moved while a mouse button is down. If the mouse moves again, motion function is called again. Motion functions are useful for dragging and drawing. Registered with glutMotionFunc(motion); // can use different name Declared as void motion(int x, int y) x and y are the mouse position, in pixels. x is from left side of window, y is from top (not bottom). Guaranteed sequence of events when dragging: First the mouse function is called (button down). Then the motion function may be called (zero or more times). Lastly, the mouse function is called (button up). 24 Sep 2003 CS 381

Mouse-Related Callbacks: Converting Coordinates [1/2] GLUT gives mouse coordinates in pixels from the upper-left corner of the window. OpenGL deals with coordinates set by the projection. May not be in pixels. Based at the lower-left corner of the viewport. 24 Sep 2003 CS 381

Mouse-Related Callbacks: Converting Coordinates [2/2] EXAMPLES Suppose we did gluOrtho2D(0.0, 1.0, 0.0, 1.0); How do we convert between GLUT mouse coordinates and OpenGL coordinates? Given mouse @ x, y; window size w, h. In OpenGL coordinates: x/w, 1-y/h. Note: The above will not work right in a C++ program, since it will do integer division. Use: double(x)/w, 1-double(y)/h. Same question for the coordinates in pixels, as in the last “reshape” slide. In OpenGL coordinates: x, h-y. 24 Sep 2003 CS 381

Mouse-Related Callbacks: Other Callbacks The keyboard and special functions are given the mouse position. Use it if you want. You might treat the keyboard as a large collection of “mouse buttons”. Unconventional … Also, you don’t get mouse-up events. There is a “passive motion” callback. It is called when the mouse moves, and no button is down. Otherwise, it works just like the motion function, except, of course, for the guaranteed sequence of events. 24 Sep 2003 CS 381

Mouse-Related Callbacks: Example Write a program the uses the mouse and motion callbacks. We will do this on Friday. For now, see simplemouse.cpp, on the web page. 24 Sep 2003 CS 381