CSC Graphics Programming. Budditha Hettige Department of Statistics and Computer Science

Similar documents
Introduction to Computer Graphics with OpenGL/GLUT

RECITATION - 1. Ceng477 Fall

Project Sketchpad. Ivan Sutherland (MIT 1963) established the basic interactive paradigm that characterizes interactive computer graphics:

Input and Interaction

Input, Interaction and Animation Week 2

CS 432 Interactive Computer Graphics

Input and Interaction. CS 537 Interactive Computer Graphics Prof. David E. Breen Department of Computer Science

CGT521 OpenGL Utility Toolkit

C++ is Fun Part 13 at Turbine/Warner Bros.! Russell Hanson

Computer Graphics 1 Computer Graphics 1

// double buffering and RGB glutinitdisplaymode(glut_double GLUT_RGBA); // your own initializations

Comp 410/510 Computer Graphics Spring Input & Interaction

Lecture 11: Callbacks. CITS 3003 Graphics & Animation

OpenGL refresher. Advanced Computer Graphics 2012

VR-programming tools (procedural) More VRML later in this course! (declarative)

Working with Callbacks

Lecture 4. Interaction / Graphical Devices. CS 354 Computer Graphics Sunday, January 20, 13

GL_COLOR_BUFFER_BIT, GL_PROJECTION, GL_MODELVIEW

To Do. Computer Graphics (Fall 2008) Course Outline. Course Outline. Methodology for Lecture. Demo: Surreal (HW 3)

CS Computer Graphics: OpenGL, Continued

CS Computer Graphics: OpenGL, Continued

CS559: Computer Graphics. Lecture 12: OpenGL Li Zhang Spring 2008

Computer Graphics. OpenGL

The OpenGL Utility Toolkit (GLUT) Programming Interface


Lecture 3 Advanced Computer Graphics (CS & SE )

CSCI 4620/8626. The 2D Viewing Pipeline

Introduction to OpenGL

OpenGL and X, Column 1: An OpenGL Toolkit

Computer Graphics. Bing-Yu Chen National Taiwan University

OPENGL TM AND X, COLUMN 1: AN OPENGL TOOLKIT

Exercise 1 Introduction to OpenGL

CS 432 Interactive Computer Graphics

GLUT Tutorial. Keyboard

Computer Graphics (CS 543) Lecture 2b: 2D Graphics Systems (Drawing Polylines, tiling, & Aspect Ratio)

Image Processing. Geometry Processing. Reading: (Not really covered in our text. See Sects 18.1, 18.2.) Overview: Display

Drawing Primitives. OpenGL basics

Computer Graphics Course 2005

Using OpenGL with CUDA

Input and Interaction. 1. Interaction. Chapter 3. Introduction: - We now turn to the development of interactive graphics programs.

OpenGL/GLUT Intro. Week 1, Fri Jan 12

CS 4204 Computer Graphics

Lecture 2 2D transformations Introduction to OpenGL

Lecture 3. Understanding of OPenGL programming

C OMPUTER G RAPHICS Thursday

ERKELEY DAVIS IRVINE LOS ANGELES RIVERSIDE SAN DIEGO SAN FRANCISCO EECS 104. Fundamentals of Computer Graphics. OpenGL

CS 4731 Lecture 3: Introduction to OpenGL and GLUT: Part II. Emmanuel Agu

Introduction to OpenGL: Part 2

CS Computer Graphics: Intro to OpenGL

CS Computer Graphics: Intro to OpenGL

Lecture 4 of 41. Lab 1a: OpenGL Basics

COMPUTER GRAPHICS LAB # 3

Basic Graphics Programming

Teacher Assistant : Tamir Grossinger Reception hours: by - Building 37 / office -102 Assignments: 4 programing using

by modifying the glutinitwindowsize() function you can change the screen size to whatever you please.

Transformation, Input and Interaction. Hanyang University

FAKULTI TEKNOLOGI MAKLUMAT DAN KOMUNIKASI BITM INTERACTIVE COMPUTER GRAPHICS LAB SESSION 4. C++ - OpenGL

