Image Rendering. Rendering can be divided into three sub-problems. Image Formation The hidden surface problem visibility determination steps

Similar documents
Lecture 4 of 41. Lab 1a: OpenGL Basics

ERKELEY DAVIS IRVINE LOS ANGELES RIVERSIDE SAN DIEGO SAN FRANCISCO EECS 104. Fundamentals of Computer Graphics. OpenGL

VR-programming tools (procedural) More VRML later in this course! (declarative)

Lecture 2 2D transformations Introduction to OpenGL

Computer Graphics. Bing-Yu Chen National Taiwan University

CS559: Computer Graphics. Lecture 12: OpenGL Li Zhang Spring 2008

Precept 2 Aleksey Boyko February 18, 2011

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

Getting Started. Overview (1): Getting Started (1): Getting Started (2): Getting Started (3): COSC 4431/5331 Computer Graphics.

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

Introduction to Computer Graphics with OpenGL/GLUT

Graphics Programming

Lectures OpenGL Introduction

CS 4204 Computer Graphics

An Interactive Introduction to OpenGL Programming

Computer Graphics 1 Computer Graphics 1

Programming using OpenGL: A first Introduction

CSE 167: Introduction to Computer Graphics Lecture #5: Visibility, OpenGL

Graphics Programming. August 31, Programming of the Sierpinski gasket. Programming with OpenGL and C/C++

RECITATION - 1. Ceng477 Fall

CS559: Computer Graphics. Lecture 12: OpenGL Transformation Li Zhang Spring 2008

Computer Graphics. Chapter 10 Three-Dimensional Viewing

OpenGL refresher. Advanced Computer Graphics 2012

Exercise 1 Introduction to OpenGL

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

Teacher Assistant : Tamir Grossinger Reception hours: by - Building 37 / office -102 Assignments: 4 programing using

GL_COLOR_BUFFER_BIT, GL_PROJECTION, GL_MODELVIEW

An Interactive Introduction to OpenGL and OpenGL ES Programming. Ed Angel Dave Shreiner

Computer Graphics. Bing-Yu Chen National Taiwan University


Modeling Transform. Chapter 4 Geometric Transformations. Overview. Instancing. Specify transformation for objects 李同益

Computer Graphics Primitive Attributes

Introduction to OpenGL

Basic Graphics Programming

Computer graphics MN1

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

Computer Graphics, Chapt 08

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

Computer Graphics (Basic OpenGL)

Introduction to OpenGL Week 1

Objectives. Image Formation Revisited. Physical Approaches. The Programmer s Interface. Practical Approach. Introduction to OpenGL Week 1

Assignment 1. Simple Graphics program using OpenGL

Drawing Primitives. OpenGL basics

OpenGL Tutorial. Ceng 477 Introduction to Computer Graphics

Lecture 2 CISC440/640 Spring Department of Computer and Information Science

Programming with OpenGL Part 1: Background

Basic Graphics Programming

Computer Graphics. OpenGL

OpenGL. 1 OpenGL OpenGL 1.2 3D. (euske) 1. Client-Server Model OpenGL

2. OpenGL -I. 2.1 What is OpenGL? Things OpenGL can do: -23-

Computer Graphics Introduction to OpenGL

COMPUTER GRAPHICS LAB # 3

Computer Graphics Course 2005

Introduction to OpenGL

to OpenGL Introduction Pipeline Graphics pipeline OpenGL pipeline OpenGL syntax Modeling Arrays Conclusion 1 Introduction Introduction to OpenGL

CS 543 Lecture 1 (Part 3) Prof Emmanuel Agu. Computer Science Dept. Worcester Polytechnic Institute (WPI)

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

Information Coding / Computer Graphics, ISY, LiTH. OpenGL! ! where it fits!! what it contains!! how you work with it 11(40)

Introduction to OpenGL. CSCI 4229/5229 Computer Graphics Fall 2012

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

Programming with OpenGL Part 2: Complete Programs Computer Graphics I, Fall

Cameras (and eye) Ideal Pinhole. Real Pinhole. Real + lens. Depth of field

OpenGL. Toolkits.

COMP 371/4 Computer Graphics Week 1

// double buffering and RGB glutinitdisplaymode(glut_double GLUT_RGBA); // your own initializations

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

