OpenGL/GLUT Intro. Week 1, Fri Jan 12

Similar documents
Rendering Pipeline/ OpenGL

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

Introduction to Computer Graphics with OpenGL/GLUT

OpenGL refresher. Advanced Computer Graphics 2012

Basic Graphics Programming

Lecture 4 of 41. Lab 1a: OpenGL Basics

Rendering Pipeline/ OpenGL

2 Transformations and Homogeneous Coordinates

Precept 2 Aleksey Boyko February 18, 2011

Computer Graphics. Bing-Yu Chen National Taiwan University

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

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

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

Exercise 1 Introduction to OpenGL

Graphics Programming

Basic Graphics Programming

GL_COLOR_BUFFER_BIT, GL_PROJECTION, GL_MODELVIEW

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


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

Computer graphics MN1

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

Programming using OpenGL: A first Introduction

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

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

Lectures OpenGL Introduction

Drawing Primitives. OpenGL basics

RECITATION - 1. Ceng477 Fall

Ulf Assarsson Department of Computer Engineering Chalmers University of Technology

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

Interaction Computer Graphics I Lecture 3

COMPUTER GRAPHICS LAB # 3

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

Interaction. CSCI 480 Computer Graphics Lecture 3

Interaction. CSCI 420 Computer Graphics Lecture 3

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

2/3/16. Interaction. Triangles (Clarification) Choice of Programming Language. Buffer Objects. The CPU-GPU bus. CSCI 420 Computer Graphics Lecture 3

Computer Graphics. OpenGL

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

Computer Graphics 1 Computer Graphics 1

Lecture 2 2D transformations Introduction to OpenGL

Ulf Assarsson Department of Computer Engineering Chalmers University of Technology

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

by modifying the glutinitwindowsize() function you can change the screen size to whatever you please.

Announcements OpenGL. Computer Graphics. Spring CS4815

Comp 410/510 Computer Graphics Spring Programming with OpenGL Part 2: First Program

Announcements OpenGL. Computer Graphics. Autumn 2009 CS4815

Hierarchical Modeling: Tree of Transformations, Display Lists and Functions, Matrix and Attribute Stacks,

Computer Graphics Course 2005

Rendering. Part 1 An introduction to OpenGL

Using OpenGL with CUDA

Abel J. P. Gomes LAB. 1. INTRODUCTION TO OpenGL

QUESTION 1 [10] 2 COS340-A October/November 2009

Class of Algorithms. Visible Surface Determination. Back Face Culling Test. Back Face Culling: Object Space v. Back Face Culling: Object Space.

An Introduction to. Graphics Programming

Input and Interaction. 1. Interaction. Chapter 3. Introduction: - We now turn to the development of interactive graphics programs.

CSC 8470 Computer Graphics. What is Computer Graphics?

C OMPUTER G RAPHICS Thursday

1.2 Basic Graphics Programming

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

Introduction to OpenGL

Lecture 3. Understanding of OPenGL programming

Graphics Hardware and OpenGL

Introduction to OpenGL

1/12/11. Basic Graphics Programming. What is OpenGL. OpenGL is cross-platform. How does OpenGL work. How does OpenGL work (continued) The result

1 (Practice 1) Introduction to OpenGL

CS 4204 Computer Graphics

CS418 OpenGL & GLUT Programming Tutorial (I) Presented by : Wei-Wen Feng 1/30/2008

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

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

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

Computer Graphics, Chapt 08

Image Processing. Geometry Processing. Reading: (Not really covered in our text. See Sects 18.1, 18.2.) Overview: Display

Computer graphics MN1

COMP 371/4 Computer Graphics Week 1

CSE4030 Introduction to Computer Graphics

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

3D Graphics and OpenGl. First Steps

Models and Architectures

Introduction to OpenGL Week 1

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

SOURCES AND URLS BIBLIOGRAPHY AND REFERENCES

Computer Graphics (Basic OpenGL)

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

API Background. Prof. George Wolberg Dept. of Computer Science City College of New York

LECTURE 02 OPENGL API

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

Modeling Objects by Polygonal Approximations. Linear and Affine Transformations (Maps)

Lecture 3 Advanced Computer Graphics (CS & SE )

CSC 470 Computer Graphics

CS 432 Interactive Computer Graphics

Programming with OpenGL Part 3: Three Dimensions

An Interactive Introduction to OpenGL Programming

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

Introduction to OpenGL: Part 2

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

Lecture 2 Sections 3.6, 3.7. Fri, Aug 28, 2009

CS Computer Graphics: OpenGL, Continued

CS Computer Graphics: OpenGL, Continued

Order of Transformations

Transcription:

University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2007 Tamara Munzner OpenGL/GLUT Intro Week 1, Fri Jan 12 http://www.ugrad.cs.ubc.ca/~cs314/vjan2007

News Labs start next week Reminder: my office hours Wed/Fri 11-12 in your 011 lab, not my X661 office Leftover handouts will be in 011 lab 2

Today s Readings today RB Chap Introduction to OpenGL RB Chap State Management and Drawing Geometric Objects RB App Basics of GLUT (Aux in v 1.1) 3