Lecture 10: Input, Interaction & callbacks. CITS 3003 Graphics & Animation

Computer Graphics Introduction to OpenGL

VTU EDUSAT PROGRAMME. Computer Graphics & Visualization

CS 543 Lecture 1 (Part II): Intro to OpenGL and GLUT (Part I) Emmanuel Agu

CS559: Computer Graphics. Lecture 12: OpenGL Transformation Li Zhang Spring 2008

Modeling Transform. Chapter 4 Geometric Transformations. Overview. Instancing. Specify transformation for objects 李同益

Lecture 2 CISC440/640 Spring Department of Computer and Information Science

Programming using OpenGL: A first Introduction

Books, OpenGL, GLUT, GLUI, CUDA, OpenCL, OpenCV, PointClouds, and G3D

Input and Interaction. Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico

CS 4204 Computer Graphics

Computer graphics MN1

Computer Graphics Primitive Attributes

Computer graphic -- Programming with OpenGL 2

Interaction. CSCI 480 Computer Graphics Lecture 3

Cameras (and eye) Ideal Pinhole. Real Pinhole. Real + lens. Depth of field

An Introduction to. Graphics Programming

Chapter 10: Events and Event Handling for Computer Graphics

BOUNCING BALL IMRAN IHSAN ASSISTANT PROFESSOR

20 GLuint objects; 36 Scale += 0.1; 37 break; 38 case GLUT_KEY_DOWN:

Display Lists in OpenGL

Books, OpenGL, GLUT, CUDA, OpenCL, OpenCV, PointClouds, G3D, and Qt

OpenGL Programming Guide Chapter 1, Introduction to OpenGL 1

Lecture 2 Sections 3.6, 3.7. Fri, Aug 28, 2009

Order of Transformations

Basic Graphics Programming

Announcements OpenGL. Computer Graphics. Spring CS4815

Information Coding / Computer Graphics, ISY, LiTH. OpenGL! ! where it fits!! what it contains!! how you work with it 11(40)

Interaction Computer Graphics I Lecture 3

Abel J. P. Gomes LAB. 1. INTRODUCTION TO OpenGL

2 Transformations and Homogeneous Coordinates

11/1/13. Basic Graphics Programming. Teaching Assistant. What is OpenGL. Course Producer. Where is OpenGL used. Graphics library (API)

Announcements OpenGL. Computer Graphics. Autumn 2009 CS4815

CMSC 425: Lecture 4 More about OpenGL and GLUT Tuesday, Feb 5, 2013

Computer Graphics. Downloaded from: LectureNotes 1 CSC-254

Erik Anchondo cse 520 lab 4

Computer graphics MN1

Programming with OpenGL Part 2: Complete Programs Computer Graphics I, Fall

GLUT. What is OpenGL? Introduction to OpenGL and GLUT

Computer Graphics (CS 4731) OpenGL/GLUT (Part 2)

gvirtualxray Tutorial 01: Creating a Window and an OpenGL Context Using GLUT

COMP 371/4 Computer Graphics Week 1

CSE4030 Introduction to Computer Graphics

Transcription:

CSC 307 1.0 Graphics Programming Department of Statistics and Computer Science

Graphics Programming GLUT 2

Events in OpenGL Event Example Keypress KeyDown KeyUp Mouse leftbuttondown leftbuttonup With mouse press Motion Without Moving Window Resizing Idle System Timer Software What to draw OpenGL Callback Function glutkeyboardfunc glutmousefunc glutmotionfunc glutpassivemotionfunc glutreshapefunc glutidlefunc gluttimerfunc glutdisplayfunc 3

GLUT Callback functions Event-driven: Programs that use windows Input/Output Wait until an event happens and then execute some pre-defined functions according to the user s input Events key press, mouse button press and release, window resize, etc. Your OpenGL program will be in infinite loop 4

GLUT Callback Functions Callback function : Routine to call when an event happens Window resize or redraw User input (mouse, keyboard) Animation (render many frames) Register callbacks with GLUT glutdisplayfunc( my_display_func ); glutidlefunc( my_idle_func ); glutkeyboardfunc( my_key_events_func ); glutmousefunc ( my_mouse_events_func ); 5

