University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2007 Tamara Munzner OpenGL/GLUT Intro Week.

Slides:



Advertisements
Similar presentations
Computer Graphics - Graphics Programming -
Advertisements

OpenGL CMSC340 3D Character Design & Animation. What is OpenGL? A low-level graphics library specification designed for use with the C and C++ provides…
Chapter 2: Graphics Programming
Computer Graphics CSCE 441
Graphics Pipeline.
CS 4731 Lecture 2: Intro to 2D, 3D, OpenGL and GLUT (Part I) Emmanuel Agu.
University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2007 Tamara Munzner Transformations I Week.
University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2005 Tamara Munzner Transformations Week 2,
Transformations II Week 2, Wed Jan 17
University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2008 Tamara Munzner Math Review Rendering.
Computer Graphics (Fall 2008) COMS 4160, Lecture 9: OpenGL 1
OpenGL (Graphics Library) Software Interface to graphics software Allows to create interactive programs that produce color images of moving 3D objects.
CSC 461: Lecture 51 CSC461 Lecture 5: Simple OpenGL Program Objectives: Discuss a simple program Discuss a simple program Introduce the OpenGL program.
#4: OpenGL Implementation & Project 2 CSE167: Computer Graphics TAs: Alex Kozlowski & Cameron Chrisman UCSD, Winter 2006.
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
Computer Graphics (Fall 2005) COMS 4160, Lecture 10: OpenGL 1
University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2008 Tamara Munzner OpenGL, GLUT, Transformations.
Based on slides created by Edward Angel
University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2005 Tamara Munzner Rendering Pipeline OpenGL/GLUT.
Introduction to OpenGL Jian Huang This set of slides are extracted from the Interactive OpenGL Programming course given by Dave Shreine, Ed Angel and Vicki.
Reference1. [OpenGL course slides by Rasmus Stenholt]
Using Graphics Libraries Lecture 3 Mon, Sep 1, 2003.
Computer Graphics Bing-Yu Chen National Taiwan University.
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.
University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2010 Tamara Munzner GLUT, Transformations.
CSE 470: Computer Graphics. 10/15/ Defining a Vertex A 2D vertex: glVertex2f(GLfloat x, GLfloat y); 2D vertexfloating pointopenGL parameter type.
Lecture 3 OpenGL.
Computer Graphics I, Fall 2010 Input and Interaction.
CSC 461: Lecture 3 1 CSC461 Lecture 3: Models and Architectures  Objectives –Learn the basic design of a graphics system –Introduce pipeline architecture.
Homogeneous Form, Introduction to 3-D Graphics Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Monday, October 20,
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 Figures are extracted from Angel's book (ISBN x) The Human Visual System vs The Pinhole camera Human Visual System Visible Spectrum Pinhole.
CD2012 Principles of Interactive Graphics Lecture 01 Introduction Abir Hussain (Rome: 6.33,Tel , Web:
Introduction to GL Geb Thomas. Example Code int main(int argc, char **argv) { glutInit(&argc, argv); glutInitDisplayMode ( GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH);
1Computer Graphics Lecture 4 - Models and Architectures John Shearer Culture Lab – space 2
COMPUTER GRAPHICS CSCI 375. What do I need to know?  Familiarity with  Trigonometry  Analytic geometry  Linear algebra  Data structures  OOP.
Interactive Computer Graphics CS 418 MP1: Dancing I TA: Zhicheng Yan Sushma S Kini Mary Pietrowicz Slides Taken from: “An Interactive Introduction to OpenGL.
Introduction to OpenGL  OpenGL is a graphics API  Software library  Layer between programmer and graphics hardware (and software)  OpenGL can fit in.
Introduction to OpenGL and GLUT. What’s OpenGL? An Application Programming Interface (API) A low-level graphics programming API – Contains over 250 functions.
Program 2 due 02/01  Be sure to document your program  program level doc  your name  what the program does  each function  describe the arguments.
Review on Graphics Basics. Outline Polygon rendering pipeline Affine transformations Projective transformations Lighting and shading From vertices to.
Chun-Yuan Lin Introduction to OpenGL 2015/12/19 1 CG.
NoufNaief.net TA: Nouf Al-harbi.
GLUT functions glutInit allows application to get command line arguments and initializes system gluInitDisplayMode requests properties for the window.
CSCE 441: Computer Graphics
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
Introduction to Graphics Programming. Graphics API.
Introduction to Graphics Programming. Graphics: Conceptual Model Real Object Human Eye Display Device Graphics System Synthetic Model Synthetic Camera.
Computer Graphics I, Fall Programming with OpenGL Part 2: Complete Programs.
CS380 LAB II OpenGL Donghyuk Kim Reference1. [OpenGL course slides by Rasmus Stenholt] Reference2. [
INTRODUCTION TO OPENGL
Computer Graphics (Fall 2003) COMS 4160, Lecture 5: OpenGL 1 Ravi Ramamoorthi Many slides courtesy Greg Humphreys.
The Human Visual System vs The Pinhole camera
Computer Graphics Lecture 33
Programming with OpenGL Part 2: Complete Programs
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.
גרפיקה ממוחשבת: מבוא ל-OpenGL
Rendering Pipeline, OpenGL/GLUT
Introduction to OpenGL
Rendering Pipeline Week 2, Mon Jan 11
Programming with OpenGL Part 2: Complete Programs
Programming with OpenGL Part 2: Complete Programs
OpenGL, GLUT, Transformations I Week 2, Wed Jan 16
Programming with OpenGL Part 2: Complete Programs
Presentation transcript:

University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2007 Tamara Munzner OpenGL/GLUT Intro Week 1, Fri Jan 12

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

3 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)

4 Readings for Next Four Lectures FCG Chap 6 Transformation Matrices except 6.1.6, 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

5 Correction: Vector-Vector Multiplication multiply: vector * vector = scalar dot product, aka inner product geometric interpretation lengths, angles can find angle between two vectors

6 Correction: Dot Product Example

7 Review: Working with Frames F1F1F1F1 F1F1F1F1 p = (3,-1) F2F2F2F2 p = (-1.5,2) F3F3F3F3 p = (1,2) F2F2F2F2 F3F3F3F3

8 More: Working with Frames F1F1F1F1 F1F1F1F1 p = (3,-1) F2F2F2F2 p = (-1.5,2) F3F3F3F3 p = (1,2) F2F2F2F2 F3F3F3F3 F1F1F1F1

9 More: Working with Frames F1F1F1F1 F1F1F1F1 p = (3,-1) F2F2F2F2 p = (-1.5,2) F3F3F3F3 p = (1,2) F2F2F2F2 F3F3F3F3 F2F2F2F2

10 More: Working with Frames F1F1F1F1 p = (3,-1) F2F2F2F2 p = (-1.5,2) F3F3F3F3 p = (1,2) F1F1F1F1 F2F2F2F2 F3F3F3F3 F3F3F3F3

11 Rendering goal 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

12 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

13 Rendering Pipeline what is the 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

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

15 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 Geometry Database Geometry Database

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

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

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

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

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

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

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

23 Blending Geometry Database Geometry Database Model/View Transform. Model/View Transform. Lighting Perspective Transform. Perspective Transform. Clipping Scan Conversion Scan Conversion Depth Test Depth Test Texturing 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

24 Framebuffer Geometry Database Geometry Database Model/View Transform. Model/View Transform. Lighting Perspective Transform. Perspective Transform. Clipping Scan Conversion Scan Conversion Depth Test Depth Test Texturing Blending Frame- buffer Frame- buffer 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

25 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

26 Pipeline Disadvantages limited flexibility 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

27 OpenGL (briefly)

28 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

29 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.

30 Geometry Pipeline tell it how to interpret geometry glBegin( ) 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()

31 Open GL: Geometric Primitives glPointSize( float size); glLineWidth( float width); glColor3f( float r, float g, float b);....

32 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

33 GLUT

34 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

35 GLUT Draw World int main(int argc, char **argv) { glutInit( &argc, argv ); glutInit( &argc, argv ); glutInitDisplayMode( GLUT_RGB | glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH); GLUT_DOUBLE | GLUT_DEPTH); glutInitWindowSize( 640, 480 ); glutCreateWindow( "openGLDemo" ); glutDisplayFunc( DrawWorld ); glutIdleFunc(Idle); glClearColor( 1,1,1 ); glutMainLoop(); return 0; // never reached }

36 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

37 GLUT Callback Functions // you supply these kind of 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 // register them with glut glutReshapeFunc(reshape); glutKeyboardFunc(keyboard); glutMouseFunc(mouse); glutIdleFunc(idle); glutDisplayFunc(display); void glutDisplayFunc (void (*func)(void)); void glutKeyboardFunc (void (*func)(unsigned char key, int x, int y)); void glutIdleFunc (void (*func)()); void glutReshapeFunc (void (*func)(int width, int height));

38 Display Function void DrawWorld() { glMatrixMode( GL_PROJECTION ); glLoadIdentity(); glMatrixMode( GL_MODELVIEW ); glLoadIdentity(); glClear( GL_COLOR_BUFFER_BIT ); angle += 0.05;//animation glRotatef(angle,0,0,1);//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!

39 Idle Function void Idle() { angle += 0.05; glutPostRedisplay(); } 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

40 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

41 Labs

42 Week 2 Lab labs start Tuesday project 0 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

43 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 or console user can reboot machine out from under you