Noggin (BYU Students, SIGGRAPH 2006). Introduction to OpenGL Programming Rick Skarbez, Instructor COMP 575 September 11, 2007.

Slides:



Advertisements
Similar presentations
Computer Graphics - Viewing -
Advertisements

02/17/05CISC640/440 OpenGL Tutorial1 OpenGL Tutorial CISC 640/440 Computer Graphics TA: Qi Li/Mani Thomas
MAT 594CM S2010Fundamentals of Spatial ComputingAngus Forbes Overview Goals of the course: 1. to introduce real-time 3D graphics programming with openGL.
Graphics Pipeline.
David Luebke5/16/2015 Administrivia l Back on track: canceling OpenGL lecture 2 l Assignment 1 –Greg Yukl found an alternate XForms site:
Viewing and Transformation
CSC 461: Lecture 51 CSC461 Lecture 5: Simple OpenGL Program Objectives: Discuss a simple program Discuss a simple program Introduce the OpenGL program.
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
Now Playing: Coulibaly Amadou & Mariam from Dimanche a Bamako Released August 2, 2005.
Now Playing: Homecoming Kanye West from Graduation Released September 11, 2007.
OpenGL (II). How to Draw a 3-D object on Screen?
CS 4731: Computer Graphics Lecture 11: 3D Viewing Emmanuel Agu.
3D Rendering with JOGL Introduction to Java OpenGL Graphic Library By Ricardo Veguilla
Introduction to 3D viewing 3D is just like taking a photograph!
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.
3D coordinate systems X Y Z Right-Hand Coordinate System X Y Z Left-Hand Coordinate System OpenGL uses this! Direct3D uses this!
GLWidget Description Jason Goffeney 3/8/2006. GLWidget The GLWidget class extends the Qt QGLWidget. The QGLWidget is a Qt Widget that happens to have.
Computer Graphics, KKU. Lecture 131 Transformation and Viewing in OpenGL.
The Viewing Pipeline (Chapter 4) 5/26/ Overview OpenGL viewing pipeline: OpenGL viewing pipeline: – Modelview matrix – Projection matrix Parallel.
Geometric transformations The Pipeline
2 COEN Computer Graphics I Evening’s Goals n Discuss the mathematical transformations that are utilized for computer graphics projection viewing.
CS 450: COMPUTER GRAPHICS REVIEW: INTRODUCTION TO COMPUTER GRAPHICS – PART 2 SPRING 2015 DR. MICHAEL J. REALE.
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,
Computer Graphics Bing-Yu Chen National Taiwan University.
OpenGL: Introduction Yanci Zhang Game Programming Practice.
Intro to OpenGL Transformations CS 445/645 Introduction to Computer Graphics David Luebke, Spring 2003.
Introduction to OpenGL  OpenGL is a graphics API  Software library  Layer between programmer and graphics hardware (and software)  OpenGL can fit in.
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.
OpenGL Viewing and Modeling Transformation Geb Thomas Adapted from the OpenGL Programming Guidethe OpenGL Programming Guide.
Viewing and Transformation. Pixel pipeline Vertex pipeline Course Map Transformation & Lighting Primitive assembly Viewport culling & clipping Texture.
CA 302 Computer Graphics and Visual Programming Lecture 2: Introduction to OpenGL Aydın Öztürk
The Camera Analogy ► Set up your tripod and point the camera at the scene (viewing transformation) ► Arrange the scene to be photographed into the desired.
Chapters 5 2 March Classical & Computer Viewing Same elements –objects –viewer –projectors –projection plane.
CGGM Lab. Tan-Chi Ho 2001 Viewing and Transformation.
Projections. Viewports Windows can have separate viewports void glViewport(GLint x, GLint y, GLsizei width, GLsizei height ) x, y - Specify the lower.
OpenGL: The Open Graphics Language Introduction By Ricardo Veguilla.
Taxonomy of Projections FVFHP Figure Taxonomy of Projections.
Chap 3 Viewing and Transformation
1 Programming with OpenGL Part 2: Complete Programs.
OpenGL API 2D Graphic Primitives Angel Angel: Interactive Computer Graphics5E © Addison-Wesley
Viewing and Projection. The topics Interior parameters Projection type Field of view Clipping Frustum… Exterior parameters Camera position Camera orientation.
Introduction to OpenGL Muhammad Aamir Khan Lecturer, DCS, UOP.
Computer Graphics I, Fall Programming with OpenGL Part 2: Complete Programs.
OpenGL LAB III.
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.
Computer Graphics (Fall 2003) COMS 4160, Lecture 5: OpenGL 1 Ravi Ramamoorthi Many slides courtesy Greg Humphreys.
Administrivia Back on track: canceling OpenGL lecture 2 Assignment 1
CSCE 441 Computer Graphics 3-D Viewing
Reference1. [OpenGL course slides by Rasmus Stenholt]
Programming with OpenGL Part 2: Complete Programs
Materi Anatomi OpenGL Fungsi GLUT Posisi Kamera Proyeksi
CS451Real-time Rendering Pipeline
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.
Computer Graphics, KKU. Lecture 13
Introduction to OpenGL
OpenGL program.
The View Frustum Lecture 10 Fri, Sep 14, 2007.
Programming with OpenGL Part 2: Complete Programs
Programming with OpenGL Part 2: Complete Programs
Computer Graphics 3Practical Lesson
Chapter 3 Viewing.
Programming with OpenGL Part 2: Complete Programs
Presentation transcript:

Noggin (BYU Students, SIGGRAPH 2006)

Introduction to OpenGL Programming Rick Skarbez, Instructor COMP 575 September 11, 2007

Announcements Reminder: Homework 1 is due Thursday Questions? Class next Tuesday (9/18) will be held in SN 014

Extended transformations to 3D Introduced some principles of computer animation Lasseter’s “Principles of Traditional Animation Applied to 3D Computer Graphics” How to create “The Illusion of Life” Last Time

Today Learning how to program in OpenGL OpenGL C/C++ GLUT, FLTK, Cocoa

OpenGL in Java I have never used Java for OpenGL programming I can’t be much help in getting it set up If you really want to try using OpenGL in Java The JOGL API Project Go there and follow the instructions

What is OpenGL? The standard specification defining an API that interfaces with the computer’s graphics system Cross-language Cross-platform Vendor-independent Competes with DirectX on Windows

The Rendering Datapath Computer Software Graphics Driver Frame Buffer Scanout Logic Display VGA / DVI OpenGL API PCI Express Bus High-Speed, Guaranteed Latency Interconnect 3D Hardware

An older version is available (free!) online: k/ k/ An older version is available (free!) online: k/ k/ The “Red Book”

Online Resources

The Camera Analogy

OpenGL’s World Camera Description (Intrinsic & Extrinsic) Scene Object Transforms What To Display On Screen Code Specified Parameters

Contexts and Viewports? Each OpenGL application creates a context to issue rendering commands to The application must also define a viewport, a region of pixels on the screen that can see the context Can be Part of a window An entire window The whole screen

OpenGL as a State Machine OpenGL is designed as a finite state machine Graphics system is a “black box” Most functions change the state of the machine One function runs input through the machine

OpenGL State Some attributes of the OpenGL state Current color Camera properties (location, orientation, field of view, etc.) Lighting model (flat, smooth, etc.) Type of primitive being drawn And many more...

Our First OpenGL Code... glClearColor(0.0, 0.0, 0.0, 0.0); glClear(GL_COLOR_BUFFER_BIT); glColor3f(1.0, 1.0, 1.0); glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0); glBegin(GL_POLYGON); glVertex2f(-0.5, -0.5); glVertex2f(-0.5, 0.5); glVertex2f(0.5, 0.5); glVertex2f(0.5, -0.5); glEnd(); glFlush();... glClearColor(0.0, 0.0, 0.0, 0.0); glClear(GL_COLOR_BUFFER_BIT); glColor3f(1.0, 1.0, 1.0); glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0); glBegin(GL_POLYGON); glVertex2f(-0.5, -0.5); glVertex2f(-0.5, 0.5); glVertex2f(0.5, 0.5); glVertex2f(0.5, -0.5); glEnd(); glFlush();...