Rendering Callback Callback function where all our drawing is done Every GLUT program must have a display callback glutdisplayfunc( my_display_func ); /* this part is in main.c */ void my_display_func (void ) glclear( GL_COLOR_BUFFER_BIT ); glbegin( GL_TRIANGLE ); glvertex3fv( v[0] ); glvertex3fv( v[1] ); glvertex3fv( v[2] ); glend(); glflush(); 6

Idle Callback Function Use for animation and continuous update Can use gluttimerfunc or timed callbacks for animations glutidlefunc( idle ); glutidlefunc(void (*func)(void)). glutidlefunc(myidlefun); void MyidleFun( void ) /* change something */ Function Name t += dt; glutpostredisplay(); 7

User Input Callbacks Process user input (Keyboard/ Mouse) glutkeyboardfunc( my_key_events ); // for keyboard glutmousefunc( my_mouse ); // for mouse glutkeyboardfunc(void (*func)(unsigned char key, int x, int y)) glutkeyboardfunc sets the keyboard callback for the current window void my_key_events (char key, int x, int y ) switch ( key ) case q : case Q : exit ( EXIT_SUCCESS); break; case r : case R : rotate = GL_TRUE; break;... 8

glutspecialfunc The new special callback function sets the special keyboard callback for the current window GLUT_KEY_F1 F1 function key. GLUT_KEY_F2 F2 function key. GLUT_KEY_F3 F3 function key. GLUT_KEY_F4 F4 function key. GLUT_KEY_F5 F5 function key. GLUT_KEY_LEFT Left directional key. GLUT_KEY_UP Up directional key. GLUT_KEY_RIGHT Right directional key. 9

glutspecialfunc Example void SpecialKeys(int key, int x, int y) if(key == GLUT_KEY_UP) // Some functions if(key == GLUT_KEY_DOWN) // Some functions if(key == GLUT_KEY_LEFT) if(key == GLUT_KEY_RIGHT) // Some functions glutpostredisplay(); int main(int argc, char *argv[]) glutinit(&argc, argv); glutinitdisplaymode(glut_double GLUT_RGB); glutinitwindowsize(800, 600); glutspecialfunc(specialkeys); glutdisplayfunc(renderscene); glutmainloop(); return 0; 10

Example Insert a keyboard function to display the simple polygon with following optons Left Increase the width Right Descries the width Up Increase the height Down Descries the height F1 Change the color as red F2 Change the color as blue F3 Change the color white F5 Set the default values 11

Mouse Callback Captures mouse press and release events glutmousefunc( my_mouse ); void mymouse(int button, int state, int x, int y) if (button == GLUT_LEFT_BUTTON) Button State GLUT LEFT BUTTON, GLUT MIDDLE BUTTON, or GLUT RIGHT BUTTON. GLUT_DOWN GLUT_UP 12

Example void mouse(int button, int state, int x, int y) switch (button) case GLUT_LEFT_BUTTON: if (state == GLUT_DOWN) break; glutidlefunc(spindisplay); case GLUT_MIDDLE_BUTTON: if (state == GLUT_DOWN) break; default: glutidlefunc(null); break; int main(int argc, char** argv) glutinit(&argc, argv); glutinitdisplaymode(glut_double GLUT_RGB); glutinitwindowsize(250, 250); glutinitwindowposition(100, 100); glutcreatewindow(argv[0]); init(); glutdisplayfunc(display); glutreshapefunc(reshape); glutmousefunc(mouse); glutmainloop(); return 0; 13

Reshape glutreshapefunc(void (*func)(int w, int h)) indicates what action should be taken when the window is resized Example glutreshapefunc(resize); void resize(glsizei w, GLsizei h) if (h==0) h=1; // avoid div by 0 glviewport(0, 0, w, h); glmatrixmode(gl_projection); glloadidentity(); if (w<=h) glortho(0, 250, 0, 250*h/w, 1.0, -1.0); else glortho(0, 250*w/h, 0, 250, 1.0, -1.0); glmatrixmode(gl_modelview); glloadidentity(); 14

