OpenGL: Open Graphics Library. Introduction to OpenGL Part II. How do I render a geometric primitive? What is OpenGL

Similar documents
CS 591B Lecture 9: The OpenGL Rendering Pipeline

3D Graphics Pipeline II Clipping. Instructor Stephen J. Guy

API for creating a display window and using keyboard/mouse interations. See RayWindow.cpp to see how these are used for Assignment3

OpenGL. Toolkits.

Computer Graphics. Chapter 7 2D Geometric Transformations

Rasterization Overview

CSE 167: Introduction to Computer Graphics Lecture #4: Vertex Transformation

Surface Graphics. 200 polys 1,000 polys 15,000 polys. an empty foot. - a mesh of spline patches:

CSE 690: GPGPU. Lecture 2: Understanding the Fabric - Intro to Graphics. Klaus Mueller Stony Brook University Computer Science Department

OpenGL Transformations

CSE 167: Lecture #4: Vertex Transformation. Jürgen P. Schulze, Ph.D. University of California, San Diego Fall Quarter 2012

Pipeline Operations. CS 4620 Lecture Steve Marschner. Cornell CS4620 Spring 2018 Lecture 11

To Do. Computer Graphics (Fall 2008) Course Outline. Course Outline. Methodology for Lecture. Demo: Surreal (HW 3)

Graphics Programming

Pipeline Operations. CS 4620 Lecture 14

Lecture 5: Viewing. CSE Computer Graphics (Fall 2010)

CSE 167: Introduction to Computer Graphics Lecture #5: Rasterization. Jürgen P. Schulze, Ph.D. University of California, San Diego Fall Quarter 2015

Graphics Pipeline & APIs

Real-Time Rendering (Echtzeitgraphik) Michael Wimmer

EECE 478. Learning Objectives. Learning Objectives. Rasterization & Scenes. Rasterization. Compositing

OpenGL. Jimmy Johansson Norrköping Visualization and Interaction Studio Linköping University

Scene Graphs. CS4620/5620: Lecture 7. Announcements. HW 1 out. PA 1 will be out on Wed

Graphics Pipeline & APIs

3D Graphics and OpenGl. First Steps

Precept 2 Aleksey Boyko February 18, 2011

Models and Architectures

Transformation Pipeline

Pipeline Operations. CS 4620 Lecture 10

Describe the Orthographic and Perspective projections. How do we combine together transform matrices?

Lecture 4 of 41. Lab 1a: OpenGL Basics

CS 112 The Rendering Pipeline. Slide 1

CS4620/5620: Lecture 14 Pipeline

Today s Agenda. Basic design of a graphics system. Introduction to OpenGL

Models and Architectures. Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico

Computer graphic -- Programming with OpenGL I

CS 4620 Program 3: Pipeline

Introduction to Computer Graphics with WebGL

The Viewing Pipeline adaptation of Paul Bunn & Kerryn Hugo s notes

Introduction to 3D Graphics with OpenGL. Z-Buffer Hidden Surface Removal. Binghamton University. EngiNet. Thomas J. Watson

Name: SID: LAB Section: Lab 6 - Part 1: Pixels and Triangle Rasterization

CSE4030 Introduction to Computer Graphics

Normalized Device Coordinate System (NDC) World Coordinate System. Example Coordinate Systems. Device Coordinate System

World Coordinate System

Graphics Hardware and Display Devices

Intro to OpenGL III. Don Fussell Computer Science Department The University of Texas at Austin

Notes on Assignment. Notes on Assignment. Notes on Assignment. Notes on Assignment

E.Order of Operations

CS451Real-time Rendering Pipeline

Introduction to OpenGL Transformations, Viewing and Lighting. Ali Bigdelou

The Traditional Graphics Pipeline

Advanced Computer Graphics (CS & SE )

Methodology for Lecture. Importance of Lighting. Outline. Shading Models. Brief primer on Color. Foundations of Computer Graphics (Spring 2010)