Readings for Next Four Lectures FCG Chap 6 Transformation Matrices except 6.1.6, 6.3.1 FCG Sect 13.3 Scene Graphs RB Chap Viewing Viewing and Modeling Transforms until Viewing Transformations Examples of Composing Several Transformations through Building an Articulated Robot Arm RB Appendix Homogeneous Coordinates and Transformation Matrices until Perspective Projection RB Chap Display Lists 4

5 Correction: Vector-Vector Multiplication multiply: vector * vector = scalar dot product, aka inner product ( ) ( ) ( ) 3 3 2 2 1 1 3 2 1 3 2 1 v u v u v u v v v u u u + + = u v cosθ v u v u = u v θ geometric interpretation lengths, angles can find angle between two vectors

6 Correction: Dot Product Example 19 6 7 6 (2*3) (1*7) (6*1) 3 7 1 2 1 6 = + + = + + = ( ) ( ) ( ) 3 3 2 2 1 1 3 2 1 3 2 1 v u v u v u v v v u u u + + =

Review: Working with Frames j o F 1 i p p = o +x i + yj F 2 i j o j F 3 i o F 1 p = (3,-1) F 2 p = (-1.5,2) F 3 p = (1,2) 7

More: Working with Frames F 1 j o F 1 i p p = o +x i + yj F 2 i j o j F 3 i o F 1 p = (3,-1) F 2 p = (-1.5,2) F 3 p = (1,2) 8

More: Working with Frames F 2 j o F 1 i p p = o +x i + yj F 2 i j o j F 3 i o F 1 p = (3,-1) F 2 p = (-1.5,2) F 3 p = (1,2) 9

More: Working with Frames F 3 j o F 1 i p p = o +x i + yj F 2 i j o j F 3 i o F 1 p = (3,-1) F 2 p = (-1.5,2) F 3 p = (1,2) 10

goal Rendering transform computer models into images may or may not be photo-realistic interactive rendering fast, but limited quality roughly follows a fixed patterns of operations rendering pipeline offline rendering ray tracing global illumination 11

Rendering tasks that need to be performed (in no particular order): project all 3D geometry onto the image plane geometric transformations determine which primitives or parts of primitives are visible hidden surface removal determine which pixels a geometric primitive covers scan conversion compute the color of every visible surface point lighting, shading, texture mapping 12

what is the pipeline? Rendering Pipeline abstract model for sequence of operations to transform geometric model into digital image abstraction of the way graphics hardware works underlying model for application programming interfaces (APIs) that allow programming of graphics hardware OpenGL Direct 3D actual implementation details of rendering pipeline will vary 13

Rendering Pipeline Geometry Database Model/View Transform. Lighting Perspective Transform. Clipping Scan Conversion Texturing Depth Test Blending Framebuffer 14

Geometry Database Geometry Database geometry database application-specific data structure for holding geometric information depends on specific needs of application triangle soup, points, mesh with connectivity information, curved surface 15

Model/View Transformation Geometry Database Model/View Transform. modeling transformation map all geometric objects from local coordinate system into world coordinates viewing transformation map all geometry from world coordinates into camera coordinates 16

Lighting Geometry Database Model/View Transform. Lighting lighting compute brightness based on property of material and light position(s) computation is performed per-vertex 17

Perspective Transformation Geometry Database Model/View Transform. Lighting Perspective Transform. perspective transformation projecting the geometry onto the image plane projective transformations and model/view transformations can all be expressed with 4x4 matrix operations 18

Clipping Geometry Database Model/View Transform. Lighting Perspective Transform. Clipping clipping removal of parts of the geometry that fall outside the visible screen or window region may require re-tessellation of geometry 19

Scan Conversion Geometry Database Model/View Transform. Lighting Perspective Transform. Clipping Scan Conversion scan conversion turn 2D drawing primitives (lines, polygons etc.) into individual pixels (discretizing/sampling) interpolate color across primitive generate discrete fragments 20

Texture Mapping Geometry Database Model/View Transform. Lighting Perspective Transform. Clipping Scan Conversion Texturing texture mapping gluing images onto geometry color of every fragment is altered by looking up a new color value from an image 21

Depth Test Geometry Database Model/View Transform. Lighting Perspective Transform. Clipping Scan Conversion Texturing Depth Test depth test remove parts of geometry hidden behind other geometric objects perform on every individual fragment other approaches (later) 22

Blending Geometry Database Model/View Transform. Lighting Perspective Transform. Clipping Scan Conversion Texturing Depth Test Blending blending final image: write fragments to pixels draw from farthest to nearest no blending replace previous color blending: combine new & old values with arithmetic operations 23

Framebuffer Geometry Database Model/View Transform. Lighting Perspective Transform. Clipping Scan Conversion Texturing Depth Test Blending Framebuffer framebuffer video memory on graphics board that holds image double-buffering: two separate buffers draw into one while displaying other, then swap to avoid flicker 155 0 155 0 155 0 155 0 0 155 155 155 155 0 0 0 0 0 0 24