OpenGL Input All inputs (i.e. geometry) to an OpenGL context are defined as vertex lists glVertex* * = nt OR ntv n - number (2, 3, 4) t - type (i = integer, f = float, etc.) v - vector

OpenGL Types SuffixData Type Typical Corresponding C-Language Type OpenGL Type Definition b8-bit integersigned charGLbyte s16-bit integershortGLshort i32-bit integerlongGLint, GLsizei f32-bit floating-pointfloatGLfloat, GLclampf d64-bit floating-pointdoubleGLdouble, GLclampd ub8-bit unsigned integerunsigned charGLubyte, GLboolean us16-bit unsigned integerunsigned shortGLushort ui32-bit unsigned integerunsigned long GLuint, GLenum, GLbitfield

OpenGL Input Examples: glVertex2i(5, 4); Specifies a vertex at location (5, 4) on the z = 0 plane “2” tells the system to expect a 2-vector (a vertex defined in 2D) “i” tells the system that the vertex will have integer locations

OpenGL Input More examples: glVertex3f(.25,.25,.5); double vertex[3] = {1.0,.33, }; glVertex3dv(vertex); “v” tells the system to expect the coordinate list in a single data structure, instead of a list of n numbers

OpenGL Primitive Types All geometry is specified by vertex lists But can draw multiple types of things Points Lines Triangles etc. The different things the system knows how to draw are the system primitives

Specifying the OpenGL Primitive Type glBegin(primitiveType); // A list of glVertex* calls goes here //... glEnd(); primitiveType can be any of several things See the next slide

OpenGL Primitive Types

OpenGL Primitives Example glBegin(GL_POLYGON); glVertex2f(0.0, 0.0); glVertex2f(0.0, 3.0); glVertex2f(3.0, 3.0); glVertex2f(4.0, 1.5); glVertex2f(3.0, 0.0); glEnd(); glBegin(GL_POLYGON); glVertex2f(0.0, 0.0); glVertex2f(0.0, 3.0); glVertex2f(3.0, 3.0); glVertex2f(4.0, 1.5); glVertex2f(3.0, 0.0); glEnd();

Color in OpenGL Monitors can have different color resolutions Black & white 256 color 16.8M color Want to specify color in a device- independent way

Color in OpenGL glColor4f(r, g, b, a); r, g, b, a - should all be between [0.0, 1.0] r, g, b - amounts of red, green, and blue a - alpha Defines how opaque a primitive is 0.0 = totally transparent, 1.0 = totally opaque Usually want a = 1.0

Finishing Up Your OpenGL Program OpenGL commands are not executed immediately They are put into a command buffer that gets fed to the hardware When you’re done drawing, need to send the commands to the graphics hardware glFlush() or glFinish()

glFlush vs. glFinish glFlush(); Forces all issued commands to begin execution Returns immediately (asynchronous) glFinish(); Forces all issued commands to execute Does not return until execution is complete (synchronous)

Matrices in OpenGL Vertices are transformed by 2 matrices: ModelView Maps 3D to 3D Transforms vertices from object coordinates to eye coordinates Projection Maps 3D to 2D (sort of) Transforms vertices from eye coordinates to clip coordinates

The ModelView Matrix In OpenGL, the viewing and modeling transforms are combined into a single matrix - the modelview matrix Viewing Transform - positioning the camera Modeling Transform - positioning the object Why? Consider how you would “translate” a fixed object with a real camera

