OpenGL Kurt Akeley CS248 Lecture 2 27 September 2007

Slides:



Advertisements
Similar presentations
COMPUTER GRAPHICS SOFTWARE.
Advertisements

Chapter 2: Graphics Programming
CS 352: Computer Graphics Chapter 7: The Rendering Pipeline.
Understanding the graphics pipeline Lecture 2 Original Slides by: Suresh Venkatasubramanian Updates by Joseph Kider.
Graphics Pipeline.
RealityEngine Graphics Kurt Akeley Silicon Graphics Computer Systems.
CS 4363/6353 BASIC RENDERING. THE GRAPHICS PIPELINE OVERVIEW Vertex Processing Coordinate transformations Compute color for each vertex Clipping and Primitive.
Computer Graphic Creator: Mohsen Asghari Session 2 Fall 2014.
CSC 461: Lecture 51 CSC461 Lecture 5: Simple OpenGL Program Objectives: Discuss a simple program Discuss a simple program Introduce the OpenGL program.
© David Kirk/NVIDIA and Wen-mei W. Hwu, ECE408, University of Illinois, Urbana-Champaign 1 Programming Massively Parallel Processors Chapter.
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
GPU Simulator Victor Moya. Summary Rendering pipeline for 3D graphics. Rendering pipeline for 3D graphics. Graphic Processors. Graphic Processors. GPU.
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Introduction to Computer Graphics Ed Angel Professor of Computer Science, Electrical and.
Status – Week 283 Victor Moya. 3D Graphics Pipeline Akeley & Hanrahan course. Akeley & Hanrahan course. Fixed vs Programmable. Fixed vs Programmable.
Texture Mapping Kurt Akeley CS248 Lecture October 2007
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Models and Architectures Ed Angel Professor of Computer Science, Electrical and Computer.
Reference1. [OpenGL course slides by Rasmus Stenholt]
CS 480/680 Computer Graphics Course Overview Dr. Frederick C Harris, Jr. Fall 2012.
Programmable Pipelines. Objectives Introduce programmable pipelines ­Vertex shaders ­Fragment shaders Introduce shading languages ­Needed to describe.
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.
Programmable Pipelines. 2 Objectives Introduce programmable pipelines ­Vertex shaders ­Fragment shaders Introduce shading languages ­Needed to describe.
Graphics Architectures & OpenGL API Introduction Angel Angel: Interactive Computer Graphics5E © Addison-Wesley
Graphics Systems and OpenGL. Business of Generating Images Images are made up of pixels.
CSC 461: Lecture 3 1 CSC461 Lecture 3: Models and Architectures  Objectives –Learn the basic design of a graphics system –Introduce pipeline architecture.
OpenGL Conclusions OpenGL Programming and Reference Guides, other sources CSCI 6360/4360.
1 Introduction to Computer Graphics SEN Introduction to OpenGL Graphics Applications.
Computer Graphics I, Fall 2008 Introduction to Computer 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 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 CS4610/7610: Introduction to Computer Graphics.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
1Computer Graphics Lecture 4 - Models and Architectures John Shearer Culture Lab – space 2
Review of OpenGL Basics
Introduction to OpenGL  OpenGL is a graphics API  Software library  Layer between programmer and graphics hardware (and software)  OpenGL can fit in.
OpenGL Architecture Display List Polynomial Evaluator Per Vertex Operations & Primitive Assembly Rasterization Per Fragment Operations Frame Buffer Texture.
Draw a Simple Object. Pixel pipeline Vertex pipeline Course Map Transformation & Lighting Primitive assembly Viewport culling & clipping Texture blending.
Advanced Computer Graphics Spring 2014 K. H. Ko School of Mechatronics Gwangju Institute of Science and Technology.
Review on Graphics Basics. Outline Polygon rendering pipeline Affine transformations Projective transformations Lighting and shading From vertices to.
NoufNaief.net TA: Nouf Al-harbi.
© David Kirk/NVIDIA and Wen-mei W. Hwu, ECE408, University of Illinois, Urbana-Champaign 1 Programming Massively Parallel Processors Lecture.
What are shaders? In the field of computer graphics, a shader is a computer program that runs on the graphics processing unit(GPU) and is used to do shading.
Lecture 7 Midterm Review. OpenGL Libraries gl: Basic OpenGL library, e.g. primitives. glu: OpenGL Utility library, a set of functions to create texture.
1 Programming with OpenGL Part 2: Complete Programs.
OpenGL API 2D Graphic Primitives Angel Angel: Interactive Computer Graphics5E © Addison-Wesley
© David Kirk/NVIDIA and Wen-mei W. Hwu, ECE408, University of Illinois, Urbana-Champaign 1 GPU.
1 E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012 Models and Architectures 靜宜大學 資訊工程系 蔡奇偉 副教授 2012.
Computer Graphics I, Fall Programming with OpenGL Part 2: Complete Programs.
COMP 175 | COMPUTER GRAPHICS Remco Chang1/XX13 – GLSL Lecture 13: OpenGL Shading Language (GLSL) COMP 175: Computer Graphics April 12, 2016.
Computer Graphics (Fall 2003) COMS 4160, Lecture 5: OpenGL 1 Ravi Ramamoorthi Many slides courtesy Greg Humphreys.
Graphics Pipeline Bringing it all together. Implementation The goal of computer graphics is to take the data out of computer memory and put it up on the.
Draw a Simple Object.
Computer Graphics Lecture 32
A Crash Course on Programmable Graphics Hardware
Graphics on GPU © David Kirk/NVIDIA and Wen-mei W. Hwu,
Graphics Processing Unit
Programming with OpenGL Part 2: Complete Programs
Chapter 6 GPU, Shaders, and Shading Languages
The Graphics Rendering Pipeline
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.
Introduction to OpenGL
Programming with OpenGL Part 2: Complete Programs
Programming with OpenGL Part 2: Complete Programs
CS297 Graphics with Java and OpenGL
Programming with OpenGL Part 2: Complete Programs
OpenGL-Rendering Pipeline
CIS 6930: Chip Multiprocessor: GPU Architecture and Programming
Presentation transcript:

OpenGL Kurt Akeley CS248 Lecture 2 27 September

CS248 Lecture 2Kurt Akeley, Fall 2007 OpenGL n Is a mechanism to create images in a frame buffer n Is an API to access that mechanism n Is well specified OpenGL n Is not a window system n Is not a user interface n Is not a display mechanism n Does not even own the framebuffer n It is owned by the window system so it can be shared n But OpenGL defines its attributes carefully

CS248 Lecture 2Kurt Akeley, Fall 2007 White-square code // Draw a white square against a black background #include #define GLUT_DISABLE_ATEXIT_HACK // yuck! #include void draw() { glClear(GL_COLOR_BUFFER_BIT); glLoadIdentity(); glOrtho(0, 4, 0, 4, -1, 1); glBegin(GL_POLYGON); glVertex2i(1, 1); glVertex2i(3, 1); glVertex2i(3, 3); glVertex2i(1, 3); glEnd(); glFlush(); } int main(int argc, char** argv) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_SINGLE | GLUT_RGBA); glutCreateWindow("whitesquare"); glutDisplayFunc(draw); glutMainLoop(); } OpenGL GLUT

CS248 Lecture 2Kurt Akeley, Fall 2007 OpenGL portion of white-square code glClear(GL_COLOR_BUFFER_BIT); // black background glLoadIdentity();// allow multipass glOrtho(0, 4, 0, 4, -1, 1);// int cast to double glBegin(GL_POLYGON);// draw white square glVertex2i(1, 1); glVertex2i(3, 1); glVertex2i(3, 3); glVertex2i(1, 3); glEnd(); glFlush();// force completion

CS248 Lecture 2Kurt Akeley, Fall 2007 Red-book example 1-1 OpenGL code glClearColor(0.0, 0.0, 0.0, 0.0); glClear(GL_COLOR_BUFFER_BIT); glColor3f(1.0, 1.0, 1.0); glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0); glBegin(GL_POLYGON); glVertex3f(0.25, 0.25, 0.0); glVertex3f(0.75, 0.25, 0.0); glVertex3f(0.75, 0.75, 0.0); glVertex3f(0.25, 0.75, 0.0); glEnd(); glFlush();// force completion

CS248 Lecture 2Kurt Akeley, Fall 2007 State tables OpenGL 2.0 Spec, Table Framebuffer Control COLOR_CLEAR_VALUE0,0,0,0

CS248 Lecture 2Kurt Akeley, Fall 2007 State tables OpenGL 2.0, Table 6.5. Current Values and Associated Data

CS248 Lecture 2Kurt Akeley, Fall 2007 A snippet from the OpenGL 2.0 spec Vertices are specified by giving their coordinates in two, three, or four dimensions. This is done using one of several versions of the Vertex command: void Vertex{234}{sifd}( T coords ); void Vertex{234}{sifd}v( T coords ); A call to any Vertex command specifies four coordinates: x, y, z, and w. The x coordinate is the first coordinate, y is second, z is third, and w is fourth. A call to Vertex2 sets the x and y coordinates; the z coordinate is implicitly set to zero and the w coordinate to one.