Outline. Other Graphics Technology. OpenGL Background and History. Platform Specifics. The Drawing Process

Graphics and Computation Introduction to OpenGL

OpenGL/GLUT Intro. Week 1, Fri Jan 12

Advanced Computer Graphics (CS & SE )

Overview of Graphics Systems Hearn & Baker Chapter 2. Some slides are taken from Robert Thomsons notes.

Computer Graphics. Making Pictures. Computer Graphics CSC470 1

CSE 167: Introduction to Computer Graphics Lecture #5: Illumination Model

Chapter 7 Display Lists

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

C++ is Fun Part 13 at Turbine/Warner Bros.! Russell Hanson

C OMPUTER G RAPHICS Thursday

Early History of APIs. PHIGS and X. SGI and GL. Programming with OpenGL Part 1: Background. Objectives

3D Graphics and API with OpenGL

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

5HDOLVP7KURXJK6\QWKHVLV

Using OpenGL with CUDA

Programming with OpenGL Part 1: Background

CMSC 425: Lecture 4 More about OpenGL and GLUT Tuesday, Feb 5, 2013

Geometry: Outline. Projections. Orthographic Perspective

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

Spring 2013, CS 112 Programming Assignment 2 Submission Due: April 26, 2013

Visualizing Molecular Dynamics

Transformation, Input and Interaction. Hanyang University

Interaction. CSCI 480 Computer Graphics Lecture 3

Graphics Programming. 1. The Sierpinski Gasket. Chapter 2. Introduction:

UNIT 7 LIGHTING AND SHADING. 1. Explain phong lighting model. Indicate the advantages and disadvantages. (Jun2012) 10M

CS Computer Graphics: OpenGL, Continued

CS Computer Graphics: OpenGL, Continued

Interaction Computer Graphics I Lecture 3

SOURCES AND URLS BIBLIOGRAPHY AND REFERENCES

1 (Practice 1) Introduction to OpenGL

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

Graphics Pipeline & APIs

Graphics Hardware and OpenGL

Transcription:

Image Rendering Rendering can be divided into three sub-problems Image Formation The hidden surface problem visibility determination steps Illumination Direct illumination Indirect illumination Shading Process of determining the distribution of light leaving a surface 1 Image Rendering Object Model Illumination Model Direct Illumination Determination Texture Indirect Illumination Determination Direct Image Formation Shading Indirect Image Formation Synthetic Image 2 1

Visibility Determination Given. A set of surfaces in three dimensions A viewpoint An oriented image plane A field of view For each point on the image plane within the field of view Determine which point on the surface is closest to the viewpoint along a line form the viewpoint through the point in the image plane 3 Visibility Determination There are two basic classes of algorithms to solve this problem: Continues algorithms Performing visibility determination over continuous areas covering the entire image plane. Every visible piece of each surface will be detected regardless of location or size. Point sampling algorithms Forms an approximate solution to the visible surface problem. These algorithms determine visibility only at a finite number of sample points and make assumptions about the visibility of objects between sample points. 4 2

