Lecture 3 OpenGL.

Slides:



Advertisements
Similar presentations
Computer Graphics - Graphics Programming -
Advertisements

Department of nskinfo i-education
OpenGL Open a Win32 Console Application in Microsoft Visual C++.
OpenGL CMSC340 3D Character Design & Animation. What is OpenGL? A low-level graphics library specification designed for use with the C and C++ provides…
OPEN GL. Install GLUT Download package di sini Dari devcpp, buka Tools->PackageManager-
Chapter 2: Graphics Programming
Computer Graphics CSCE 441
#include int line_width = 1; void Display( void ) { glEnable( GL_LINE_STIPPLE ); glClearColor (0.0, 0.0, 0.0, 0.0); glClear(GL_COLOR_BUFFER_BIT);
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
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
University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2008 Tamara Munzner OpenGL, GLUT, Transformations.
InteractionHofstra University1 Graphics Programming Input and Interaction.
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.
Chapter 03: Graphics Primitives Course web page: Chapter #3.
Reference1. [OpenGL course slides by Rasmus Stenholt]
CS380 LAB I OpenGL Donghyuk Kim Reference1. [OpenGL course slides by Rasmus Stenholt] Reference2. [
Using Graphics Libraries Lecture 3 Mon, Sep 1, 2003.
Introduction to OpenGL and GLUT GLUT. What is OpenGL? An application programming interface (API) A (low-level) Graphics rendering API Generate high-quality.
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 
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.
1 Figures are extracted from Angel's book (ISBN x) The Human Visual System vs The Pinhole camera Human Visual System Visible Spectrum Pinhole.
Managing Multiple Windows with OpenGL and GLUT
Introduction to GL Geb Thomas. Example Code int main(int argc, char **argv) { glutInit(&argc, argv); glutInitDisplayMode ( GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH);
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.
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.
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: –
Input and Interaction Yuanfeng Zhou Shandong University Software College 1.
C O M P U T E R G R A P H I C S Jie chen Computer graphic -- Programming with OpenGL 2.
University of New Mexico
Chun-Yuan Lin Introduction to OpenGL 2015/12/19 1 CG.
GLUT functions glutInit allows application to get command line arguments and initializes system gluInitDisplayMode requests properties for the window.
Doç. Dr. Cemil Öz SAÜ Bilgisayar Mühendisliği Dr. Cemil Öz.
Introduction to OpenGL Programming
OpenGL Basic Drawing 2003 Spring Keng Shih-Ling
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.
31/1/2006Based on: Angel (4th Edition) & Akeine-Möller & Haines (2nd Edition)1 CSC345: Advanced Graphics & Virtual Environments Lecture 2: Introduction.
CS559: Computer Graphics Lecture 12: OpenGL: ModelView Li Zhang Spring 2010.
OpenGL Basic Drawing Jian-Liang Lin A Smidgen of OpenGL Code #include main() { InitializeAWindowPlease(); glClearColor (0.0, 0.0, 0.0, 0.0); glClear.
Introduction to Graphics Programming. Graphics API.
Introduction to Graphics Programming. Graphics: Conceptual Model Real Object Human Eye Display Device Graphics System Synthetic Model Synthetic Camera.
CSC Graphics Programming Budditha Hettige Department of Statistics and Computer Science.
INTRODUCTION TO OPENGL
Computer Graphics (Fall 2003) COMS 4160, Lecture 5: OpenGL 1 Ravi Ramamoorthi Many slides courtesy Greg Humphreys.
OpenGL and GLUT Review Daniel Ritchie Monday, October 3 rd, 2011.
Basic Program with OpenGL and GLUT
Computer Graphics Lecture 33
CSC461 Lecture 8: Input Devices
The User Interface Lecture 2 Mon, Aug 27, 2007.
גרפיקה ממוחשבת: מבוא ל-OpenGL
Introduction to OpenGL
Input and Interaction Ed Angel
University of New Mexico
Input and Interaction Ed Angel
Managing Multiple Windows with OpenGL and GLUT
Presentation transcript:

Lecture 3 OpenGL

Lecture 3 Review Rasterization OpenGL Libraries: GL, GLU, GLUT Buffers: Buffer Types Clearing Buffers Primitives Colors Sample Code

Lecture Three Color Modes Event Driven Programming RGB vs. Color-Index mode Event Driven Programming Call back Registration Mouse, Keyboard call backs Reshape, Display, Idle Double buffering Animation

Color Modes RGB Mode: A color is specified by: Red Green Blue Alpha Number of colors simultaneously displayed: n bits represents 2^n colors. 8 to 16 bits represent 256 to 64K colors

Color Modes Color Index Mode: Uses Color Index Table We can still use only 2^n color simultaneously But the set of 2^n colors are picked from a table, Color Index Table Void glutInitDisplayMode (GLUT_RGBA or GLUT_INDEX)

Choosing Color Model In order to choose a color Model use: Void glutInitDisplayMode (GLUT_RGBA or GLUT_INDEX) Need more details? Visit ‘Online Resources’ in course website, or click following link http://www.cse.yorku.ca/~alireza/courses/540/rgba.pdf

Event Driven Programming Definition. A programming where the primary activity is reaction to the receipt of event. Applications: GUI, HCI Ingredients: Events: Can be from any source, human input, e.g. mouse or other sensors. Event Dispatcher: Assigns events to event handlers. Event Handler

Event Processing in GLUT Initial Setup: Initializing Display Modes, e.g. Color mode, Single/Double Buffer, etc. Entering GLUT event processing loop void glutMainLoop (void)

Call Back Registration Definitions: current window Normal Plane Assigning events to event-handler. glutReshapeFunction glutDisplayFunction glutKeyboardFunction glutMouseFunction

Display Function The display function of current window When is it called? If the normal plane of a window needs to be redisplayed as a result of window damage. GLUT determines this based on redisplay state of a window. When a user requests. How is it called? Implicitly: By GLUT, e.g. when the window system reports a region of the window's normal plane is undefined (for example, damaged by another window moving or being initially shown) Explicitly: Using glutPostRedisplay function.

Reshape Function Takes care of Window Resize When is it called? Whenever current window is reshaped How is it called? By GLUT Width and height of new window is passed void reshape (int w, int h)

main method GLUT initialization Registering Event Handler functions glutInit (&argc, argv) glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB) glutInitWindowSize (width, height) glutInitWindowPosition (X, Y) Registering Event Handler functions Display Function, Reshape Function, etc. Entering GLUT Event Processing glutMainLoop function

Sample Code in main method glutInit(&argc, argv); glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB); glutInitWindowSize (250, 250); glutInitWindowPosition (100, 100); glutCreateWindow (argv[0]); glClearColor (0.0, 0.0, 0.0, 0.0); glShadeModel (GL_FLAT); glutDisplayFunc(display); glutReshapeFunc(reshape); glutMouseFunc(mouse); glutKeyboardFunc(keyboard); glutMainLoop(); return 0;