Timer Function gluttimerfunc registers a timer callback to be triggered in a specified number of milliseconds Wait ms, value pass to call back function void gluttimerfunc(unsigned int msecs, void (*func)(int value), int value); void TimerFunction(int value) Main gluttimerfunc(33, TimerFunction, 1); 15

OpenGL Menu GLUT supports simple cascading pop-up menus designed to let a user select various modes within a program pop-up menu facility with an attempt to create a full-featured user interface It is illegal to create, destroy, change, add, or remove menu items while a menu are in use 16

Menu Functions glutcreatemenu glutcreatemenu creates a new pop-up menu. int glutcreatemenu(void (*func)(int value)); glutaddsubmenu glutaddsubmenu adds a sub-menu trigger to the bottom of the current menu. void glutaddsubmenu(char *name, int menu); glutaddmenuentry glutaddmenuentry adds a menu entry to the bottom of the current menu void glutaddmenuentry(char *name, int value); 17

Menu Functions glutremovemenuitem glutremovemenuitem remove the specified menu item. void glutremovemenuitem(int entry); glutattachmenu attaches a mouse button for the current window to the identifier of the current menu; void glutattachmenu(int button); glutdetachmenu detaches an attached mouse button from the current window. void glutdetachmenu(int button); 18

Menu Example glutcreatemenu(processmenu); glutaddmenuentry("save Image",0); glutaddmenuentry("draw Pixels",1); glutaddmenuentry("flip Pixels",2); glutaddmenuentry("zoom Pixels",3); glutattachmenu(glut_right_button); void ProcessMenu(int value) if(value == 0) // TASK FOR 0 VALUE glutpostredisplay(); 19

Window Management GLUT supports two types of windows: top-level windows and subwindows glutcreatewindow glutcreatewindow creates a top-level window. int glutcreatewindow(char *name); glutcreatesubwindow glutcreatesubwindow creates a subwindow. int glutcreatesubwindow(int win, int x, int y, int width, int height); glutsetwindow, glutgetwindow glutsetwindow sets the current window; glutgetwindow returns the identifier of the current window. void glutsetwindow(int win); int glutgetwindow(void); 20

Window Management glutdestroywindow glutdestroywindow destroys the specified window. void glutdestroywindow(int win); glutpostredisplay glutpostredisplay marks the current window as needing to be redisplayed. void glutpostredisplay(void); glutswapbuffers glutswapbuffers swaps the buffers of the current window if double buffered. void glutswapbuffers(void); 21

Window Management glutpositionwindow glutpositionwindow requests a change to the position of the current window. void glutpositionwindow(int x, int y); glutreshapewindow glutreshapewindow requests a change to the size of the current window. void glutreshapewindow(int width, int height); glutfullscreen glutfullscreen requests that the current window be made full screen. void glutfullscreen(void); 22

Window Management glutpopwindow, glutpushwindow glutpopwindow and glutpushwindow change the stacking order of the current window relative to its siblings. void glutpopwindow(void); void glutpushwindow(void); glutsetwindowtitle, glutseticontitle glutsetwindowtitle and glutseticontitlechange thewindow or icon title respectively of the current top-level window. void glutsetwindowtitle(char *name); void glutseticontitle(char *name); glutshowwindow, gluthidewindow, gluticonifywindow glutshowwindow, gluthidewindow, and gluticonifywindow change the display status of the current window. void glutshowwindow(void); void gluthidewindow(void); void gluticonifywindow(void); 23

Window Management glutsetcursor glutsetcursor changes the cursor image of the current window. void glutsetcursor(int cursor); glutsetcursor(glut_cursor_none); GLUT_CURSOR_RIGHT_ARROW GLUT_CURSOR_LEFT GLUT_CURSOR_INFO GLUT_CURSOR_DESTROY. GLUT_CURSOR_HELP GLUT_CURSOR_CYCLE GLUT_CURSOR_SPRAY GLUT_CURSOR_WAIT GLUT_CURSOR_NONE GLUT_CURSOR_INHERIT 24