Visibility Determination Continuous Algorithms: Area/volume subdivision scan-plane Point Sampling Algorithms: Z-buffer Ray Tracing Painter s Scan-line Other Algorithms: wavefront propagation 5 Point Sampling Algorithms Scan-Line sort objects by y, for all y { sort objects by x, for all x { compare z Painter s sort objects by z, for all objects { for all covered pixels(x,y) { paint Z-Buffer for all objects { for all covered pixels { compare z Ray Tracing for all pixels (x,y) { for all objects { compare z 6 3

OpenGL A Visual Introduction to OpenGL Programming Siggraph 1998 - Course Mason Woo Dave Shreiner ACM Copyright Notice Copyright (C) 1998 by the Association for Computing Machinery, Inc. Permission to make digital or hard copies of part or all of this work for personal or classroom use is granted without fee providedthat copies are not made or distributed for profit or commercial advantage and that copies bear this notice and the full citation on the first page. Copyrights for components of this work owned by others than ACM must be honored. Abstracting with credit is permitted. To copy otherwise, to republish, to post on servers, or to redistribute to lists, requires prior specific permission and/or a fee. Request permissions from Publications Dept., ACM Inc., FAX +1-212-869-0481, or e-mail "permission@acm.org". What is OpenGL? A graphics rendering library API to produce high-quality, color images from geometric and raster primitives Window System and Operating System independent. OpenGL doesn t do windows 8 4

OpenGL Architecture 9 OpenGL as a Renderer Renders simple geometric primitives points, lines, polygons Renders images and bitmaps separate pipelines for geometry and pixels, linked through texture mapping Rendering depends on state colors, light sources, materials surface normals, texture 10 5

OpenGL and Related APIs GLU (OpenGL Utility Library) guaranteed to be available tesselators, quadrics, NURBs, etc. some surprisingly common operations, such as projection transformations (such as gluperspective) GLX or WGL bridge between window system and OpenGL GLUT portable bridge between window system and OpenGL not standard, but informal popularity 11 OpenGL and Related APIs 12 6

Program Structure Initialize visual & open window Initialize states & display lists Register display callback function clear screen, change states, render graphics, swap buffers... Register reshape callback function modify clipping, viewing Register input device (mouse, keybd) callback functions Register idle callback function (the keep busy operation) Enter main loop if contents need to be redrawn, display callback called if window resized, reshape callback called if input event, appropriate input callback function called if nothing happening, idle callback function called 13 Preliminaries Header files #include <GL/gl.h> #include <GL/glu.h> #include <GL/glut.h> /* see note! */ Link with graphics libraries cc prog.c -lglut -lglu -lgl -lx11 -lxmu -o prog cl proc.c glut32.lib glu32.lib opengl32.lib \ gdi32.lib user32.lib GL enumerated types for platform independence GLbyte, GLshort, GLushort, GLint, GLuint, GLsizei, GLfloat, GLdouble, GLclampf, GLclampd, GLubyte, GLboolean, GLenum, GLbitfield 14

OpenGL Command Syntax 15 A Simple Example Program #include <GL/glut.h> void display(void) { glclear(gl_color_buffer_bit); glcolor3f(0.0, 1.0, 1.0); /* cyan */ glbegin(gl_quads); glvertex2i(100,100); glvertex2i(200, 100); glvertex2i(200,300); glvertex2i(100, 300); glend(); glflush(); void gfxinit(void) { glclearcolor(0.0, 0.0, 0.0, 0.0); 16 8

A Simple Example Program void reshape(int width, int height) { glviewport(0, 0, width, height) glmatrixmode(gl_projection); glloadidentity(); gluortho2d(0.0, (GLdouble) width, 0.0, (GLdouble) height); void main(int argc, char **argv){ glutinit(&argc, argv); glutinitdisplaymode(glut_single GLUT_RGB); win = glutcreatewindow("rect"); glutreshapefunc(reshape); glutdisplayfunc(display); gfxinit(); glutmainloop(); 1 Error Handling GLenum glgeterror(void) Have an error handling routine Call it every time in display() GLenum errcode; const GLubyte *errstring; if ((errcode = glgeterror())!= GL_NO_ERROR) { errstring = gluerrorstring(errcode); fprintf (stderr, OpenGL Error: %s\n, errstring); If GL_NO_ERROR returned, great! 18 9

Elementary Rendering Geometric Primitives Managing OpenGL State OpenGL Buffers 19 OpenGL Geometric Primitives 20 10

Specifying Geometric Primitives Primitives are specified using glbegin( primtype ); glend(); primtype determines how vertices are combined GLfloat r, g, b; r, g, b; Glfloat coords[3];]; glbegin( primtype ); ); for ( i = 0; i < nverts; ++i ) { glcolor3f( red, green,blue); ue ); glvertex3fv( coords ); glend(); 21 Simple Example void drawrhombus( GLfloat color[] ) { glcolor3fv( color ); glbegin( GL_QUADS ); glvertex2f( 0.0, 0.0 ); glvertex2f( 1.0, 0.0 ); glvertex2f( 1.5, 1.118 ); glvertex2f( 0.5, 1.118 ); glend(); 22 11

Advanced Primitives Vertex Arrays Bernstein Polynomial Evaluators basis for GLU Nurbs GLU Quadric Objects sphere cylinder disk 23 Vertex Arrays Pass arrays of vertices, colors, etc. to OpenGL in a large chunk glvertexpointer( 3, GL_FLOAT, 0, coords) glcolorpointer( 4, GL_FLOAT, 0, colors ) glenableclientstate( GL_VERTEX_ARRAY ) glenableclientstate( GL_COLOR_ARRAY ) All active arrays are used in rendering 24 12

Combined Vertex Data Combine all vertex data into a single array glinterleavedarrays( GL_C3F_V3F, 0, data ); ); Color data Vertex data Interleaved data 25 Rendering with Vertex Arrays Render arrays sequentially gldrawarrays( GL_TRIANGLE_STRIP, 0, numverts ); Automatically index into arrays Gluint indices[] = { 0, 2, 1, 3, 2, 3, 6, 5 ; gldrawelements( GL_QUADS, 2, GL_UNSIGNED_INT, indices ); Manually index into arrays glbegin( GL_LINES ); for ( i = 0; i < numlines; ++i ) { glarrayelement( leftend[i] ); glarrayelement( rightend[i] ); glend(); 26 13

OpenGL s State Machine All rendering attributes are encapsulated in the OpenGL State rendering styles shading lighting texture mapping 2 Manipulating OpenGL State Appearance is controlled by current state foreach( primitive to render ) { update OpenGL state render primitive Manipulating vertex attributes is most common way to manipulate state glcolor*() / glindex*() glnormal*() gltexcoord*() 28 14

Controlling current state Setting State glpointsize( size ); gllinestipple( repeat, pattern ); glmaterialfv( GL_FRONT, GL_DIFFUSE, color ); Enabling Features glenable( GL_LIGHTING ); gldisable( GL_TEXTURE_2D ); 29 Transformations Prior to rendering, view, locate, and orient: eye/camera position eye/camera position 3D geometry 3D geometry Manage the matrices including matrix stack incmatrix stack Combine (composite) transformations 30 15

Transformation Pipeline object eye clip normalized device window 31 Matrix Operations Specify Current Matrix Stack glmatrixmode (GL_MODELVIEW or GL_PROJECTION) Other Matrix or Stack Operations glloadidentity() glpushmatrix() glpopmatrix() Viewport usually same as window size viewport aspect ratio should be same as projection transformation or resulting image may be distorted glviewport(x, y, width, height) 32 16

Projection Transformation Shape of viewing frustum Perspective projection gluperspective (fovy, aspect, znear, zfar) glfrustum (left, right, bottom, top, znear, zfar) Orthographic parallel projection glortho (left, right, bottom, top, znear, zfar) gluortho2d (left, right, bottom, top) calls glortho with z values near zero 33 Viewing Transformations Position the camera/eye in the scene place the tripod down; aim camera To fly through a scene change viewing transformation and redraw scene redraw scene glulookat(eyex, eyey, eyez, aimx, aimy, aimz, upx, upy, upz) up vector determines unique orientation careful of degenerate positions 34 1

Modeling Transformations Move object gltranslate{fd(x, y, z) Rotate object around arbitrary axis (x, y, z) glrotate{fd(angle, x, y, z)) angle is in degrees Dilate (stretch or shrink) or mirror object glscale{fd(x, y, z)(x, y, z) 35 Projection is left handed Projection transformations ( gluperspective, glortho ) are left handed think of znear an d zfaras distance from viewpoint Everything else is right handed, including the vertexes to be ren dered 36 18

Modeling in OpenGL All Geometric Primitives are Eventually Described in Terms of Verticies All Verticies are 3-D and Described by 4 Coordinates (x, y, z, w) If w is not specified, w=1 If w!= 0 ==> (x/w, y/w, z/w, 1) Restrictions on OpenGL Polygons Polygons MUST be Simple Edges intersect ONLY at verticies Exactly two edges meet at ant vertex Polygons MUST be Convex Given any two interior points, the line segment joinging them is also interior 3 Modeling in OpenGL Restrictions on OpenGL Polygons Polygons may NOT have Holes Polygons may have any number of edges Tesselation Polygons Restrictions Allow Fast Polygon Rendering in Hardware 38 19

Modeling in OpenGL After Transformations, Non-planer Polygons May No Longer Be Simple Not unusual when curved surfaces are approximated with quadrilateral polygons Avoid problem by using triangular facets 20