Event Handling: Keyboard Registration void glutKeyboardFunc (void (*func) (unsigned char key, int x, int y)) X,Y are the coordinate of mouse when key is pressed Refer to online resources GLUT API for details about key callbacks. For non-ASCII key strokes F1~F12, Direction, Del, Ins, PgUp, etc. glutSpecialFunc

Event Handling: Mouse Registration void glutMouseFunc (void (*func) (int button, int state, int x, int y)) Button value: GLUT_LEFT_BUTTON, GLUT_MIDDLE_BUTTON, or GLUT_RIGHT_BUTTON. State Value: GLUT_UP or GLUT_DOWN: Represents that the event happened because of press or release. void glutMotionFunc (void (*func) (int x, int y)) Is called whenever the mouse moves within the window while one or more mouse buttons are pressed. void glutPassiveMotionFunc (void (*func) (int x, int y)) Is called whenever the mouse moves within the window while no mouse buttons are pressed.

Idle Function Even sitting Idle is an event Handling Idle event glutIdleFunc (void (*func) (void)) Most useful for creating animations

Example Download the “Keyboard Event” sample code from the course website. Let’s explain the code Add an arbitrary mouse event to the code

Double Buffering Using Two buffers Is specified in initialization step Front Buffer Back Buffer Is specified in initialization step glutInitDisplayMode (GLUT_DOUBLE) Replace glFlush() with glSwapBuffers() Increases the performance It’s NOT free, you have to pay: memory

Example Download the “Double Buffer Example” sample code from the course website. Compare the performance of Single buffer and Double buffer Try to add events to the program.

Animation Algorithm Initialize GLUT windowing system Initialize Event Handlers Display Reshape Mouse, Keyboard, etc Idle Single/Double Buffering glFlush or glSwapBuffers

Conclusion What we covered today: Color Modes Event Driven Programming Registering Callback Functions Double Buffering Animation

QUESTIONS?

Next Week Basic 3D Graphics Basic Camera Setup and Control Orthographic Projection Perspective Projection Drawing 3D Objects GLUT solid and wireframe objects

END