OpenGL A Brief Overview. What is OpenGL? It is NOT a programming language. It is a Graphics Rendering API consisting of a set of functions with a well.

Slides:



Advertisements
Similar presentations
OpenGL CMSC340 3D Character Design & Animation. What is OpenGL? A low-level graphics library specification designed for use with the C and C++ provides…
Advertisements

Chapter 2: Graphics Programming
OpenGL (Graphics Library) Software Interface to graphics software Allows to create interactive programs that produce color images of moving 3D objects.
CSC 461: Lecture 51 CSC461 Lecture 5: Simple OpenGL Program Objectives: Discuss a simple program Discuss a simple program Introduce the OpenGL program.
#4: OpenGL Implementation & Project 2 CSE167: Computer Graphics TAs: Alex Kozlowski & Cameron Chrisman UCSD, Winter 2006.
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Programming with OpenGL Part 2: Complete Programs Ed Angel Professor of Computer Science,
OpenGL and Projections
Interactive 3D Graphics and Virtual Reality Introduction to OpenGL concepts Session 2.
3D Rendering with JOGL Introduction to Java OpenGL Graphic Library By Ricardo Veguilla
Introduction to OpenGL M. Ramanathan STTP CAD 2011Introduction to OpenGL.
Introduction to OpenGL Jian Huang This set of slides are extracted from the Interactive OpenGL Programming course given by Dave Shreine, Ed Angel and Vicki.
OpenGL A Brief Overview. What is OpenGL?  It is NOT a programming language.  It is a Graphics Rendering API consisting of a set of function with a well.
Reference1. [OpenGL course slides by Rasmus Stenholt]
CS380 LAB I OpenGL Donghyuk Kim Reference1. [OpenGL course slides by Rasmus Stenholt] Reference2. [
CAP 4703 Computer Graphic Methods Prof. Roy Levow Lecture 2.
3D coordinate systems X Y Z Right-Hand Coordinate System X Y Z Left-Hand Coordinate System OpenGL uses this! Direct3D uses this!
1 OpenGL Basics A Graphics Standard ©Mel Slater, Anthony Steed
Introduction to OpenGL and GLUT GLUT. What is OpenGL? An application programming interface (API) A (low-level) Graphics rendering API Generate high-quality.
Using OpenGL in Visual C++ Opengl32.dll and glu32.dll should be in the system folder Opengl32.dll and glu32.dll should be in the system folder Opengl32.lib.
CSE 470: Computer Graphics. 10/15/ Defining a Vertex A 2D vertex: glVertex2f(GLfloat x, GLfloat y); 2D vertexfloating pointopenGL parameter type.
Homogeneous Form, Introduction to 3-D Graphics Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Monday, October 20,
Introduction to OpenGL 1. 2 OpenGL A Graphics rendering API introduced in 1992 by Silicon Graphics Inc Provide the low-level functions to access graphics.
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.
Computing & Information Sciences Kansas State University CIS 536/636 Introduction to Computer Graphics Lecture 4 of 41 William H. Hsu Department of Computing.
OpenGL: Introduction Yanci Zhang Game Programming Practice.
Introduction to OpenGL and GLUT. What’s OpenGL? An Application Programming Interface (API) A low-level graphics programming API – Contains over 250 functions.
OpenGL The Viewing Pipeline: Definition: a series of operations that are applied to the OpenGL matrices, in order to create a 2D representation from 3D.
Viewing and Transformation. Pixel pipeline Vertex pipeline Course Map Transformation & Lighting Primitive assembly Viewport culling & clipping Texture.
Chapters 5 2 March Classical & Computer Viewing Same elements –objects –viewer –projectors –projection plane.
CGGM Lab. Tan-Chi Ho 2001 Viewing and Transformation.
Chun-Yuan Lin Introduction to OpenGL 2015/12/19 1 CG.
Chap 3 Viewing and Transformation
CS552: Computer Graphics Lecture 6: Viewing in 2D.
1 Programming with OpenGL Part 2: Complete Programs.
OpenGL API 2D Graphic Primitives Angel Angel: Interactive Computer Graphics5E © Addison-Wesley
CS559: Computer Graphics Lecture 12: OpenGL - Transformation Li Zhang Spring 2008.
CS559: Computer Graphics Lecture 12: OpenGL: ModelView Li Zhang Spring 2010.
Computer Graphics Comp 175 Chapter 2
CIS 681 Review: OpenGL. CIS 681 Command Syntax OpenGL commands start with a gl. This is followed by the base command such as Color. Followed by the number.
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 Based on GL (graphics library) by Silicon Graphics Inc. (SGI) Advantages: Runs on everything, including.
OpenGL CS418 Computer Graphics John C. Hart. OpenGL: Event-driven How in OpenGL? Programmer registers callback functions Callback function called when.
CS380 LAB II OpenGL Donghyuk Kim Reference1. [OpenGL course slides by Rasmus Stenholt] Reference2. [
OpenGL: The Open Graphics Language Technology and Historical Overview By Ricardo Veguilla.
INTRODUCTION TO OPENGL
Computer Graphics (Fall 2003) COMS 4160, Lecture 5: OpenGL 1 Ravi Ramamoorthi Many slides courtesy Greg Humphreys.
Program Studi S-1 Teknik Informatika FMIPA Universitas Padjadjaran
The Human Visual System vs The Pinhole camera
Reference1. [OpenGL course slides by Rasmus Stenholt]
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
OpenGL (Open Graphics Library) Mr. B.A.Swamy Assistant Professor Dept of CSE.
OpenGL A Brief Overview.
Lab 3 Geometric Drawing Lab 3 Geometric Drawing.
גרפיקה ממוחשבת: מבוא ל-OpenGL
Coordinate Systems and Transforming the Coordinates
Drawing in the plane 455.
Introduction to OpenGL
OpenGL program.
Programming with OpenGL Part 2: Complete Programs
Programming with OpenGL Part 2: Complete Programs
Programming with OpenGL Part 2: Complete Programs
OpenGL A Brief Overview.
Presentation transcript:

OpenGL A Brief Overview

What is OpenGL? It is NOT a programming language. It is a Graphics Rendering API consisting of a set of functions with a well defined interface. Whenever we say that a program is OpenGL- based or OpenGL applications, we mean that it is written in some programming language (such as C/C++ or Java) that makes calls to one or more of OpenGL libraries.

OpenGL & Alternative Based on GL (graphics library) by Silicon Graphics Inc. (SGI) ( Advantages: Runs on everything, including smart phones (OpenGL/ES) Alternatives: Microsoft’s Direct3D – limited to MS-Windows ( us/windows7/products/features/directx-11) us/windows7/products/features/directx-11 Sun’s Java3D – slower, implemented on top of OpenGL (

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

APP GLUT Library Layers OpenGL = GL + GLU – Basic low-level GL routines implemented using OS graphics routines – Time-saving higher-level GLU routines implemented using GL routines GLUT opens and manages OpenGL windows and adds helper functions OpenGL Extensions provide direct device-dependent access to hardware GL GLU OS Driver HW EXT

OpenGL API Functions OpenGL contains over 200 functions – Primitive functions: define the elements (e.g. points, lines, polygons, etc.) – Attribute functions: control the appearance of primitives (e.g. colors, line types, light source, textures, etc.) – Viewing functions: determine the properties of camera. Handle transformations. – Windowing functions: not part of core OpenGL (in GLUT) – Other functions

Libraries and Headers Library NameLibrary FileHeader FileNote OpenGL opengl32.lib (Win) -lgl (UNIX) gl.h“core” library Auxiliary library glu32.lib (Win) -lglu (UNIX) glu.h handles a variety of accessory functions Utility toolkitglut32.lib (Win) -lglut (UNIX) glut.h glaux.h window management & others

Function Naming Conventions glColor3f(…) library name, command name, # of arguments, argument type gl: OpenGL glu: GLU glut: GLUT f: the argument is float type i: the argument is integer type v: the argument requires a vector

A Sample Program void main (int argc, char **argv) { glutInit (&argc, argv); glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB); glutInitWindowSize (500, 500); glutCreateWindow (“My First Program"); myinit (); glutDisplayFunc ( display ); glutReshapeFunc ( resize ); glutKeyboardFunc ( key ); glutMainLoop (); } #include

1. Initialize & Create Window void main (int argc, char **argv) { glutInit (&argc, argv); // GLUT initialization glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB); // display model glutInitWindowSize (500, 500); // set window size glutCreateWindow (“My First Program”); // create window …… } Initiate a GLUT window…

2. Initialize OpenGL State void myinit(void) { glClearColor(1.0, 1.0, 1.0, 1.0); // background color glColor3f(1.0, 0.0, 0.0); // line color glMatrixMode(GL_PROJECTION); // set up viewing: glLoadIdentity(); // load identity matrix gluOrtho2D(0.0, 500.0, 0.0, 500.0);// specify Orthographic view glMatrixMode(GL_MODELVIEW);// go back to MV matrix } Set up the canvas for drawing, including the background color and view

3. Register Callback Functions void main (int argc, char **argv) { …… glutDisplayFunc ( display ); // display callback glutReshapeFunc ( resize ); // window resize callback glutKeyboardFunc ( key ); // keyboard callback …… } Event handling

(side note) GLUT Callback Functions Contents of window need to be refreshed glutDisplayFunc() Window is resized or moved glutReshapeFunc() Key action glutKeyboardFunc() Mouse button action glutMouseFunc() Mouse moves while a button is pressed glutMotionFunc() Mouse moves regardless of mouse button state glutPassiveMouseFunc() Called when nothing else is going on glutIdleFunc()

3.1 Rendering Callback void display( void ) { int k; glClear(GL_COLOR_BUFFER_BIT); for( k=0; k<5000; k++) …… } Here is the place you do the drawing!!!

3.2 Window Resize Callback void resize(int w, int h) { …… display(); }

3.3 Keyboard Input Callback void key( char mkey, int x, int y ) { switch( mkey ) { case ‘q’ : exit( EXIT_SUCCESS ); break; …… }

4. Event Process Loop This is where your application receives events, and schedules when callback functions are called void main (int argc, char **argv) { …… glutMainLoop(); }

Viewport Coordinates Physical per-pixel integer coordinates Also called screen or device coordinates glViewport(x,y,w,h) – x,y – lower left pixel (integers) – w – width – h – height Sometimes (0,0) is in the upper left corner (e.g. for mouse input) (0,0)(HRES-1,0) (HRES-1, VRES-1) (0,VRES-1)

Window Coordinates Logical, mathematical floating-point coordinates glOrtho(l,r,b,t,n,f) (for 3D) – left, right, bottom, top – near, far: limits depth For 2D use gluOrtho2D(l,r,b,t) calls glOrtho(l,r,b,t,-1,1) To use per-pixel coordinates, call: gluOrtho2D(-.5,-.5,w-.5,h-.5); (-1,-1)(1,-1) (1,1) (-1,1)

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

GL_POINTS GL_LINES GL_LINE_STRIP GL_POLYGON GL_QUADS GL_TRIANGLES GL_TRIANGLE_FAN All geometric primitives are specified by vertices 2D Geometric Primitives GL_LINE_LOOP

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

An Example void drawSquare (GLfloat *color) { glColor3fv( color ); // sets the color of the square 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 }

Points glBegin(GL_POINTS); glVertex2f(-.6,1.); glVertex2f(-.6,.6); glVertex2f(-.2,.6); glVertex2f(-.2,-.6); glVertex2f(-.6,-.6); glVertex2f(-.6,-1.); glVertex2f(.6,-1.); glVertex2f(.6,-.6); glVertex2f(.2,-.6); glVertex2f(.2,.6); glVertex2f(.6,.6); glVertex2f(.6,1.); glEnd(); (-1,-1)(1,-1) (1,1) (-1,1)

Lines glBegin(GL_LINES); glVertex2f(-.6,1.); glVertex2f(-.6,.6); glVertex2f(-.2,.6); glVertex2f(-.2,-.6); glVertex2f(-.6,-.6); glVertex2f(-.6,-1.); glVertex2f(.6,-1.); glVertex2f(.6,-.6); glVertex2f(.2,-.6); glVertex2f(.2,.6); glVertex2f(.6,.6); glVertex2f(.6,1.); glEnd(); (-1,-1)(1,-1) (1,1) (-1,1)

Line Strip glBegin(GL_LINE_STRIP); glVertex2f(-.6,1.); glVertex2f(-.6,.6); glVertex2f(-.2,.6); glVertex2f(-.2,-.6); glVertex2f(-.6,-.6); glVertex2f(-.6,-1.); glVertex2f(.6,-1.); glVertex2f(.6,-.6); glVertex2f(.2,-.6); glVertex2f(.2,.6); glVertex2f(.6,.6); glVertex2f(.6,1.); glEnd(); (-1,-1)(1,-1) (1,1) (-1,1)

Line Loop glBegin(GL_LINE_LOOP); glVertex2f(-.6,1.); glVertex2f(-.6,.6); glVertex2f(-.2,.6); glVertex2f(-.2,-.6); glVertex2f(-.6,-.6); glVertex2f(-.6,-1.); glVertex2f(.6,-1.); glVertex2f(.6,-.6); glVertex2f(.2,-.6); glVertex2f(.2,.6); glVertex2f(.6,.6); glVertex2f(.6,1.); glEnd(); (-1,-1)(1,-1) (1,1) (-1,1)

Polygon glBegin(GL_POLYGON); glVertex2f(-.6,1.); glVertex2f(-.6,.6); glVertex2f(-.2,.6); glVertex2f(-.2,-.6); glVertex2f(-.6,-.6); glVertex2f(-.6,-1.); glVertex2f(.6,-1.); glVertex2f(.6,-.6); glVertex2f(.2,-.6); glVertex2f(.2,.6); glVertex2f(.6,.6); glVertex2f(.6,1.); glEnd(); (-1,-1)(1,-1) (1,1) (-1,1) OpenGL only supports convex polygons (and really only triangles)

Quads glBegin(GL_QUADS); glVertex2f(-.6,1.); glVertex2f(-.6,.6); glVertex2f(-.2,.6); glVertex2f(-.2,-.6); glVertex2f(-.6,-.6); glVertex2f(-.6,-1.); glVertex2f(.6,-1.); glVertex2f(.6,-.6); glVertex2f(.2,-.6); glVertex2f(.2,.6); glVertex2f(.6,.6); glVertex2f(.6,1.); glEnd(); (-1,-1)(1,-1) (1,1) (-1,1)

Quads glBegin(GL_QUADS); glVertex2f(-.6,1.); glVertex2f(-.6,.6); glVertex2f(-.6,-.6); glVertex2f(-.6,-1.); glVertex2f(.6,-1.); glVertex2f(.6,-.6); glEnd(); glVertex2f(-.2,.6); glVertex2f(-.2,-.6); glVertex2f(.2,-.6); glVertex2f(.2,.6); glVertex2f(.6,.6); glVertex2f(.6,1.);

Quads glBegin(GL_QUADS); glVertex2f(-.6,1.); glVertex2f(-.6,.6); glVertex2f(.6,.6); glVertex2f(.6,1.); glVertex2f(-.6,-.6); glVertex2f(-.6,-1.); glVertex2f(.6,-1.); glVertex2f(.6,-.6); glVertex2f(-.2,.6); glVertex2f(-.2,-.6); glVertex2f(.2,-.6); glVertex2f(.2,.6); glEnd(); (-1,1) (-1,-1)(1,-1) (1,1) (-1,1)

Triangles glBegin(GL_TRIANGLES); glVertex2f(-.6,1.); glVertex2f(-.6,.6); glVertex2f(-.2,.6); glVertex2f(-.2,-.6); glVertex2f(-.6,-.6); glVertex2f(-.6,-1.); glVertex2f(.6,-1.); glVertex2f(.6,-.6); glVertex2f(.2,-.6); glVertex2f(.2,.6); glVertex2f(.6,.6); glVertex2f(.6,1.); glEnd(); (-1,-1)(1,-1) (1,1) (-1,1)

Triangles glBegin(GL_TRIANGLES); glVertex2f(-.6,1.); glVertex2f(-.6,.6); glVertex2f(-.2,.6); glVertex2f(-.6,1.); glVertex2f(-.2,.6); glVertex2f(.6,1.); glVertex2f(-.2,.6); glVertex2f(.2,.6); glVertex2f(.6,1.); glVertex2f(.2,.6); glVertex2f(.6,.6); glVertex2f(.6,1.); … glEnd(); (-1,-1)(1,-1) (1,1) (-1,1)

Triangle Strip glBegin(GL_TRIANGLE_STRIP); glVertex2f(-.6,1.); glVertex2f(-.6,.6); glVertex2f(-.2,.6); glVertex2f(-.2,-.6); glVertex2f(-.6,-.6); glVertex2f(-.6,-1.); glVertex2f(.6,-1.); glVertex2f(.6,-.6); glVertex2f(.2,-.6); glVertex2f(.2,.6); glVertex2f(.6,.6); glVertex2f(.6,1.); glEnd(); (-1,-1)(1,-1) (1,1) (-1,1)

Triangle Strip glBegin(GL_TRIANGLE_STRIP); glVertex2f(-.6,1.); glVertex2f(.6,1.); glVertex2f(-.2,.6); glVertex2f(.2,.6); glVertex2f(-.2,-.6); glVertex2f(.2,-.6); glVertex2f(.6,-1.); glVertex2f(.6,-.6); glEnd(); … (-1,-1)(1,-1) (1,1) (-1,1) First two vertices prime the pump, then every new vertex creates a triangle connecting it to the previous two vertices

Triangle Fan glBegin(GL_TRIANGLE_FAN); glVertex2f(-.2,.6); glVertex2f(-.6,.6); glVertex2f(-.6,1.); glVertex2f(.6,1.); glVertex2f(.2,.6); glVertex2f(.2,-.6); glVertex2f(-.2,-.6); glEnd(); … (-1,-1)(1,-1) (1,1) (-1,1) First two vertices prime the pump, then every new vertex creates a triangle connecting it to the previous vertex and the first vertex

Assigning Color glColor3f(0,0,1); glBegin(GL_POLYGON); glVertex2f(-1,1); glVertex2f(-1,-1); glVertex2f(1,-1); glEnd(); glColor3f(1,0,0); glBegin(GL_POLYGON); glVertex2f(-1,1); glVertex2f(-1,-1); glVertex2f(1,-1); glEnd(); glColor3f(0,0,0); glBegin(GL_LINE_LOOP); glVertex2f(-1,1); glVertex2f(-1,-1); glVertex2f(1,-1); glEnd(); glBegin(GL_POLYGON); glColor3f(0,1,0); glVertex2f(-1,1); glColor3f(0,0,1); glVertex2f(-1,-1); glColor3f(1,0,0); glVertex2f(1,-1); glEnd();

Graphics Pipeline of OpenGL Homogeneous Divide Model Coords Model Xform World Coords Viewing Xform Still Clip Coords Clipping Window Coordinates Window Coordinates Window to Viewport Window to Viewport Coordinates Viewport Coordinates Clip Coords Viewing Coords Perspective Distortion

Coordinate Systems and Transformation Identify which matrix we wish to alter Set the matrix to an identity matrix Alter the matrix to form the desired matrix glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluOrtho2D(-1.0, 1.0, -1.0, 1.0);

glMatrixMode(GLenum mode); – Identify which matrix we wish to alter – The mode is usually GL_MODELVIEW, GL_PROJECTION glLoadIdentity(); – Set the current matrix to an identity matrix Coordinate Systems and Transformation

Transformations and Camera Analogy Modeling transformation – Positioning and moving the model. Viewing transformation – Positioning and aiming camera in the world. Projection transformation – Adjusting the lens of the camera. Viewport transformation – Enlarging or reducing the physical photograph.

Transformations in OpenGL Transformations are specified by matrix operations. Desired transformation can be obtained by a sequence of simple transformations that can be concatenated together. Transformation matrix is usually represented by 4x4 matrix (homogeneous coordinates). Provides matrix stacks for each type of supported matrix to store matrices.

Specifying Operations (1) Translation glTranslate {fd} (TYPE x, TYPE y, TYPE z) Multiplies the current matrix by a matrix that translates an object by the given x, y, z.

Specifying Operations (2) Scaling glScale {fd} (TYPE x, TYPE y, TYPE z) Multiplies the current matrix by a matrix that scales an object by the given x, y, z.

Specifying Operations (3) Rotation glRotate {fd} (TYPE angle, TYPE x, TYPE y, TYPE z) Multiplies the current matrix by a matrix that rotates an object in a counterclockwise direction about the ray from origin through the point by the given x, y, z. The angle parameter specifies the angle of rotation in degrees.

Order of Transformations The transformation matrices appear in reverse order to that in which the transformations are applied. In OpenGL, the transformation specified most recently is the one applied first.

Viewing-Modeling Transformation If given an object, and we want to render it from a viewpoint, what information do we have to have? – Viewing position – Which way I am looking at – Which way is “up” …..

Default Viewing +X +Z +Y default negative By default, the camera is at the origin, looking down the negative z-axis

Where are we and what are we looking at? x y z x y z Eyepoint (eye x, eye y, eye z ) Model View-up vector (up x, up y, up z ) Loot at (at x, at y, at z )

Viewing in OpenGL Look-At Function gluLookAt ( eye x, eye y, eye z, at x, at y, at z, up x, up y, up z ) ModelView Defines a viewing matrix and multiplies the current matrix by it. Alters the ModelView matrix.

Projection Transformation Projection & Viewing Volume Projection Transformation Viewpoint Transformation

Perspective Projection Volume Far-plane: zFar Near-plane: zNear Viewing volume h w aspect ratio = w/h y z x fovy

Perspective Projection Commands glFrustum( left, right, bottom, top, zNear, zFar ) Projection Creates a matrix for a perspective viewing frustum and multiplies the current matrix by it. Alters the Projection matrix.

gluPerspective( fovy, aspect, zNear, zFar ) Alternative to glFrustum(..). Creates a matrix for an perspective viewing frustum and multiplies the current matrix by it. Alters the Projection matrix. Note: fovy is the field of view (fov) angle between the top and bottom planes of the clipping volume. aspect is the aspect ratio Perspective Projection Commands

Enabling GL Features Features – lighting, hidden-surface removal, texture mapping, etc… Each feature will slow down the rendering process. We can enable/disable each feature individually void glEnable(GLenum feature) void glDisable(GLenum feature) E.g. glEnable(GL_LIGHTING);

Enabling GL Features GL_ALPHA_TEST If enabled, do alpha testing. GL_AUTO_NORMAL If enabled, generate normal vectors when either GL_MAP2_VERTEX_3 or GL_MAP2_VERTEX_4 is used to generate vertices. See glMap2. GL_BLEND If enabled, blend the incoming RGBA color values with the values in the color buffers.. GL_CLIP_PLANE i If enabled, clip geometry against user-defined clipping plane i.. GL_COLOR_LOGIC_OP If enabled, apply the currently selected logical operation to the incoming RGBA color and color buffer values. GL_COLOR_MATERIAL If enabled, have one or more material parameters track the current color. GL_COLOR_TABLE If enabled, preform a color table lookup on the incoming RGBA color values. GL_CONVOLUTION_1D If enabled, perform a 1D convolution operation on incoming RGBA color values. GL_CONVOLUTION_2D If enabled, perform a 2D convolution operation on incoming RGBA color values. ……

Double Buffering Use two buffers: front buffer and back buffer to guarantee the displaying of a fully redrawn buffer image glutSwapBuffers(); – Replace glFlush() by glutSwapBuffer() in the display callback if using double buffering

Advanced Topics Lighting Texture Mapping Plotting Implicit Functions Shadows Fog Picking (object selection) GUI (glut pop-up menus, glui library) Reference links given on slide 3

main function

OpenGL header files and libraries

GLUI interface libraries

Acknowledgment Thanks for materials from – Dr. John C. Hart – Dr. Eugene Zhang – Dr. Mike Bailey

Viewport – The region within the window that will be used for drawing the clipping area – By default, it is set to the entire rectangle of the window that is opened – Measured in the window coordinates, which reflect the position of pixels on the screen related to the lower-left corner of the window

Viewport Transformation A viewpoint is defined as the same size as the window A viewpoint is defined as half the size of the window h w h w

Viewport Commands glViewport( x, y, width, height ) Defines an area of the window into which the final image is mapped (x, y) specifies the lower-left corner of the viewport (width, height) specifies the size of the viewport rectangle

Indexed Face Set Popular file format – VRML, Wavefront “.obj”, etc. Ordered list of vertices – Prefaced by “v” (Wavefront) – Spatial coordinates x,y,z – Index given by order List of polygons – Prefaced by “f” (Wavefront) – Ordered list of vertex indices – Length = # of sides – Orientation given by order v x 1 y 1 z 1 v x 2 y 2 z 2 v x 3 y 3 z 3 v x 4 y 4 z 4 f f (x1,y1,z1)(x1,y1,z1) (x2,y2,z2)(x2,y2,z2) (x3,y3,z3)(x3,y3,z3) (x4,y4,z4)(x4,y4,z4)

Other Attributes Vertex normals – Prefixed w/ “vn” (Wavefront) – Contains x,y,z of normal – Not necessarily unit length – Not necessarily in vertex order – Indexed as with vertices Texture coordinates – Prefixed with “vt” (Wavefront) – Not necessarily in vertex order – Contains u,v surface parameters Faces – Uses “/” to separate indices – Vertex “/” normal “/” texture – Normal and texture optional – Can eliminate normal with “//” v x 0 y 0 z 0 v x 1 y 1 z 1 v x 2 y 2 z 2 vn a 0 b 0 c 0 vn a 1 b 1 c 1 vn a 2 b 2 c 2 vt u 0 v 0 vt u 1 v 1 vt u 2 v 2 (x 0,y 0,z 0 ) (a 0,b 0,c 0 ) (u 0,v 0 ) (x1,y1,z1)(a1,b1,c1)(u1,v1)(x1,y1,z1)(a1,b1,c1)(u1,v1) (x2,y2,z2)(a2,b2,c2)(u2,v2)(x2,y2,z2)(a2,b2,c2)(u2,v2) f 0/0/0 1/1/1 2/2/2f 0/0/0 1/0/1 2/0/2

Three Views of OpenGL Programmer’s view – Specify a set of objects to render – Describe the properties of these objects – Define how these objects should be viewed State machine – States determine how the inputs are processed. – Change a state (such as color) by using state changing functions OpenGL uses Rendering Pipeline Model – Models -> Transformer -> Clipper -> Projector -> Rasterizer -> Image

2D Viewing Where do we draw the 2D object? – Assume that we draw objects on an infinite sheet of paper – Then we need to specify clipping region and project these 2D objects to the screen void gluOrtho2D(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top);

Saving the State State changing functions – overwrites the state variables We can store previous state values for later use – Matrix stacks void glPushMatrix() void glPopMatrix() – Attribute stacks void glPishAttrib(GLbitfield mask) void glPopAttrib()

Saving the State glMatrix(GL_PROJECTION) // set projection matrix // draw scene glPushMatrix(); // change the project matrix //draw scene glPopMatrix();