Placing the Camera gluLookAt( GLdouble eyeX, GLdouble eyeY, GLdouble eyeZ, GLdouble midX, GLdouble midY, GLdouble midZ, GLdouble upX, GLdouble upY, GLdouble upZ) (eyeX, eyeY, eyeZ) - location of the viewpoint (midX, midY, midZ) - location of a point on the line of sight (upX, upY, upZ) - direction of the up vector By default the camera is at the origin, looking down negative z, and the up vector is the positive y axis

WARNING! OpenGL Matrices In C/C++, we are used to row-major matrices In OpenGL, matrices are specified in column-major order Row-Major OrderColumn-Major Order

Using OpenGL Matrices Use the following function to specify which matrix you are changing: glMatrixMode(whichMatrix); whichMatrix = GL_PROJECTION | GL_MODELVIEW To guarantee a “fresh start”, use glLoadIdentity(); Loads the identity matrix into the active matrix

Using OpenGL Matrices To load a user-defined matrix into the current matrix: glLoadMatrix{fd}(TYPE *m) To multiply the current matrix by a user defined matrix glMultMatrix{fd}(TYPE *m) SUGGESTION: To avoid row-/column- major confusion, specify matrices as m[16] instead of m[4][4]

Transforms in OpenGL OpenGL uses 4x4 matrices for all its transforms But you don’t have to build them all by hand! glRotate{fd}(angle, x, y, z) Rotates counter-clockwise by angle degrees about the vector (x, y, z) glTranslate{fd}(x, y, z) glScale{fd}(x, y, z)

In OpenGL, the last transform in a list is applied FIRST Think back to right-multiplication of transforms Example: glRotatef(45.0f, 0.0f, 0.0f, 0.0f); glTranslatef(10.0f, 0.0f, 0.0f); drawSomeVertices(); Translates first, then rotates WARNING!Order of Transforms

Projection Transforms The projection matrix defines the viewing volume Used for 2 things: Projects an object onto the screen Determines how objects are clipped The viewpoint (the location of the “camera”) that we’ve been talking about is at one end of the viewing volume

Projection Transforms Perspective Viewing volume is a truncated pyramid aka frustum Orthographic Viewing volume is a box Perspective Orthographic

Perspective Projection The most noticeable effect of perspective projection is foreshortening OpenGL provides several functions to define a viewing frustum glFrustum(...) gluPerspective(...)

glFrustum glFrustum(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble near, GLdouble far) (left, bottom, -near) and (right, top, -near) are the bottom-left and top-right corners of the near clip plane far is the distance to the far clip plane near and far should always be positive

gluPerspective This GL Utility Library function provides a more intuitive way (I think) to define a frustum gluPerspective(GLdouble fovy, GLdouble aspect, GLdouble near, GLdouble far) fovy - field of view in y (in degrees) aspect - aspect ratio (width / height) near and far - same as with glFrustum()

Orthographic Projection With orthographic projection, there is no foreshortening Distance from the camera does not change apparent size Again, there are several functions that can define an orthographic projection glOrtho() gluOrtho2D()

glOrtho glOrtho(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble near, GLdouble far) Arguments are the same as glPerspective() (left, bottom, -near) and (right, top, -near) are the bottom-left and top-right corners of the near clip plane near and far can be any values, but they should not be the same

gluOrtho2D This GL Utility Library function provides a more intuitive way (I think) to define a frustum gluOrtho2D(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top) (left, bottom) and (right, top) define the (x, y) coordinates of the bottom-left and top-right corners of the clipping region Automatically clips to between -1.0 and 1.0 in z

Viewport The viewport is the part of the window your drawing is displayed to By default, the viewport is the entire window Modifying the viewport is analogous to changing the size of the final picture From the camera analogy Can have multiple viewports in the same window for a split-screen effect

Setting the Viewport glViewport(int x, int y, int width, int height) (x, y) is the location of the origin (lower-left) within the window (width, height) is the size of the viewport The aspect ratio of the viewport should be the same as that of the viewing volume (0,0) width height (x,y) Viewport Window