Introduction to OpenGL and GLUT. What’s OpenGL? An Application Programming Interface (API) A low-level graphics programming API – Contains over 250 functions.

Slides:



Advertisements
Similar presentations
Programming with OpenGL - Getting started - Hanyang University Han Jae-Hyek.
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…
Chapter 2: Graphics Programming
Computer Graphics CSCE 441
Pemrograman OpenGL Dasar
CS 4731 Lecture 2: Intro to 2D, 3D, OpenGL and GLUT (Part I) Emmanuel Agu.
What is OpenGL? Low level 2D and 3D Graphics Library Competitor to Direct3D (the rendering part of DirectX) Used in: CAD, virtual reality, scientific.
OpenGL Basics Donghui Han. Assignment Grading Visual Studio Glut Files of four types needed: – Source code:.cpp,.h – Executable file:.exe (build in release.
OpenGL (Graphics Library) Software Interface to graphics software Allows to create interactive programs that produce color images of moving 3D objects.
OpenGL (I). What is OpenGL (OGL)? OGL is a 3D graphics & modeling library Can also use it to draw 2D objects.
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Programming with OpenGL Part 2: Complete Programs Ed Angel Professor of Computer Science,
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Programming with OpenGL Part 1: Background Ed Angel Professor of Computer Science, Electrical.
InteractionHofstra University1 Graphics Programming Input and Interaction.
University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2008 Tamara Munzner OpenGL, GLUT, Transformations.
CENG477 Introduction to Computer Graphics Introduction to OpenGL, GLUT and GLUI.
CSE 494/598 Intro to Applied Computer Graphics Anshuman Razdan DCST AR's Web Page AR's Web Page
Programming with OpenGL Part 1: Background Mohan Sridharan Based on slides created by Edward Angel CS4395: Computer Graphics 1.
Based on slides created by Edward Angel
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.
Computer Graphics Bing-Yu Chen National Taiwan University.
1 GLUT Callback functions Event-driven: Programs that use windows  Input/Output  Wait until an event happens and then execute some pre-defined functions.
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.
Graphics Architectures & OpenGL API Introduction Angel Angel: Interactive Computer Graphics5E © Addison-Wesley
University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2010 Tamara Munzner GLUT, Transformations.
Computer Graphics using OpenGL, 3 rd Edition F. S. Hill, Jr. and S. Kelley Chapter 2 Initial Steps in Drawing Figures Ureerat Suksawatchon Faculty of Informatics.
Programming with OpenGL Part 1: Background
Lecture 3 OpenGL.
Computer Graphics I, Fall 2010 Input and Interaction.
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Programming with OpenGL Part 1: Background Ed Angel Professor of Computer Science, Electrical.
Computer Graphics CS 385 January 31, Fractals Some definitions Object which is self-similar at all scales. Regardless of scale the same level of.
 “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.
CD2012 Principles of Interactive Graphics Lecture 01 Introduction Abir Hussain (Rome: 6.33,Tel , Web:
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.
1 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 Programming with OpenGL Review.
1 Input and Interaction. 2 Objectives Introduce the basic input devices ­Physical Devices ­Logical Devices ­Input Modes Event-driven input Introduce double.
University of New Mexico
NoufNaief.net TA: Nouf Al-harbi.
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.
CSCE 441: Computer Graphics
OpenGL Basic Drawing 2003 Spring Keng Shih-Ling
1 Programming with OpenGL Part 2: Complete Programs.
OpenGL API 2D Graphic Primitives Angel Angel: Interactive Computer Graphics5E © Addison-Wesley
31/1/2006Based on: Angel (4th Edition) & Akeine-Möller & Haines (2nd Edition)1 CSC345: Advanced Graphics & Virtual Environments Lecture 2: Introduction.
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 OpenGL Muhammad Aamir Khan Lecturer, DCS, UOP.
Introduction to Graphics Programming. Graphics API.
Graphics Graphics Korea University kucg.korea.ac.kr Graphics Programming 고려대학교 컴퓨터 그래픽스 연구실.
Introduction to Graphics Programming. Graphics: Conceptual Model Real Object Human Eye Display Device Graphics System Synthetic Model Synthetic Camera.
Computer Graphics I, Fall Programming with OpenGL Part 2: Complete Programs.
OpenGL CS418 Computer Graphics John C. Hart. OpenGL: Event-driven How in OpenGL? Programmer registers callback functions Callback function called when.
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.
Computer Graphics -practical- Lecture 6. (visual c++) open gl library To use open GL with VC++ we add these files:- 1)Glut.h C:\program files\ Microsoft.
The Human Visual System vs The Pinhole camera
Programming with OpenGL Part 1: Background
גרפיקה ממוחשבת: מבוא ל-OpenGL
OpenGL Basics OpenGL’s primary function – Rendering
Programming with OpenGL Part 1: Background
Programming with OpenGL Part 1: Background
Presentation transcript:

Introduction to OpenGL and GLUT

What’s OpenGL? An Application Programming Interface (API) A low-level graphics programming API – Contains over 250 functions – Developed by Silicon Graphics Inc. (SGI) in 1992 – Most recent version: 4.2, released on 08/08/2011

OpenGL Applications And more…

Portability Independent of display devices Independent of window systems Independent of operating systems (100 Device 1: Line(100, 50, 150, 80) Device 2: MoveTo(100, 50) LineTo(150, 80) (100, 50) (150, 80)

OpenGL Basics The main use: Rendering. OpenGL can render: – Geometric primitives – Bitmaps and images Rendering is the process of generating an image from a model (or models in what collectively could be called a scene file), by means of computer programs Wikipedia

An Example void Display() { glClear(GL_COLOR_BUFFER_BITS); glColor4f(1, 1, 0, 1); glBegin(GL_POLYGON); glVertex2f(-0.5, -0.5); glVertex2f(-0.5, 0.5); glVertex2f( 0.5, 0.5); glVertex2f( 0.5, -0.5); glEnd(); glutSwapBuffers(); }

Primitives Primitives are specified as: PrimType: – GL_POINTS, GL_LINES, GL_TRIANGLES, … glBegin(primType); // your primitive vertices here. //... glEnd();

Primitive Types

An Example void Display() { glClear(GL_COLOR_BUFFER_BITS); glColor4f(1, 1, 0, 1); glBegin(GL_POLYGON); glVertex2f(-0.5, -0.5); glVertex2f(-0.5, 0.5); glVertex2f( 0.5, 0.5); glVertex2f( 0.5, -0.5); glEnd(); glutSwapBuffers(); } (-0.5, -0.5)(0.5, -0.5) (-0.5, 0.5)(0.5, 0.5)

Vertices glVertex2f(x, y) Number of dimensions/components 2: (x, y) 3: (x, y, z) or (r, g, b) 4: (x, y, z, w) or (r, g, b, a) Format b: byte ub: unsigned byte i: int ui: unsigned int f: float d: double v stands for vectors glVertex2fv(x, y)

An Example void Draw_Circle() { glColor4f(0, 0, 0, 1); int number = 20; //number of vertices float radius = 0.8f; //radius float twoPi = 2.0f * f; glBegin(GL_POLGYON); for(int i = 0; i <number; i++) glVertex2f(radius*cosf(i*twoPi/number), radius*sinf(i*twoPi/number)); glEnd(); }

Window-Based Programming Most modern operating systems are windows- based. Not window-basedWindow-based

Window-Based Programming OpenGL is independent of window systems. – No functions for window operations, such as creating, resizing, event handling, … – This is to ensure portability across different platforms – Now we have a problem: OpenGL doesn’t work by itself.

Graphics User Interfaces A Graphics User Interface (GUI) provides functions to: – Create windows, sliders, menus, buttons… – Resize windows – Handle mouse click, keyboard…. –…–… GLX for X window system AGL for Mac WGL for Microsoft Windows No portability…

GLUT (OpenGL Utility Toolkit) GLUT provides basic functions to operate windows. GLUT is cross-platform: X window, MS window, and Mac OS. No sliders, no buttons, no menus, …

GLUT Basics Program structure: 1.Configure and open a window (GLUT) 2.Initialize OpenGL. (Optional) 3.Register callback functions.(GLUT) a.Display(OpenGL) b.Resize(OpenGL) c.Input/output 4.Enter an event processing loop.(GLUT)

An Example #include void main(int argc, char **argv) { int mode=GLUT_RGB|GLUT_DOUBLE; glutInit(&argc, argv); glutInitDisplayMode(mode); glutInitWindowSize(800, 800); glutCreateWindow(“Hello Graphics World”); init(); glutDisplayFunc(display); glutKeyboardFunc(key); glutMainLoop(); }

An Example #include void main(int argc, char **argv) { int mode=GLUT_RGB|GLUT_DOUBLE; glutInit(&argc, argv); glutInitDisplayMode(mode); glutInitWindowSize(800, 800); glutCreateWindow(“Hello Graphics World”); init(); glutDisplayFunc(display); glutKeyboardFunc(key); glutMainLoop(); } Display mode: RGB or color index? Single frame buffer or double?

An Example #include void main(int argc, char **argv) { int mode=GLUT_RGB|GLUT_DOUBLE; glutInit(&argc, argv); glutInitDisplayMode(mode); glutInitWindowSize(800, 800); glutCreateWindow(“Hello Graphics World”); init(); glutDisplayFunc(display); glutKeyboardFunc(key); glutMainLoop(); } A window with resolution 800*800

An Example #include void main(int argc, char **argv) { int mode=GLUT_RGB|GLUT_DOUBLE; glutInit(&argc, argv); glutInitDisplayMode(mode); glutInitWindowSize(800, 800); glutCreateWindow(“Hello Graphics World”); init(); glutDisplayFunc(display); glutKeyboardFunc(key); glutMainLoop(); } Create the window with a title: “hello graphics world”

An Example #include void main(int argc, char **argv) { int mode=GLUT_RGB|GLUT_DOUBLE; glutInit(&argc, argv); glutInitDisplayMode(mode); glutInitWindowSize(800, 800); glutCreateWindow(“Hello Graphics World”); init(); glutDisplayFunc(display); glutKeyboardFunc(key); glutMainLoop(); } An optional init function

An Example #include void main(int argc, char **argv) { int mode=GLUT_RGB|GLUT_DOUBLE; glutInit(&argc, argv); glutInitDisplayMode(mode); glutInitWindowSize(800, 800); glutCreateWindow(“Hello Graphics World”); init(); glutDisplayFunc(display); glutKeyboardFunc(key); glutMainLoop(); } Let GLUT know which function to call, when an event happens

An Example #include void main(int argc, char **argv) { int mode=GLUT_RGB|GLUT_DOUBLE; glutInit(&argc, argv); glutInitDisplayMode(mode); glutInitWindowSize(800, 800); glutCreateWindow(“Hello Graphics World”); init(); glutDisplayFunc(display); glutKeyboardFunc(key); glutMainLoop(); } A loop that waits for events

Event-Driven Callbacks Most window-based programs are event- driven: – Do nothing until an event happens, – Then call the corresponding callback function Events – Key press, mouse button click/release, resize, ….

GLUT Display glutDisplayFunc(mydisplay); mydisplay is the name of a function that you will provide. You can use OpenGL to draw something. This function is called when the window needs to be refreshed. You can also signal a display event by youself: glutPostRedisplay();

Event Queue glutMainLoop(); Mouse event Keyboard event Display event Call mouse function

Some Callback Functions glutKeyboardFunc glutMouseFunc glutMotionFunc glutSpecialFunc glutIdleFunc