Intro to OpenGL Transformations CS 445/645 Introduction to Computer Graphics David Luebke, Spring 2003.

Slides:



Advertisements
Similar presentations
Computer Graphics - Viewing -
Advertisements

GR2 Advanced Computer Graphics AGR
SI23 Introduction to Computer Graphics
02/17/05CISC640/440 OpenGL Tutorial1 OpenGL Tutorial CISC 640/440 Computer Graphics TA: Qi Li/Mani Thomas
OpenGL: Simple Use Open a window and attach OpenGL to it Set projection parameters (e.g., field of view) Setup lighting, if any Main rendering loop –Set.
MAT 594CM S2010Fundamentals of Spatial ComputingAngus Forbes Overview Goals of the course: 1. to introduce real-time 3D graphics programming with openGL.
David Luebke5/16/2015 Administrivia l Back on track: canceling OpenGL lecture 2 l Assignment 1 –Greg Yukl found an alternate XForms site:
Based on slides created by Edward Angel
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Computer Viewing Ed Angel Professor of Computer Science, Electrical and Computer Engineering,
CS 352: Computer Graphics Chapter 5: Viewing. Interactive Computer GraphicsChapter Overview Specifying the viewpoint Specifying the projection Types.
OpenGL and Projections
Further Programming for 3D applications CE Introduction to Further Programming for 3D application Bob Hobbs Faculty of Computing, Engineering and.
3.1si31_2001 SI31 Advanced Computer Graphics AGR Lecture 3 Viewing Transformation Getting Started with OpenGL Introduction to Projections.
Sep 30, I3I3DG&VR CE00539-m Interactive 3D Graphics and Virtual Reality Bob Hobbs Faculty of Computing, Engineering and Technology Staffordshire.
OpenGL (II). How to Draw a 3-D object on Screen?
CS 4731: Computer Graphics Lecture 11: 3D Viewing Emmanuel Agu.
Rendering Pipeline Aaron Bloomfield CS 445: Introduction to Graphics Fall 2006 (Slide set originally by Greg Humphreys)
3D Rendering with JOGL Introduction to Java OpenGL Graphic Library By Ricardo Veguilla
Introduction to 3D viewing 3D is just like taking a photograph!
3D coordinate systems X Y Z Right-Hand Coordinate System X Y Z Left-Hand Coordinate System OpenGL uses this! Direct3D uses this!
Introduction to Computer Graphics CS 445 / 645 Lecture 4 OpenGL OpenGL OpenGL Programming Guide.
1 OpenGL Basics A Graphics Standard ©Mel Slater, Anthony Steed
INTRO TO COMPUTER GRAPHICS TEXT EDWARD ANGEL: EDITION 5 CS770/870
OpenGL Matrices and Transformations Angel, Chapter 3 slides from AW, Red Book, etc. CSCI 6360.
The Viewing Pipeline (Chapter 4) 5/26/ Overview OpenGL viewing pipeline: OpenGL viewing pipeline: – Modelview matrix – Projection matrix Parallel.
Image Synthesis Rabie A. Ramadan, PhD 2. 2 Java OpenGL Using JOGL: Using JOGL: Wiki: You can download JOGL from.
Geometric transformations The Pipeline
Viewing Angel Angel: Interactive Computer Graphics5E © Addison-Wesley
OpenGL and Parametric Curves Advanced Multimedia Technology: Computer Graphics Yung-Yu Chuang 2005/12/21 with slides by Brian Curless, Zoran Popovic, Robin.
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,
CS 445 / 645 Introduction to Computer Graphics Lecture 4 OpenGL Intro Assignment 1 Lecture 4 OpenGL Intro Assignment 1.
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.
The Rendering Pipeline CS 445/645 Introduction to Computer Graphics David Luebke, Spring 2003.
Computer Graphics I, Fall 2010 Computer Viewing.
Representation. Objectives Introduce concepts such as dimension and basis Introduce coordinate systems for representing vectors spaces and frames for.
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.
Image Synthesis Rabie A. Ramadan, PhD 4. 2 Review Questions Q1: What are the two principal tasks required to create an image of a three-dimensional scene?
OpenGL Viewing and Modeling Transformation Geb Thomas Adapted from the OpenGL Programming Guidethe OpenGL Programming Guide.
2 COEN Computer Graphics I Evening’s Goals n Discuss viewing and modeling transformations n Describe matrix stacks and their uses n Show basic geometric.
Viewing and Transformation. Pixel pipeline Vertex pipeline Course Map Transformation & Lighting Primitive assembly Viewport culling & clipping Texture.
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.
OpenGL: The Open Graphics Language Introduction By Ricardo Veguilla.
David Luebke1/5/2016 CS 551 / 645: Introductory Computer Graphics David Luebke
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Classical Viewing Ed Angel Professor of Computer Science, Electrical and Computer Engineering,
Classical Viewing Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico.
Transformations: Projection CS 445/645 Introduction to Computer Graphics David Luebke, Spring 2003.
Chap 3 Viewing and Transformation
Lecture 7 Midterm Review. OpenGL Libraries gl: Basic OpenGL library, e.g. primitives. glu: OpenGL Utility library, a set of functions to create texture.
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.
Viewing Angel Angel: Interactive Computer Graphics5E © Addison-Wesley
CS5500 Computer Graphics March 20, Computer Viewing Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts.
Geometric Transformations Ceng 477 Introduction to Computer Graphics Computer Engineering METU.
CSC Graphics Programming Budditha Hettige Department of Statistics and Computer Science.
OpenGL LAB III.
OpenGL: The Open Graphics Language Technology and Historical Overview By Ricardo Veguilla.
Introduction to 3-D Viewing Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Monday, October 27, 2003.
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
Viewing.
Computer Viewing.
Isaac Gang University of Mary Hardin-Baylor
Rendering Pipeline Aaron Bloomfield CS 445: Introduction to Graphics
Reference1. [OpenGL course slides by Rasmus Stenholt]
Modeling 101 For the moment assume that all geometry consists of points, lines and faces Line: A segment between two endpoints Face: A planar area bounded.
Projection in 3-D Glenn G. Chappell
Introduction to OpenGL
University of New Mexico
Computer Graphics 3Practical Lesson
Presentation transcript:

Intro to OpenGL Transformations CS 445/645 Introduction to Computer Graphics David Luebke, Spring 2003

David Luebke 2 11/17/2015 Admin ● Assignment 1 ■ Note: changed due date AGAIN (sorry): Mon 3 Feb ■ Lab logistics: ○ Q: How many are planning to use the lab as their primary programming location? ○ Remember to reboot computer when done

David Luebke 3 11/17/2015 Admin ● Paired projects for CS 445: ■ Recommend XP “pair programming” model, especially for assignment 1 ■ 1 turn-in, 1 grade, no exceptions, no negotiating ○ This means your highest priority is to find a way to work successfully together! ○ Bring any problems to my attention sooner rather than later ■ Late days taken affect both students equally ■ Tips on working in groups: ■ Pair programming description/advice/advocacy:

David Luebke 4 11/17/2015 Admin ● Peer evaluations for CS 445 ■ After each assignment you will evaluate your partner: ○ Effort ○ Shows up for meetings ○ Easy to work with ○ Programming ability ○ Overall contribution ■ Peer evaluations affect an end-of-semester “instructor evaluation” grade, which is worth 10% of your final grade

David Luebke 5 11/17/2015 Introducing OpenGL ● Recall the rendering pipeline: ■ Transform geometry (object  world, world  eye) ■ Calculate surface lighting ■ Apply perspective projection (eye  screen) ■ Clip to the view frustum ■ Perform visible-surface processing ● Implementing all this is a lot of work (as you’ll find) ● OpenGL provides a standard implementation ■ So why study the basics?

David Luebke 6 11/17/2015 OpenGL Design Goals ● SGI’s design goals for OpenGL: ■ High-performance (hardware-accelerated) graphics API ■ Some hardware independence ■ Natural, terse API with some built-in extensibility ● OpenGL has become a standard because: ■ It doesn’t try to do too much ○ Only renders the image, doesn’t manage windows, etc. ○ No high-level animation, modeling, sound (!), etc. ■ It does enough ○ Useful rendering effects + high performance ■ It was promoted by SGI (& Microsoft, half-heartedly), is now promoted/supported by NVIDIA, ATI, etc. ■ It doesn’t change every year (like DirectX, it’s main competitor)