CIS 636 Interactive Computer Graphics CIS 736 Computer Graphics Spring 2011

Drawing Fast The Graphics Pipeline

CSE 167: Introduction to Computer Graphics Lecture #5: Projection. Jürgen P. Schulze, Ph.D. University of California, San Diego Fall Quarter 2017

cs123 Lab 3 OpenGL Part One 1 Introduction 2 OpenGL Basics 2.2 The Rendering Pipeline 2.1 The CPU and the GPU 2.3 Basic Syntax of OpenGL commands

The Traditional Graphics Pipeline

3D computer graphics: geometric modeling of objects in the computer and rendering them

Drawing Fast The Graphics Pipeline

Computer Graphics. Chapter 10 Three-Dimensional Viewing

Sign up for crits! Announcments

Discrete Techniques. 11 th Week, Define a buffer by its spatial resolution (n m) and its depth (or precision) k, the number of

CSC Graphics Programming. Budditha Hettige Department of Statistics and Computer Science

graphics pipeline computer graphics graphics pipeline 2009 fabio pellacini 1

CS354 Computer Graphics Viewing and Modeling

The Rendering Pipeline (1)

graphics pipeline computer graphics graphics pipeline 2009 fabio pellacini 1

Today. Rendering pipeline. Rendering pipeline. Object vs. Image order. Rendering engine Rendering engine (jtrt) Computergrafik. Rendering pipeline

Lecture 4. Viewing, Projection and Viewport Transformations

Drawing Fast The Graphics Pipeline

Graphics Hardware and OpenGL

Basic Graphics Programming

CS Computer Graphics: Hidden Surface Removal

The Traditional Graphics Pipeline

Rendering Objects. Need to transform all geometry then

Module Contact: Dr Stephen Laycock, CMP Copyright of the University of East Anglia Version 1

Basic Graphics Programming

Graphics Hardware. Instructor Stephen J. Guy

CSC 470 Computer Graphics

Rendering. Converting a 3D scene to a 2D image. Camera. Light. Rendering. View Plane

SHADER PROGRAMMING. Based on Jian Huang s lecture on Shader Programming

CS 4204 Computer Graphics

Motivation. What we ve seen so far. Demo (Projection Tutorial) Outline. Projections. Foundations of Computer Graphics

Graphics Pipeline 2D Geometric Transformations

Geometry Primitives. Computer Science Department University of Malta. Sandro Spina Computer Graphics and Simulation Group. CGSG Geometry Primitives

- Rasterization. Geometry. Scan Conversion. Rasterization

Translation. 3D Transformations. Rotation about z axis. Scaling. CS 4620 Lecture 8. 3 Cornell CS4620 Fall 2009!Lecture 8

For each question, indicate whether the statement is true or false by circling T or F, respectively.

Computer Graphics Programming

Computer Viewing Computer Graphics I, Fall 2008

Books, OpenGL, GLUT, GLUI, CUDA, OpenCL, OpenCV, PointClouds, and G3D

To Do. Demo (Projection Tutorial) Motivation. What we ve seen so far. Outline. Foundations of Computer Graphics (Fall 2012) CS 184, Lecture 5: Viewing

X. GPU Programming. Jacobs University Visualization and Computer Graphics Lab : Advanced Graphics - Chapter X 1

VISIBILITY & CULLING. Don t draw what you can t see. Thomas Larsson, Afshin Ameri DVA338, Spring 2018, MDH

11/1/13. Basic Graphics Programming. Teaching Assistant. What is OpenGL. Course Producer. Where is OpenGL used. Graphics library (API)

CS 465 Program 4: Modeller

Game Architecture. 2/19/16: Rasterization

COMP 175 COMPUTER GRAPHICS. Lecture 07: Scene Graph. COMP 175: Computer Graphics March 10, Remco Chang 07 Scene Graph

Blue colour text questions Black colour text sample answers Red colour text further explanation or references for the sample answers