CS248 Lecture 2Kurt Akeley, Fall 2007 The OpenGL Vertex Pipeline

CS248 Lecture 2Kurt Akeley, Fall 2007 OpenGL shaded-quad code glClearColor(1, 1, 1, 1);// white glClear(GL_COLOR_BUFFER_BIT); glLoadIdentity(); glOrtho(0, 100, 0, 100, -1, 1); glBegin(GL_TRIANGLE_STRIP); glColor3f(0, 0.5, 0); // dark green glVertex2i(11, 31); glVertex2i(37, 71); glColor3f(0.5, 0, 0); // dark red glVertex2i(91, 38); glVertex2i(65, 71); glEnd(); glFlush();

CS248 Lecture 2Kurt Akeley, Fall 2007 OpenGL vertex pipeline Emphasis is on data types Diagram ignores n Pixel pipeline n Texture memory n Display lists n … Display is not part of OpenGL Vertex assembly Primitive assembly Rasterization Fragment operations Display Vertex operations Application Primitive operations Framebuffer

CS248 Lecture 2Kurt Akeley, Fall 2007 Vertex assembly (data types) struct { float x,y,z,w; float r,g,b,a; } vertex; Vertex assembly Primitive assembly Rasterization Fragment operations Display Vertex operations Application Primitive operations Framebuffer

CS248 Lecture 2Kurt Akeley, Fall 2007 Vertex assembly (OpenGL) Vertex assembly n Force input to canonical format n Convert to internal representation –E.g., x, y to float n Initialize unspecified values –E.g., z = 0, w=1 n Insert current modal state –E.g., color to 0,0.5,0,1 n Or create using evaluators Error detection n INVALID_ENUM n INVALID_VALUE n INVALID_OPERATION n Especially between Begin and End Vertex assembly Primitive assembly Rasterization Fragment operations Display Vertex operations Application Primitive operations Framebuffer