Pipeline Advantages modularity: logical separation of different components easy to parallelize earlier stages can already work on new data while later stages still work with previous data similar to pipelining in modern CPUs but much more aggressive parallelization possible (special purpose hardware!) important for hardware implementations only local knowledge of the scene is necessary 25

limited flexibility Pipeline Disadvantages some algorithms would require different ordering of pipeline stages hard to achieve while still preserving compatibility only local knowledge of scene is available shadows, global illumination difficult 26

OpenGL (briefly) 27

OpenGL started in 1989 by Kurt Akeley based on IRIS_GL by SGI API to graphics hardware designed to exploit hardware optimized for display and manipulation of 3D graphics implemented on many different platforms low level, powerful flexible pipeline processing set state as needed 28

Graphics State set the state once, remains until overwritten glcolor3f(1.0, 1.0, 0.0) set color to yellow glsetclearcolor(0.0, 0.0, 0.2) dark blue bg glenable(light0) turn on light glenable(gl_depth_test) hidden surf. 29

Geometry Pipeline tell it how to interpret geometry glbegin(<mode of geometric primitives>) mode = GL_TRIANGLE, GL_POLYGON, etc. feed it vertices glvertex3f(-1.0, 0.0, -1.0) glvertex3f(1.0, 0.0, -1.0) glvertex3f(0.0, 1.0, -1.0) tell it you re done glend() 30

Open GL: Geometric Primitives glpointsize( ( float size); gllinewidth( ( float width); glcolor3f( float r, float g, float b);... 31

Code Sample void display() { glclearcolor(0.0, 0.0, 0.0, 0.0); glclear(gl_color_buffer_bit); glcolor3f(0.0, 1.0, 0.0); glbegin(gl_polygon); glvertex3f(0.25, 0.25, -0.5); glvertex3f(0.75, 0.25, -0.5); glvertex3f(0.75, 0.75, -0.5); glvertex3f(0.25, 0.75, -0.5); glend(); glflush(); } more OpenGL as course continues 32

GLUT 33

GLUT: OpenGL Utility Toolkit developed by Mark Kilgard (also from SGI) simple, portable window manager opening windows handling graphics contexts handling input with callbacks keyboard, mouse, window reshape events timing idle processing, idle events designed for small-medium size applications distributed as binaries free, but not open source 34

GLUT Draw World int main(int int argc,, char **argv argv) { glutinit( ( &argc& argc, argv ); glutinitdisplaymode( ( GLUT_RGB GLUT_DOUBLE GLUT_DEPTH); glutinitwindowsize( ( 640, 480 ); glutcreatewindow( ( "opengldemo" opengldemo" " ); glutdisplayfunc( DrawWorld ); glutidlefunc(idle); glclearcolor( ( 1,1,1 ); glutmainloop(); } return 0; // never reached 35

Event-Driven Programming main loop not under your control vs. batch mode where you control the flow control flow through event callbacks redraw the window now key was pressed mouse moved callback functions called from main loop when events occur mouse/keyboard state setting vs. redrawing 36

GLUT Callback Functions // you supply these kind of functions void reshape(int w, int h); void keyboard(unsigned char key, int x, int y); void mouse(int but, int state, int x, int y); void idle(); void display(); // register them with glut glutreshapefunc(reshape); glutkeyboardfunc(keyboard); glutmousefunc(mouse); glutidlefunc(idle); glutdisplayfunc(display); void glutdisplayfunc (void (*func func)(void)); void glutkeyboardfunc (void (*func func)(unsigned char key, int x, int y)); void glutidlefunc (void (*func func)()); void glutreshapefunc (void (*func func)( )(int width, int height)); 37

Display Function void DrawWorld() { glmatrixmode( GL_PROJECTION ); glloadidentity(); glmatrixmode( GL_MODELVIEW ); glloadidentity(); glclear( GL_COLOR_BUFFER_BIT ); angle += 0.05; glrotatef(angle,0,0,1); //animation //animation... // redraw triangle in new position glutswapbuffers(); } directly update value of angle variable so, why doesn't it spin? only called in response to window/input event! 38

void Idle() { angle += 0.05; glutpostredisplay(); } Idle Function called from main loop when no user input should return control to main loop quickly update value of angle variable here then request redraw event from GLUT draw function will be called next time through continues to rotate even when no user action 39

Keyboard/Mouse Callbacks do minimal work request redraw for display example: keypress triggering animation do not create loop in input callback! what if user hits another key during animation? shared/global variables to keep track of state display function acts on current variable value 40

Labs 41

Week 2 Lab labs start Tuesday project 0 http://www.ugrad.cs.ubc.ca/~cs314/vjan2007/a0 make sure you can compile OpenGL/GLUT very useful to test home computing environment template: spin around obj files todo: change rotation axis do handin to test configuration, but not graded 42

Remote Graphics OpenGL does not work well remotely very slow only one user can use graphics at a time current X server doesn t give priority to console, just does first come first served problem: FCFS policy = confusion/chaos solution: console user gets priority only use graphics remotely if nobody else logged on with who command, :0 is console person stop using graphics if asked by console user via email or console user can reboot machine out from under you 43