Hidden Surface Removal. 3D Graphics with OpenGL. Back-Face Culling

Transcription:

OpenGL: Open Graphics Library Introduction to OpenGL Part II CS 351-50 Graphics API ( Application Programming Interface) Software library Layer between programmer and graphics hardware (and other software Several hundred procedures and functions What is OpenGL Configurable state machine Input is 2D or 3D data Output is framebuffer Modify state to modify functionality How do I render a geometric primitive? To Framebuffer OpenGL primitives A group of one or more vertices Vertex defines: A point An endpoint of an edge A corner of a polygon where two edges meet 1

OpenGL Rendering Data consists of Positional coordinates Colors Normals Texture Coordinates Each vertex is processed independely In order In the same way OpenGL Primitives Points Lines Polygon Triangle Quad Quad strip Triangle strip Triangle Fan OpenGL drawing To draw a primitive, call glbegin() glend() encloses a list of vertices and their attributes Coordinates of a primitive are given counter-clockwise order Function calls to draw a primitive glbegin(gl_points); glvertex3f(0.0f, 0.0f, 0.0f); glend(); 2

Draw a triangle: glbegin(gl_triangles); glvertex3f(0.0f, 1.0f, 0.0f); glvertex3f(-1.0f, -1.0f, 0.0f); glvertex3f(1.0f, -1.0f, 0.0f); glend(); Draws a triangle with different colors at each vertex glbegin(gl_triangles); glcolor3f(1.0f, 0.0f, 0.0f); //pure red glvertex3f(0.0f, 1.0f, 0.0f); glcolor3f(0.0f, 1.0f, 0.0f); //pure green glvertex3f(-1.0f, -1.0f, 0.0f); glcolor3f(0.0f, 0.0f, 1.0f); //pure blue glvertex3f(1.0f, -1.0f, 0.0f); glend(); Wireframe Types of rendering Display only lines and curves No filled objects Flat Shading Compute a single color for each polygon Fill the polygon with that constant color Types of rendering Smooth (Gouraud shading) Interpolate vertex colors across polygon Vertex colors can be specified explicitly or computed using lighting calculations Texture Mapping Modify color of each pixel with colors from an image 1991 Pixar Shutterbug Example http://www.siggraph.org/education/curriculum/projects/slide_sets/slides91/91_01_2.htm 3

Functions How are these options configured? glenable, gldisable, glcullmode, glpolygonmode, gllightmodel, etc. What is the OpenGL Pipeline Process thru which OpenGL processes data Geometric data and pixel data processed separately Geometry subject to per-vertex operations Pixel data subject to per-pix operations Both share the same final step Rasterization and per-fragement ops (fragment is general term for pixel or vertex) OpenGL Pipeline OpenGL Pipeline Vertices Images/ Pixels Geomety Primitive Operations Pixel Operations Scan Conversion Texture Memory Fragment Operations Framebuffer Understanding Pipeline is important! Helps design algorithms Helps find bottlenecks Which parts are supported by hardware 4

Pixel Primitives Provide a way of manipulating rectangles of pixels gldrawpixels, glreadpixels, glcopypixels move pixel rectangles to and from the framebuffer glbitmap takes a binary image and renders the current color in framebuffer positions corresponding to 1s in image (useful for drawing fonts) glrasterpos defines where pixels go in the framebuffer Hidden Surface Removal When we draw a fragment, record the z (distance to the eye) in the depth buffer If the z stored in the depth buffer is greater than the z for the fragment about to be drawn, draw it Otherwise, the fragment is behind something that has already been drawn, so throw it away Hidden Surface Removal When seeing up your window, specify a depth buffer: glutinitdisplaymode(glut_depth); When clearing, make sure to: glclear(gl_depth_buffer_bit); glenable(gl_depth_test); Set the depth test comparison operation: gldepthfunc(gl_less); //this is the default, don t really need to specify Demos Shapes (Nate Robin s Tutors) Ctrl and mouse to change primitive 5

OpenGL Color Models RGBA color Red, Green, Blue, Alpha Separate channel for each 8 bits/channel = 16 million colors Indexed Color Small number of colors accessed by indices into a color look up table 8 bits = 256 colors OpenGL Transparency Use the fourth component (alpha) of RGBA color Alpha = 0 is fully transparent Alpha = 1 is fully opaque Objects are composited as they are rendered Example: C = alpha*cs + (1 - alpha) Cf Cs is the color of the incoming fragment Cf is the color already in the framebuffer Viewing in OpenGL Viewing consists of two parts Object positioning model view transformation matrix View projection projection transformation matrix OpenGL support both perspective and orthographic viewing transformations OpenGL camera is always at the origin, pointing in the -z direction Transformations move objects relative to camera ModelView Matrix Positions objects in world coordinates Usually formed by concatenating simple transformations glrotate(theta, x,y,z) gltranslate(x,y,z) glscale(x,y,z) Order is important 6

Modeling Transformations gltranslatef(0.0f, 0.0f, -10.0f); glrotatef(45.0f, 0.0f, 1.0f, 0.0f); glbegin(gl_triangles); glcolor3f(1.0f, 0.0f, 0.0f); //pure red glvertex3f(0.0f, 1.0f, 0.0f); glcolor3f(0.0f, 1.0f, 0.0f); //pure green glvertex3f(-1.0f, -1.0f, 0.0f); glcolor3f(0.0f, 0.0f, 1.0f); //pure blue glvertex3f(1.0f, -1.0f, 0.0f); glend(); Viewing in OpenGL Orthographic projection Boundaries of the parallel viewing volume Objects are clipped to specified viewing cube glortho(left, right, bottom, top, front, back) Perspective Projection glfrustum, gluperspective Clipping volume is a frustum Make sure near and far clipping planes aren t too far apart Make sure near plane isn t too close to eye Positioning the Camera Use glulookat to specify Eye location Look-at point up vector glulookat(10,10,10,1,2,3,0,0,1); Eye is (10,10,10) Look at point is (1,2,3) Up is (0,0,1) Usually done in GL_PROJECTION matrix and combined with perspective matrix Complete Viewing Example //Projection first glmatrixmode( GL_PROJECCTION); glloadidentity(); gluperspective(60, 1, 1, 100); glulookat(10,10,10,1,2,3,0,0,1) //Now object transformations glmatrixmode(gl_modelview) glload Identity(); gltranslate(1,1,1); glrotatef(90, 1,0,0); DrawObject(); 7

Matrix Stacks OpenGL has multiple matrix stacks glpushmatrix pushes a copy of the top fo the stack matrix glpopmatrix throws away the top of the stack Very useful for hierachically defined figures Column versus row order OpenGL uses column, C uses row We will use column Demo: http://www.cs.princeton.edu/~min/cs426/jar/transform.html From OpenGL maual (pg 103 of Programmers 1.1) If you are programming in C and declare a matrix as m[4][4] then the element m[i][j] is in the ith column and jth row of the OpenGL transformation matrix. This is the reverse of the standard C convention in which m[i][j] is in row i and column j. To avoid confusion you should declare your matrices as m[16]. OpenGL Matrix: (zero based) m 0 m 4 m 8 m 12 m 1 m 5 m 9 m 13 m 2 m 6 m 10 m 14 m 3 m 7 m 11 m 15 8

Demos Transformations (Nate Robin s Tutors) The transformation tutorial program (shown at left) demonstrates how the basic transformations of rotate, translate and scale operate in OpenGL. The order of the transforms can be changed to see how that effects rendering. Slide Credits These slides were pieced together based upon information in the following valuable sources: Greg Humphreys, 2000 (pdf of Intro to OpenGL, CS148 Lecture 7) http://www.csie.nctu.edu.tw/~jllin/d_documents.htm Michael Mack, http://www.acm.wwu.edu/~mackm/pres/index.php 9