David Luebke 7 11/17/2015 OpenGL: Conventions ● Functions in OpenGL start with gl ■ Most functions just gl (e.g., glColor() ) ■ Functions starting with glu are utility functions (e.g., gluLookAt() ) ○ Note that GLU functions can always be composed entirely from core GL functions ■ Functions starting with glut are from the GLUT library, built on top of OpenGL and WGL (Windows) or X (Linux) for window management, mouse and keyboard events, etc. ○ Created and distributed as an entirely different library

David Luebke 8 11/17/2015 OpenGL: Conventions ● Function names indicate argument type and number ■ Functions ending with f take floats ■ Functions ending with i take ints ■ Functions ending with b take bytes ■ Functions ending with ub take unsigned bytes ■ Functions that end with v take an array. ● Examples ■ glColor3f() takes 3 floats ■ glColor4fv() takes an array of 4 floats

David Luebke 9 11/17/2015 OpenGL: Simple Use ● Open a window and attach OpenGL to it ● Set projection parameters (e.g., field of view) ● Setup lighting, if any ● Main rendering loop ■ Set camera pose with gluLookAt() ○ Camera position specified in world coordinates ■ Render polygons of model ○ Use modeling matrices to transform vertices in world coordinates

David Luebke 10 11/17/2015 OpenGL: Simple Use ● Open a window and attach OpenGL to it ■ FLTK/GLUT (assignment 0) ● Set projection parameters (e.g., field of view) ● Setup lighting, if any ● Main rendering loop ■ Set camera pose with gluLookAt() ○ Camera position specified in world coordinates ■ Render polygons of model ○ Use modeling matrices to transform vertices in world coordinates

David Luebke 11 11/17/2015 OpenGL: Simple Use ● Open a window and attach OpenGL to it ● Set projection parameters (e.g., field of view) ● Setup lighting, if any ● Main rendering loop ■ Set camera pose with gluLookAt() ○ Camera position specified in world coordinates ■ Render polygons of model ○ Use modeling matrices to transform vertices in world coordinates

David Luebke 12 11/17/2015 OpenGL: Perspective Projection ● Typically, we use a perspective projection ■ Distant objects appear smaller than near objects ■ Vanishing point at center of screen ■ Defined by a view frustum (draw it) ● Other projections: orthographic, isometric

David Luebke 13 11/17/2015 OpenGL: Perspective Projection ● In OpenGL: ■ Projections implemented by projection matrix ■ gluPerspective() creates a perspective projection matrix: glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(vfov, aspect, near, far); ● Parameters to gluPerspective() : ■ vfov : vertical field of view ■ aspect : window width/height ■ near, far : distance to near & far clipping planes More on these in a bit

David Luebke 14 11/17/2015 OpenGL: Simple Use ● Open a window and attach OpenGL to it ● Set projection parameters (e.g., field of view) ● Setup lighting, if any ● Main rendering loop ■ Set camera pose with gluLookAt() ○ Camera position specified in world coordinates ■ Render polygons of model ○ Use modeling matrices to transform vertices in world coordinates

David Luebke 15 11/17/2015 OpenGL: Lighting ● Simplest option: change the current color between polygons or vertices ■ glColor() sets the current color ● Or OpenGL provides a simple lighting model: ■ Set parameters for light(s) ○ Intensity, position, direction & falloff (if applicable) ■ Set material parameters to describe how light reflects from the surface ● Won’t go into details now; check the red book if interested

David Luebke 16 11/17/2015 OpenGL: Simple Use ● Open a window and attach OpenGL to it ● Set projection parameters (e.g., field of view) ● Setup lighting, if any ● Main rendering loop ■ Set camera pose with gluLookAt() ○ Camera position specified in world coordinates ■ Render polygons of model ○ Use modeling matrices to transform vertices in world coordinates

David Luebke 17 11/17/2015 OpenGL: Specifying Viewpoint ● glMatrixMode(GL_MODELVIEW); ● glLoadIdentity(); ● gluLookAt(eyeX, eyeY, eyeZ, lookX, lookY, lookZ, upX, upY, upZ); ■ eye[XYZ ]: camera position in world coordinates ■ look[XYZ] : a point centered in camera’s view ■ up[XYZ] : a vector defining the camera’s vertical ● Creates a matrix that transforms points in world coordinates to camera coordinates ■ Camera at origin ■ Looking down -Z axis ■ Up vector aligned with Y axis (actually Y-Z plane) More on these in a bit