CS248 Lecture 2Kurt Akeley, Fall 2007 Vertex assembly (in our case) struct { float x,y,z,w; // 11, 31, 0, 1 float r,g,b,a; // 0, 0.5, 0, 1 } vertex; Vertex assembly Primitive assembly Rasterization Fragment operations Display Vertex operations Application Primitive operations glColor3f(0, 0.5, 0); glVertex2i(11, 31); glVertex2i(37, 71); glColor3f(0.5, 0, 0); // no effect struct { float x,y,z,w; // 37, 71, 0, 1 float r,g,b,a; // 0, 0.5, 0, 1 } vertex; Framebuffer

CS248 Lecture 2Kurt Akeley, Fall 2007 Vertex operations OpenGL n Transform coordinates n 4x4 matrix arithmetic n Compute (vertex) lighting n Compute texture coordinates n … In our case: n Scale (arbitrary 100x100) coordinates to fit window n No lighting, no texture coordinates Vertex assembly Primitive assembly Rasterization Fragment operations Display Vertex operations Application Primitive operations Framebuffer

CS248 Lecture 2Kurt Akeley, Fall 2007 Primitive assembly (data types) Vertex assembly Primitive assembly Rasterization Fragment operations Display Vertex operations Application Primitive operations struct { float x,y,z,w; float r,g,b,a; } vertex; struct { vertex v0,v1,v2; } triangle; struct { vertex v0,v1; } line; struct { vertex v0; } point; or Framebuffer

CS248 Lecture 2Kurt Akeley, Fall 2007 Primitive assembly OpenGL n Group vertexes into primitives: n points, n lines, or n triangles n Decompose polygons to triangles n Duplicate vertexes in strips or fans In our case: n Create two triangles from a strip: Vertex assembly Primitive assembly Rasterization Fragment operations Display Vertex operations Application Primitive operations glBegin(GL_TRIANGLE_STRIP); glColor(green); glVertex2i(…); // 0 glVertex2i(…); // 1 glColor(red); glVertex2i(…); // 2 glVertex2i(…); // 3 glEnd(); Framebuffer

CS248 Lecture 2Kurt Akeley, Fall 2007 Primitive operations OpenGL n Clip to the window boundaries n Actually to the frustum surfaces n Perform back-face / front-face ops n Culling n Color assignment for 2-side lighting In our case n Nothing happens Vertex assembly Primitive assembly Rasterization Fragment operations Display Vertex operations Application Primitive operations Framebuffer

CS248 Lecture 2Kurt Akeley, Fall 2007 Rasterization (data types) Vertex assembly Primitive assembly Rasterization Fragment operations Display Vertex operations Application Primitive operations struct { float x,y,z,w; float r,g,b,a; } vertex; struct { vertex v0,v1,v2 } triangle; struct { short int x,y; float depth; float r,g,b,a; } fragment; Framebuffer

CS248 Lecture 2Kurt Akeley, Fall 2007 Rasterization OpenGL n Determine which pixels are included in the primitive n Generate a fragment for each such pixel n Assign attributes (e.g., color) to each fragment In our case: Vertex assembly Primitive assembly Rasterization Fragment operations Display Vertex operations Application Primitive operations Framebuffer

CS248 Lecture 2Kurt Akeley, Fall 2007 Fragment operations OpenGL n Texture mapping n Fragment lighting (OpenGL 2.0) n Fog n Scissor test n Alpha test In our case, nothing happens: Vertex assembly Primitive assembly Rasterization Fragment operations Display Vertex operations Application Primitive operations Framebuffer

CS248 Lecture 2Kurt Akeley, Fall 2007 Framebuffer (2-D array of pixels) Vertex assembly Primitive assembly Rasterization Fragment operations Display Vertex operations Application Primitive operations struct { float x,y,z,w; float r,g,b,a; } vertex; struct { vertex v0,v1,v2 } triangle; struct { short int x,y; float depth; float r,g,b,a; } fragment; struct { int depth; byte r,g,b,a; } pixel; Framebuffer

CS248 Lecture 2Kurt Akeley, Fall 2007 Fragment  framebuffer operations OpenGL n Color blending n Depth testing (aka z-buffering) n Conversion to pixels In our case, conversion to pixels: Vertex assembly Primitive assembly Rasterization Fragment operations Display Vertex operations Application Primitive operations Key idea: images are built in the framebuffer, not just placed there! Framebuffer

CS248 Lecture 2Kurt Akeley, Fall 2007 Discussion

CS248 Lecture 2Kurt Akeley, Fall 2007 OpenGL is mechanism Programmer specifies operation modes: n Vertex n Transformation n Lighting n Primitive n Back-face culling n Fragment n Shading (texture and lighting) n Framebuffer (blending and depth testing) Great example is the diagram at the back of the old (out of print) “blue book” … Vertex assembly Primitive assembly Rasterization Fragment operations Display Vertex operations Application Primitive operations Framebuffer

CS248 Lecture 2Kurt Akeley, Fall 2007

CS248 Lecture 2Kurt Akeley, Fall 2007 Abstraction From the OpenGL specification, Section 1.5: Thus OpenGL is an abstraction n It doesn’t specify what does happen n It specifies what appears to happen “An implementation must produce results conforming to those produced by the specified methods, but there may be ways to carry out a particular computation that are more efficient than the one specified.”

CS248 Lecture 2Kurt Akeley, Fall 2007 Implementation = abstraction L2 FB SP L1 TF Thread Processor Vtx Thread Issue Setup / Rstr / ZCull Geom Thread IssuePixel Thread Issue Data Assembler Host SP L1 TF SP L1 TF SP L1 TF SP L1 TF SP L1 TF SP L1 TF SP L1 TF L2 FB L2 FB L2 FB L2 FB L2 FB Vertex assembly Primitive assembly Rasterization Fragment operations Vertex operations Application Primitive operations NVIDIA GeForce 8800OpenGL Pipeline Framebuffer

CS248 Lecture 2Kurt Akeley, Fall 2007 Declarative vs. imperative abstractions Declarative (what, not how) n Descriptive: specify input and desired result n E.g., OmitHiddenSurfaces(); n Example systems: n RenderMan scene description n Inventor and Performer scene graphs Imperative (how, not what) n Procedural: specify actions to create the result n E.g., EnableDepthBuffer(); n Example systems n PostScript and Xlib n OpenGL and Direct3D

CS248 Lecture 2Kurt Akeley, Fall 2007 Direct3D 10OpenGL 2.1 Graphics software stacks GeForce 8800 VRML web application Radeon 9600 Unreal engine Gears of War GPU graphics API scene graph application

CS248 Lecture 2Kurt Akeley, Fall 2007 Direct3D 10OpenGL 2.1 Levels of abstraction GeForce 8800 VRML web application Radeon 9600 Unreal engine Gears of War Imperative Declarative Specific, high leverage General, low leverage

CS248 Lecture 2Kurt Akeley, Fall 2007 An imperative API defines an architecture We mean architecture in the Brooks/Blaauw sense: n Separate from and above implementation OpenGL defines an architecture: Can separate architecture’s interface and mechanism: n Direct3D 10 (interface) n WGF 2.0 (mechanism) OpenGL 2.1 GeForce 8800

CS248 Lecture 2Kurt Akeley, Fall 2007 Additional OpenGL mechanisms Pixel pipeline Client-server operation Display lists Error behavior and reporting

CS248 Lecture 2Kurt Akeley, Fall 2007 OpenGL pixel pipeline Vertex assembly Primitive assembly Rasterization Fragment operations Display Vertex operations Application Primitive operations Framebuffer Texture memory Pixel assembly (unpack) Pixel operations Pixel pack Vertex pipelinePixel pipeline Application

CS248 Lecture 2Kurt Akeley, Fall 2007 Client-server operation OpenGL Client OpenGL Server Network Application Display (you) Client side Server side

CS248 Lecture 2Kurt Akeley, Fall 2007 Display lists glNewList( listname, …); glColor3f(…); glVertex3f(…); … glEndList(); glCallList( listname ); OpenGL Client OpenGL Server Network Application Display (you) Client side Server side Display list state

CS248 Lecture 2Kurt Akeley, Fall 2007 Error behavior and reporting No undefined operations n Architectural integrity n Application portability Queried, not returned n Why ? Enumerated error types n INVALID_ENUM n INVALID_VALUE n INVALID_OPERATION Should query after rendering OpenGL Client OpenGL Server Network Application Display (you)

CS248 Lecture 2Kurt Akeley, Fall 2007 Check for errors after rendering void CheckErrors() { bool got_error = false; while (int i = glGetError()) { got_error = true; fprintf(stderr, "ERROR: 0x%x\n", i); } if (got_error) exit(1); } Example application-defined error routine

CS248 Lecture 2Kurt Akeley, Fall 2007 OpenGL abstraction properties Immediate mode Orthogonality Programmability Details n Ordered operation n Modal state model n Synchronous operation

CS248 Lecture 2Kurt Akeley, Fall 2007 Immediate mode Different meanings to different people n Begin/End command sequences n Abstraction doesn’t maintain object descriptions n Vertex arrays stored on client side n Display lists don’t count n Implementation doesn’t queue indefinitely n E.g., doesn’t wait for all primitives before beginning to render OpenGL Client OpenGL Server Network Application Display (you)

CS248 Lecture 2Kurt Akeley, Fall 2007 Orthogonality Vertex assembly Primitive assembly Rasterization Fragment operations Display Vertex operations Application Primitive operations Framebuffer Texture memory Pixel assembly (unpack) Pixel operations Pixel pack Vertex pipelinePixel pipeline Application All primitives (including pixels) are rasterized All vertexes are treated equally (e.g., lighted) All fragments are treated equally (e.g., z-buffered)

CS248 Lecture 2Kurt Akeley, Fall 2007 Programmability Programmable “shaders,” of course Multi-pass composition n Intended from the start n Requires repeatability n Invariance and equivariance n Appendix A in OpenGL spec Vertex assembly Primitive assembly Rasterization Fragment operations Vertex operations Application Primitive operations Framebuffer  Application programmable

CS248 Lecture 2Kurt Akeley, Fall 2007 Abstraction details Ordered operation n Implementation may be out of order n But results must be as though computed in order Modal state model n Also in-order n Pipeline implementations require care Synchronous operation (as in synchronous i/o) n Data bound at call n Queries stall until data are ready and returned

CS248 Lecture 2Kurt Akeley, Fall 2007 Interface details Object naming (programmer-assigned, why) Lots of geometry-specification entry points (why)

CS248 Lecture 2Kurt Akeley, Fall 2007 Other things you should know Programming tips (Red book, Appendix G) n Correctness tips (e.g., pixel-exact 2-D rendering) n Performance tips (user/implementer contract) Extensions ( n Recent ones include history and examples n Great way to understand graphics algorithms

CS248 Lecture 2Kurt Akeley, Fall 2007 Summary OpenGL is an imperative abstraction (aka architecture) n Mechanism (the OpenGL pipeline) n Interface (API) to feed and manage the mechanism The pipeline is best understood in terms of data types: n Vertex n Primitive (point, line, triangle) n Fragment n Pixel You should trust and be familiar with the OpenGL specification

CS248 Lecture 2Kurt Akeley, Fall 2007 Reading assignment Before Tuesday’s class, read n FvD Aliasing and antialiasing n Return to the OpenGL specification n E.g., state tables Optional: n Set up your OpenGL/GLUT programming environment

CS248 Lecture 2Kurt Akeley, Fall 2007 End