Using OpenGL. 2 What is OpenGL? A software interface to graphics hardware It is a Graphics Rendering API (Application Programmer’s Interface) that is.

Slides:



Advertisements
Similar presentations
Programming with OpenGL - Getting started - Hanyang University Han Jae-Hyek.
Advertisements

©Zachary Wartell, UNCC9/28/ :30 AM 1 Overview of OpenGL Revision: 1.2 Copyright Professor Zachary Wartell, University of North Carolina All Rights.
Chapter 2: Graphics Programming
Computer Graphics CSCE 441
Pemrograman OpenGL Dasar
Introduction to OpenGL
David Luebke5/16/2015 Administrivia l Back on track: canceling OpenGL lecture 2 l Assignment 1 –Greg Yukl found an alternate XForms site:
Informationsteknologi Monday, October 29, 2007Computer Graphics - Class 21 Today’s class Graphics programming Color.
OpenGL (Graphics Library) Software Interface to graphics software Allows to create interactive programs that produce color images of moving 3D objects.
Drawing Geometric 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.
Programming with OpenGL Part 1: Background Mohan Sridharan Based on slides created by Edward Angel CS4395: Computer Graphics 1.
CSC 461: Lecture 6 1 CSC461 Lecture 6: 2D Programming in OpenGL Objectives:  Fundamental OpenGL primitives  Attributes  Viewport.
3D Rendering with JOGL Introduction to Java OpenGL Graphic Library By Ricardo Veguilla
Introduction to OpenGL M. Ramanathan STTP CAD 2011Introduction to OpenGL.
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. [
Computer Graphics Bing-Yu Chen National Taiwan University.
Lecture 5 - Programming with OpenGL
CAP4730: Computational Structures in Computer Graphics Introduction to OpenGL.
Basic OpenGL Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Wednesday, September 10, 2003.
Drawing Basic Graphics Primitives Lecture 4 Wed, Sep 3, 2003.
Introduction to OpenGL and GLUT GLUT. What is OpenGL? An application programming interface (API) A (low-level) Graphics rendering API Generate high-quality.
CSC 461: Lecture 41 CSC461: Lecture 4 Introduction to OpenGL Objectives: Development of the OpenGL API OpenGL Architecture -- OpenGL as a state machine.
Graphics Architectures & OpenGL API Introduction Angel Angel: Interactive Computer Graphics5E © Addison-Wesley
2 COEN Computer Graphics I Introductions n Brad Grantham lecturer lab dude n Dave Shreiner lecturer slave driver.
Programming with OpenGL Part 1: Background
Ch 2 Graphics Programming page 1 CSC 367 Coordinate Systems (2.1.2) Device coordinates, or screen coordinates (pixels) put limitations on programmers and.
1. OpenGL/GLU/GLUT  OpenGL v4.0 (latest) is the “core” library that is platform independent  GLUT v3.7 is an auxiliary library that handles window creation,
1 Figures are extracted from Angel's book (ISBN x) The Human Visual System vs The Pinhole camera Human Visual System Visible Spectrum Pinhole.
CS 4363/6353 OPENGL BACKGROUND. WHY IS THIS CLASS SO HARD TO TEACH? (I’LL STOP WHINING SOON) Hardware (GPUs) double in processing power ever 6 months!
Introduction to OpenGL Programming Jian-Liang Lin 2002.
Computer Graphics Bing-Yu Chen National Taiwan University.
Introduction to OpenGL and GLUT. What’s OpenGL? An Application Programming Interface (API) A low-level graphics programming API – Contains over 250 functions.
Programming With OpenGL
Chun-Yuan Lin Introduction to OpenGL 2015/12/19 1 CG.
NoufNaief.net TA: Nouf Al-harbi.
NoufNaief.net 1 TA: Nouf Al-Harbi.
CSCE 441: Computer Graphics
1 Programming with OpenGL Part 2: Complete Programs.
OpenGL API 2D Graphic Primitives Angel Angel: Interactive Computer Graphics5E © Addison-Wesley
1 Perception, Illusion and VR HNRS 299, Spring 2008 Lecture 15 Creating 3D Models.
OpenGL: Introduction #include main() { OpenWindow() ; glClearColor(0.0, 0.0, 0.0, 0.0); glClear(GL_COLOR_BUFFER_BIT); glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0,
Introduction to Graphics Programming. Graphics API.
Graphics Graphics Korea University kucg.korea.ac.kr Graphics Programming 고려대학교 컴퓨터 그래픽스 연구실.
Introduction to OpenGL (INF 250) Veronika Solteszova et al., UiB Dept. of Informatics,
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.
Computer Graphics (Fall 2003) COMS 4160, Lecture 5: OpenGL 1 Ravi Ramamoorthi Many slides courtesy Greg Humphreys.
Computer Graphics Lecture 34. OpenGL Programming II Taqdees A. Siddiqi
Program Studi S-1 Teknik Informatika FMIPA Universitas Padjadjaran
Administrivia Back on track: canceling OpenGL lecture 2 Assignment 1
CSC Graphics Programming
The Human Visual System vs The Pinhole camera
Programming with OpenGL Part 1: Background
Programming with OpenGL Part 2: Complete Programs
Materi Anatomi OpenGL Fungsi GLUT Posisi Kamera Proyeksi
OpenGL API 2D Graphic Primitives
Programming with OpenGL Part 2: Complete Programs
Lab 3 Geometric Drawing Lab 3 Geometric Drawing.
Programming with OpenGL Part 1: Background
Drawing in the plane 455.
Introduction to OpenGL
Programming with OpenGL Part 2: Complete Programs
Programming with OpenGL Part 2: Complete Programs
Programming with OpenGL Part 1: Background
Programming with OpenGL Part 2: Complete Programs
OpenGL Background CS 4722.
Presentation transcript:

Using OpenGL

2 What is OpenGL? A software interface to graphics hardware It is a Graphics Rendering API (Application Programmer’s Interface) that is a set of function with well defined interface. OpenGL is intended for use with computer hardware that is designed and optimized for the display and manipulation of 3D graphics. Software-only implementations of OpenGL are also possible (MESA) 2

A History of OpenGL Was SGI’s Iris GL – basis for “Open”GL “Open” standard allowing for wide range hardware platforms OpenGL v1.0 (1992) OpenGL v1.1 (1995) OpenGL v1.5 “Mesa” – an Open source implementation of OpenGL (

4 The OpenGL ARB OpenGL Architecture Review Board (ARB) –Control license and conformance test of OpenGL The Khronos Group(after 2006) is industry consortium focused on the creation and maintenance of open media standards. Most ARB members are already members of Khronos. A vendor who wants to create and market an OpenGL implementation must first license OpenGL from The Khronos Group.

5 Useful Websites and Books Official Site Non official sites – BOOKS –OpenGL Red Book & –OpenGL Blue Book 5

6 Useful Links Online Reference manual sites GL and GLU GLUT GLUT.html 6

7 OpenGL API Functions OpenGL contains over 200 functions –Primitive functions : define the elements (eg. A point, line, polygon, etc) –Attribute functions : control the appearance of primitives (eg. colors, line types, light source, textures.) –Viewing functions : determine the properties of camera. Transformation –Windowing functions: not part of core OpenGL –Other functions 7

8 Window Management OpenGL is meant to be platform independent. i.e. OpenGL is window and operating system independent. OpenGL does not include any functions for window management, user interaction, and file I/O. Host environment is responsible for window management. 8

9 Related APIs GL –“core” library of OpenGL that is platform independent GLU (OpenGL Utility Library) –part of OpenGL –an auxiliary library that handles a variety of graphics accessory functions –NURBS, tessellators, quadric shapes, etc. AGL, GLX, WGL –glue between OpenGL and windowing systems GLUT (OpenGL Utility Toolkit) –utility toolkits that handle window managements –portable windowing API –not officially part of OpenGL

OpenGL API Hierarchy GLUT, JOGL GLU GL GLX, AGL or WGL X, Win32, Mac O/S Java Virtual Machine software and/or hardware application program OpenGL Motif widget or similar

Programming Convention : OpenGL Function Naming OpenGL functions all follow a naming convention that tells you which library the function is from, and how many and what type of arguments that the function takes

Programming Convention : OpenGL Function Naming glVertex3fv( v ) Number of components 2 - (x,y) 3 - (x,y,z) 4 - (x,y,z,w) Data Type b - byte ub - unsigned byte s - short us - unsigned short i - int ui - unsigned int f - float d - double Vector omit “v” for scalar form glVertex2f( x, y )

13 Programming Convention : OpenGL Function Naming Multiple forms of OpenGL functions to support the variety of data types –glVertex3i(ix, iy, iz) –glVertex3f(x, y, z) –glVertex2i(ix, iy) –glVertex2f(x, y) –.. –We shall use the notation glVertex*() to refer to all the forms of the vertex function 13

14 OpenGL Data TypeInternal Representation Literal Suffix GLbyte8-bit integerb GLshort16-bit integers GLint, GLsizei32-bit integeri GLfloat, GLclampf32-bit floating pointf GLdouble, GLclampd64-bit floating pointd GLubyte, GLboolean8-bit unsigned integerub GLushort16bit unsigned integerus GLuint, GLenum, GLbitfield 32bit unsigned integerui

15 General Structure of an OpenGL Program Configure and open a window Initialize OpenGL’s state Process user events Draw an image

16 2D Geometric Primitives Primitives – fundamental entities such as point and polygons Basic types of geometric primitives –Points –Line segments –Polygons 16

17 2D Geometric Primitives 17 GL_POINTS GL_LINESGL_LINE_STRIPGL_LINE_LOOP GL_POLYGON GL_QUADS GL_TRIANGLES GL_TRIANGLE_FAN All geometric primitives are specified by vertices

18 Geometry Commands glBegin(GLenum type) marks the beginning of a vertex-data list that describes a geometric primitives 18 glEnd (void) marks the end of a vertex-data list glVertex*(…) specifies vertex for describing a geometric object

19 Specifying Geometric Primitives glBegin( type ); glVertex*(…); …… glVertex*(…); glEnd(); 19 type determines how vertices are combined

20 Types

21 Types GL_POINTS GL_LINES : each successive pair for a ling segment GL_LINE_STRIP: vertices defining a sequence of line segments GL_LINE_LOOP: GL_LINE_STRIP + the last vertex connects to the first GL_POLYGON : sequence of vertices of polygon, filled GL_QUADS: each successive group of four vertices for a quadrilaterals GL_TRIANGLES: each successive group of three vertices for a triangle GL_TRIANGLE_FAN: first three vertices for the first triangle and each subsequent vertex with the first vertex and the previous vertex for the next triangle 21

22 Example 22 void drawSquare () { glClear(GL_COLOR_BUFFER_BIT); glBegin(GL_POLYGON); glVertex2f ( 0.0, 0.0 ); glVertex2f ( 1.0, 0.0 ); glVertex2f ( 1.1, 1.1 ); glVertex2f ( 0.0, 1.0 ); glEnd(); glFlush();// force the renderer to output the results }

23 Winding glFrontFace(GL_CCW);

24 Triangle Strips When drawing several connected triangles, you can save a lot of time by drawing a strip of connected triangles The pattern is V0, V1, V2; then V2, V1, V3; then V2, V3, V4; and so on.

25 Triangle Fans Produce a group of connected triangles that fan around a central point The first vertex, V0, forms the origin of the fan. After the first three vertices are used to draw the initial triangle, all subsequent vertices are used with the origin (V0) and the vertex immediately preceding it (Vn–1) to form the next triangle.

26 How OpenGL Works: The Conceptual Model Configure how OpenGL should draw stuff Draw stuff

27 Controlling OpenGL’s Drawing Set OpenGL’s rendering state –State controls how things are drawn shading – lighting texture maps – line styles (stipples) polygon patterns – transparency

28 The Power of Setting OpenGL State Appearance is controlled by setting OpenGL’s state.

29 Setting OpenGL State Three ways to set OpenGL state: 1.Set values to be used for processing vertices most common methods of setting state –glColor() / glIndex() –glNormal() –glTexCoord() state must be set before calling glVertex()

30 Setting OpenGL State (cont’d.) 2.Turning on a rendering mode glEnable() / glDisable() 3.Configuring the specifics of a particular rendering mode Each mode has unique commands for setting its values glMaterialfv()

31 OpenGL Color There are two color models in OpenGL –RGB Color (True Color) –Indexed Color (Color map) Colors are specified as floating-point numbers in the range [ 0.0, 1.0 ] 31

32 RGB Color Model 32 R, G, B components are stored for each pixel

33 How Many Colors? Color number = 33 For example: 4-bit color = 16 colors 8-bit color = 256 colors 24-bit color = million colors

34 How Much Memory? Buffer size = width * height *color depth 34 For example: If width = 640, height = 480, color depth = 24 bits Buffer size = (640 * 480 * 2) bytes If width = 640, height = 480, color depth = 32 bits Buffer size = (640 * 480 * 4) bytes

35 Alpha Component Alpha value A value indicating the pixels opacity 0 usually represents totally transparent and the 1 represents completely opaque Alpha buffer Hold the alpha value for every pixel Alpha values are commonly represented in 8 bits, in which case transparent to opaque ranges from 0 to

36 RGB Color Commands glColor*( … ) specifies vertex colors 36 glClearColor(r, g, b, a) sets current color for cleaning color buffer

37 Example 37 void drawLine (GLfloat *color) { glColor3fv ( color ); glBegin(GL_LINE); glVertex2f ( 0.0, 0.0 ); glVertex2f ( 1.0, 0.0 ); glEnd(); }

38 Example 38 void drawLine (GLfloat *color) { glBegin(GL_LINE); glColor3f(1.0,0.0,0.0 ); glVertex2f ( 0.0, 0.0 ); glColor3f(0.0,0.0,1.0); glVertex2f ( 1.0, 0.0 ); glEnd(); }

39 Color Interpolation glShadeModel(GL_SMOOTH); Or glShadeModel(GL_FLAT); - the last vertex color Linear interpolation for a line Bilinear interpolation for a polygons 39