David Luebke 18 11/17/2015 OpenGL: Specifying Geometry ● Simple case first: object vertices already in world coordinates ● Geometry in OpenGL consists of a list of vertices in between calls to glBegin() and glEnd() ■ A simple example: telling GL to render a triangle glBegin(GL_POLYGON); glVertex3f(x1, y1, z1); glVertex3f(x2, y2, z2); glVertex3f(x3, y3, z3); glEnd(); ■ Usage: glBegin( geomtype ) where geomtype is: ○ Points, lines, polygons, triangles, quadrilaterals, etc...

David Luebke 19 11/17/2015 OpenGL: More Examples ● Example: GL supports quadrilaterals: glBegin(GL_QUADS); glVertex3f(-1, 1, 0); glVertex3f(-1, -1, 0); glVertex3f(1, -1, 0); glVertex3f(1, 1, 0); glEnd(); ■ This type of operation is called immediate-mode rendering; each command happens immediately ■ Why do you suppose OpenGL uses a series of glVertex() calls instead of one polygon function that takes all its vertices as arguments?

David Luebke 20 11/17/2015 OpenGL: Front/Back Rendering ● Each polygon has two sides, front and back ● OpenGL can render the two differently ● The ordering of vertices in the list determines which is the front side: ■ When looking at the front side, the vertices go counterclockwise ○ This is basically the right-hand rule ○ Note that this still holds after perspective projection

David Luebke 21 11/17/2015 OpenGL: Drawing Triangles ● You can draw multiple triangles between glBegin(GL_TRIANGLES) and glEnd() : float v1[3], v2[3], v3[3], v4[3];... glBegin(GL_TRIANGLES); glVertex3fv(v1); glVertex3fv(v2); glVertex3fv(v3); glVertex3fv(v1); glVertex3fv(v3); glVertex3fv(v4); glEnd(); ● Each set of 3 vertices forms a triangle ■ What do the triangles drawn above look like? ■ How much redundant computation is happening?

David Luebke 22 11/17/2015 OpenGL: Triangle Strips ● An OpenGL triangle strip primitive reduces this redundancy by sharing vertices: glBegin(GL_TRIANGLE_STRIP); glVertex3fv(v0); glVertex3fv(v1); glVertex3fv(v2); glVertex3fv(v3); glVertex3fv(v4); glVertex3fv(v5); glEnd(); ■ triangle 0 is v0, v1, v2 ■ triangle 1 is v2, v1, v3 (why not v1, v2, v3?) ■ triangle 2 is v2, v3, v4 ■ triangle 3 is v4, v3, v5 (again, not v3, v4, v5) v0v0 v2v2 v1v1 v3v3 v4v4 v5v5

David Luebke 23 11/17/2015 OpenGL: Modeling Transforms ● OpenGL provides several commands for performing modeling transforms: ■ glTranslate{fd}(x, y, z) ○ Creates a matrix T that transforms an object by translating (moving) it by the specified x, y, and z values ■ glRotate{fd}(angle, x, y, z) ○ Creates a matrix R that transforms an object by rotating it counterclockwise angle degrees about the vector {x, y, z} ■ glScale{fd}(x, y, z) ○ Creates a matrix S that scales an object by the specified factors in the x, y, and z directions

David Luebke 24 11/17/2015 OpenGL: Matrix Manipulation ● Each of these postmultiplies the current matrix ■ E.g., if current matrix is C, then C=CS ■ The current matrix is either the modelview matrix or the projection matrix (also a texture matrix, won’t discuss) ■ Set these with glMatrixMode(), e.g.: glMatrixMode(GL_MODELVIEW); glMatrixMode(GL_PROJECTION); ■ WARNING: common mistake ahead! ○ Be sure that you are in GL_MODELVIEW mode before making modeling or viewing calls! ○ Ugly mistake because it can appear to work, at least for a while…

David Luebke 25 11/17/2015 OpenGL: Matrix Manipulation ● More matrix manipulation calls ■ To replace the current matrix with an identity matrix: glLoadIdentity() ■ Postmultiply the current matrix with an arbitrary matrix: glMultMatrix{fd}(float/double m[16]) ■ Copy the current matrix and push it onto a stack: glPushMatrix() ■ Discard the current matrix and replace it with whatever’s on top of the stack: glPopMatrix() ■ Note that there are matrix stacks for both modelview and projection modes