Download presentation
Presentation is loading. Please wait.
1
30/1/2006Based on: Angel (4th Edition) & Akeine-Möller & Haines (2nd Edition)1 CSC345: Advanced Graphics & Virtual Environments Lecture 1: Introduction to OpenGL (1) Patrick Olivier p.l.olivier@ncl.ac.uk 2 nd floor in the Devonshire Building
2
31/1/2006Based on: Angel (4th Edition) & Akeine-Möller & Haines (2nd Edition)2 Course structure Introduction to OpenGL Visual appearance (fogging & transparency) Discrete Techniques (aliasing & textures) Advanced lighting & shading (shadows & reflections) Curves & curved surfaces Solid object modelling Visualisation Procedural modelling Acceleration algorithms Intersection and collision detection Non-photorealistic rendering Virtual environments
3
31/1/2006Based on: Angel (4th Edition) & Akeine-Möller & Haines (2nd Edition)3 Required reading (1) Edward Angel: “Interactive Computer Graphics: A Top-Down Approach Using OpenGL” 3 rd Edition Addison Wesley, 2002 Required for theory
4
31/1/2006Based on: Angel (4th Edition) & Akeine-Möller & Haines (2nd Edition)4 Required reading (2) Put image here Edward Angel: “OpenGL: A Primer” 2 nd Edition Addison Wesley, 2004 Compulsory for practicals
5
31/1/2006Based on: Angel (4th Edition) & Akeine-Möller & Haines (2nd Edition)5 Extra reading… Put image here Tomas Akeine-Möller & Eric Haines: “Real-time Rendering” 2 nd Edition AK Peters, 2002 Advanced topics & for serious graphics types
6
31/1/2006Based on: Angel (4th Edition) & Akeine-Möller & Haines (2nd Edition)6 Extra reading… Put image here “OpenGL Programming Guide: The Official Guide to Learning OpenGL” 4 th Edition Addison Wesley, 2004 Old version online: see module webpages
7
31/1/2006Based on: Angel (4th Edition) & Akeine-Möller & Haines (2nd Edition)7 Practical (programming) schedule… 1. Two-dimensional programming & C (OpenGL primer: ch. 2) 2. Two-dimensional programming & C (OpenGL primer: ch. 2) Exercise 1 (worth 3% is due: 13 th February) 3. Interaction & animation (OpenGL primer: ch. 3) 4. Basic three-dimensional programming (OpenGL primer: ch. 4) 5. Transformations (OpenGL primer: ch. 5) Exercise 2 (worth 3% is due: 6 th March) 6. Lights & materials (OpenGL primer: ch. 6) 7. Images (OpenGL primer: ch. 7) 8. Texture mapping (OpenGL primer: ch. 8) Exercise 3 (worth 4% is due: 27 th March) 9. Curves & surfaces (OpenGL primer: ch. 9) Exercise 4 (worth 15% is due: 12 th May) Exam is worth 80% date to be confirmed
8
31/1/2006Based on: Angel (4th Edition) & Akeine-Möller & Haines (2nd Edition)8 OpenGL library OpenGL core library OpenGL32 on Windows GL on most unix/linux systems (libGL.a) OpenGL Utility Library (GLU) Provides functionality in OpenGL core but avoids having to rewrite code Links with window system GLX for X window systems WGL for Windows AGL for Macintosh
9
31/1/2006Based on: Angel (4th Edition) & Akeine-Möller & Haines (2nd Edition)9 GLUT library OpenGL Utility Toolkit (GLUT) Provides functionality common to all window systems open a window get input from mouse and keyboard menus event-driven Code is portable but GLUT lacks functionality of a good toolkit for a specific platform e.g. no slide bars
10
31/1/2006Based on: Angel (4th Edition) & Akeine-Möller & Haines (2nd Edition)10 OpenGL architecture Immediate Mode Display List Polynomial Evaluator Per Vertex Operations & Primitive Assembly Rasterization Per Fragment Operations Texture Memor y CPU Pixel Operations Frame Buffer geometry pipeline
11
31/1/2006Based on: Angel (4th Edition) & Akeine-Möller & Haines (2nd Edition)11 OpenGL functions Primitives Points Line Segments Polygons Attributes Transformations Viewing Modeling Control (GLUT) Input (GLUT) Query
12
31/1/2006Based on: Angel (4th Edition) & Akeine-Möller & Haines (2nd Edition)12 OpenGL state OpenGL is a state machine OpenGL functions are of two types Primitive generating Can cause output if primitive is visible How vertices are processed and appearance of primitive are controlled by the state State changing Transformation functions Attribute functions
13
31/1/2006Based on: Angel (4th Edition) & Akeine-Möller & Haines (2nd Edition)13 OpenGL is not object oriented so that there are multiple functions for a given logical function glVertex3f glVertex2i glVertex3dv Underlying storage mode is the same Function format: OpenGL function format function name glVertex3f(x,y,z) belongs to GL library x,y,z are floats dimensions glVertex3fv(p) p is a pointer to an array
14
31/1/2006Based on: Angel (4th Edition) & Akeine-Möller & Haines (2nd Edition)14 OpenGL #defines Most constants are defined in the include files gl.h, glu.h and glut.h Note #include should automatically include the others Examples: glBegin(GL_POLYGON) glClear(GL_COLOR_BUFFER_BIT) include files also define OpenGL data types: GLfloat, GLdouble,….
15
31/1/2006Based on: Angel (4th Edition) & Akeine-Möller & Haines (2nd Edition)15 A simple program: simple.c #include void mydisplay(){ glClear(GL_COLOR_BUFFER_BIT); glBegin(GL_POLYGON); glVertex2f(-0.5, -0.5); glVertex2f(-0.5, 0.5); glVertex2f(0.5, 0.5); glVertex2f(0.5, -0.5); glEnd(); glFlush(); } int main(int argc, char** argv){ glutCreateWindow("simple"); glutDisplayFunc(mydisplay); glutMainLoop(); }
16
31/1/2006Based on: Angel (4th Edition) & Akeine-Möller & Haines (2nd Edition)16 Event loop & defaults program defines display callback function named mydisplay every glut program must have a display callback display callback is executed whenever OpenGL decides the display must be refreshed, (e.g the window is opened) main function end by entering an event loop simple.c is too simple makes heavy use of state variable defaults viewing / colours / window parameters next version makes defaults more explicit
17
31/1/2006Based on: Angel (4th Edition) & Akeine-Möller & Haines (2nd Edition)17 Compilation Unix/linux include files usually in …/include/GL compile with –lglut –lglu –lgl loader flags may have to add –L flag for X libraries make file provided on module webpage Windows (Visual Studio) get glut.h, glut32.lib and glut32.dll from web create a console application add opengl32.lib, glut32.lib, glut32.lib to project settings (under link tab)
18
31/1/2006Based on: Angel (4th Edition) & Akeine-Möller & Haines (2nd Edition)18 Program structure most OpenGL programs have same structure: main() defines the callback functions opens one or more windows with the required properties enters event loop (last executable statement) init() sets the state variables (viewing / attributes) callbacks… display function input and window functions rewrite simple.c that sets colour, view & window…
19
31/1/2006Based on: Angel (4th Edition) & Akeine-Möller & Haines (2nd Edition)19 #include int main(int argc, char** argv) { glutInit(&argc,argv); glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB); glutInitWindowSize(500,500); glutInitWindowPosition(0,0); glutCreateWindow("simple"); glutDisplayFunc(mydisplay); init(); glutMainLoop(); } main.c …define window size …define window position …set OpenGL state …enter event loop
20
31/1/2006Based on: Angel (4th Edition) & Akeine-Möller & Haines (2nd Edition)20 GLUT functions glutInit allows application to get command line arguments and initializes system gluInitDisplayMode requests properties for the window (the rendering context) RGB color single buffering properties logically ORed together glutWindowSize in pixels glutWindowPosition from top-left corner of display glutCreateWindow create window with title “simple” glutDisplayFunc display callback glutMainLoop enter infinite event loop
21
31/1/2006Based on: Angel (4th Edition) & Akeine-Möller & Haines (2nd Edition)21 init.c void init() { glClearColor (0.0, 0.0, 0.0, 1.0); /* first 3 values = black, final = opaque */ glColor3f(1.0, 1.0, 1.0); /* set current draw colour to white */ glMatrixMode (GL_PROJECTION); glLoadIdentity (); glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0); /* bounds of the view volume */ }
22
31/1/2006Based on: Angel (4th Edition) & Akeine-Möller & Haines (2nd Edition)22 Coordinate systems & cameras units of glVertex in object coordinates viewing specifications also in object coordinates OpenGL converts to camera (eye) coordinates and later to screen coordinates OpenGL puts camera at the origin pointing in -z direction direction The default viewing volume is a box centered at the origin of length 2
23
31/1/2006Based on: Angel (4th Edition) & Akeine-Möller & Haines (2nd Edition)23 Transformations and viewing In OpenGL, projection is carried out by a projection matrix (transformation) There is only one set of transformation functions so we must set the matrix mode first glMatrixMode (GL_PROJECTION) Transformation functions are incremental so: we start with an identity matrix alter it with projection matrix that gives the view volume glLoadIdentity(); glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0);
24
31/1/2006Based on: Angel (4th Edition) & Akeine-Möller & Haines (2nd Edition)24 2-D and 3-D viewing The near & far distances are measured from the camera, in: glOrtho(left,right,bottom,top,near,far) Two-dimensional vertex commands place all vertices in the plane z=0 If the application is in two dimensions, we can use the function: gluOrtho2D(left,right,bottom,top) In two dimensions, the view or clipping volume becomes a clipping window
25
31/1/2006Based on: Angel (4th Edition) & Akeine-Möller & Haines (2nd Edition)25 mydisplay.c void mydisplay() { glClear(GL_COLOR_BUFFER_BIT); glBegin(GL_POLYGON); glVertex2f(-0.5, -0.5); glVertex2f(-0.5, 0.5); glVertex2f(0.5, 0.5); glVertex2f(0.5, -0.5); glEnd(); glFlush(); }
Similar presentations
© 2024 SlidePlayer.com Inc.
All rights reserved.