Computer Graphics 3 Lecture 3: OpenGL Benjamin Mora 1 University of Wales Swansea Pr. Min Chen Dr. Benjamin Mora.

Slides:



Advertisements
Similar presentations
Understanding the graphics pipeline Lecture 2 Original Slides by: Suresh Venkatasubramanian Updates by Joseph Kider.
Advertisements

Graphics Pipeline.
2 COEN Computer Graphics I Evening’s Goals n Discuss the fundamentals of lighting in computer graphics n Analyze OpenGL’s lighting model n Show.
Computer Graphics(Fall 2003) COMS 4160, Lecture 7: OpenGL 3 Ravi Ramamoorthi Many slides courtesy Greg Humphreys.
OPENGL Return of the Survival Guide. Buffers (0,0) OpenGL holds the buffers in a coordinate system such that the origin is the lower left corner.
Computer Graphic Creator: Mohsen Asghari Session 2 Fall 2014.
The Graphics Pipeline CS2150 Anthony Jones. Introduction What is this lecture about? – The graphics pipeline as a whole – With examples from the video.
OpenGL (II). How to Draw a 3-D object on Screen?
3D Rendering with JOGL Introduction to Java OpenGL Graphic Library By Ricardo Veguilla
GPU Graphics Processing Unit. Graphics Pipeline Scene Transformations Lighting & Shading ViewingTransformations Rasterization GPUs evolved as hardware.
Programmable Pipelines. Objectives Introduce programmable pipelines ­Vertex shaders ­Fragment shaders Introduce shading languages ­Needed to describe.
1 OpenGL Basics A Graphics Standard ©Mel Slater, Anthony Steed
Basic OpenGL Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Wednesday, September 10, 2003.
CSE 381 – Advanced Game Programming Basic 3D Graphics
OpenGL Shading Language (Advanced Computer Graphics) Ernest Tatum.
Programmable Pipelines. 2 Objectives Introduce programmable pipelines ­Vertex shaders ­Fragment shaders Introduce shading languages ­Needed to describe.
Image Synthesis Rabie A. Ramadan, PhD 2. 2 Java OpenGL Using JOGL: Using JOGL: Wiki: You can download JOGL from.
Geometric transformations The Pipeline
Texture Mapping. Scope Buffers Buffers Various of graphics image Various of graphics image Texture mapping Texture mapping.
Korea University Korea University Computer Graphics Laboratory Computer Graphics Laboratory Jung Lee, Chapter 13.
CS 450: COMPUTER GRAPHICS REVIEW: INTRODUCTION TO COMPUTER GRAPHICS – PART 2 SPRING 2015 DR. MICHAEL J. REALE.
Advanced Computer Graphics Depth & Stencil Buffers / Rendering to Textures CO2409 Computer Graphics Week 19.
CSE 470: Computer Graphics. 10/15/ Defining a Vertex A 2D vertex: glVertex2f(GLfloat x, GLfloat y); 2D vertexfloating pointopenGL parameter type.
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,
Introduction to OpenGL 1. 2 OpenGL A Graphics rendering API introduced in 1992 by Silicon Graphics Inc Provide the low-level functions to access graphics.
CS 4363/6353 OPENGL BACKGROUND. WHY IS THIS CLASS SO HARD TO TEACH? (I’LL STOP WHINING SOON) Hardware (GPUs) double in processing power ever 6 months!
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
COMPUTER GRAPHICS CSCI 375. What do I need to know?  Familiarity with  Trigonometry  Analytic geometry  Linear algebra  Data structures  OOP.
GRAPHICS PIPELINE & SHADERS SET09115 Intro to Graphics Programming.
Programmable Pipelines Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts Director, Arts Technology Center University.
OpenGL: Introduction Yanci Zhang Game Programming Practice.
Computer Graphics 2 Lecture 7: Texture Mapping Benjamin Mora 1 University of Wales Swansea Pr. Min Chen Dr. Benjamin Mora.
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.
09/16/03CS679 - Fall Copyright Univ. of Wisconsin Last Time Environment mapping Light mapping Project Goals for Stage 1.
Advanced Computer Graphics Spring 2014 K. H. Ko School of Mechatronics Gwangju Institute of Science and Technology.
Viewing and Transformation. Pixel pipeline Vertex pipeline Course Map Transformation & Lighting Primitive assembly Viewport culling & clipping Texture.
Review on Graphics Basics. Outline Polygon rendering pipeline Affine transformations Projective transformations Lighting and shading From vertices to.
Chapters 5 2 March Classical & Computer Viewing Same elements –objects –viewer –projectors –projection plane.
Computer Graphics 3 Lecture 6: Other Hardware-Based Extensions Benjamin Mora 1 University of Wales Swansea Dr. Benjamin Mora.
OpenGL: The Open Graphics Language Introduction By Ricardo Veguilla.
1 Angel: Interactive Computer Graphics5E © Addison- Wesley 2009 Image Formation Fundamental imaging notions Fundamental imaging notions Physical basis.
11/5/2002 (c) University of Wisconsin, CS 559 Last Time Local Shading –Diffuse term –Specular term –All together –OpenGL brief overview.
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.
Real-Time Dynamic Shadow Algorithms Evan Closson CSE 528.
1 Programming with OpenGL Part 2: Complete Programs.
OpenGL API 2D Graphic Primitives Angel Angel: Interactive Computer Graphics5E © Addison-Wesley
1 Perception, Illusion and VR HNRS 299, Spring 2008 Lecture 15 Creating 3D Models.
1 E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012 Models and Architectures 靜宜大學 資訊工程系 蔡奇偉 副教授 2012.
An Introduction to the Cg Shading Language Marco Leon Brandeis University Computer Science Department.
GLSL Review Monday, Nov OpenGL pipeline Command Stream Vertex Processing Geometry processing Rasterization Fragment processing Fragment Ops/Blending.
Introduction to OpenGL (INF 250) Veronika Solteszova et al., UiB Dept. of Informatics,
Computer Graphics I, Fall Programming with OpenGL Part 2: Complete Programs.
OpenGL CS418 Computer Graphics John C. Hart. OpenGL Based on GL (graphics library) by Silicon Graphics Inc. (SGI) Advantages: Runs on everything, including.
OpenGL LAB III.
OpenGL: The Open Graphics Language Technology and Historical Overview By Ricardo Veguilla.
Introduction to 3-D Viewing Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Monday, October 27, 2003.
Computer Graphics (Fall 2003) COMS 4160, Lecture 5: OpenGL 1 Ravi Ramamoorthi Many slides courtesy Greg Humphreys.
Computer Graphics Lecture 34. OpenGL Programming II Taqdees A. Siddiqi
- Introduction - Graphics Pipeline
Draw a Simple Object.
Programmable Pipelines
Reference1. [OpenGL course slides by Rasmus Stenholt]
Programming with OpenGL Part 2: Complete Programs
Chapter 6 GPU, Shaders, and Shading Languages
CS451Real-time Rendering Pipeline
Models and Architectures
Programming with OpenGL Part 2: Complete Programs
OpenGL Background CS 4722.
Presentation transcript:

Computer Graphics 3 Lecture 3: OpenGL Benjamin Mora 1 University of Wales Swansea Pr. Min Chen Dr. Benjamin Mora

Content 2 Benjamin Mora University of Wales Swansea Introduction to OpenGL-NVidia Dawn Demo. Different “drawable” primitives in OpenGL. OpenGL Pipeline and Matrix Transformations. Lighting. Textures. Initialization of the OpenGL machine and OpenGL coding. Advanced Features.

Dawn Demo 3 Benjamin Mora University of Wales Swansea

Introduction 4 Benjamin Mora University of Wales Swansea

What Is OpenGL? 5 Benjamin Mora University of Wales Swansea OpenGL is a C (Graphics) Library allowing rendering (i.e., displaying) 3D objects like triangles. Conceived in such a way that most routines are hardware accelerated. Similar to Direct3D (DirectX, Microsoft) on many points. OpenGL 1.0 has been introduced in 1992 by SGI (Silicon Graphics Incorporation). Current Version 3.0. Available now on every PC equipped with a descent graphics card (NVidia, ATI, also Intel…).

What Is OpenGL? 6 Benjamin Mora University of Wales Swansea Pros: –Industry Standard (not only used in games) –Hardware-accelerated. Specially designed GPUs. Software-based versions are by far slower. –Portable (Linux, Windows, Macintosh, etc…). –Lot of documentation. The OpenGL Programming Guide 4th Edition The Official Guide to Learning OpenGL Version 1.4. OpenGL forums. –Still evolving: more and more options for more realistic renderings.

What Is OpenGL? 7 Benjamin Mora University of Wales Swansea Cons: –State Machine: Awful programming, difficult to debug, and difficult for beginners!!! Supposed to get better with the 3.0 release –Computer Graphics concepts must be learned. –Brute force approach: Hardware-Accelerated, but not optimized. –Not very flexible: Some computer graphics algorithms cannot take advantage of OpenGL. –Not the only way to display objects: Processing a huge amount of data can be faster in software under some conditions.

What Is OpenGL? 8 Benjamin Mora University of Wales Swansea OpenGL does not contain a window manager, so an OpenGL rendering context (i.e., an OpenGL windows) must be created through another library (MFCs (?), GLUT, FLTK, GTK…). To use OpenGL, the code should include the correct libraries and files: –#include –OpenGL extensions must be included separately. OpenGL is mainly used in a C/C++ context, but extensions of the API to other languages exist (OpenGL for java, delphi,…).

How OpenGL works? 9 Benjamin Mora University of Wales Swansea Aim: Rendering (i.e. displaying) a 3D scene. Objects are “rendered” (drawn) into an invisible frame-buffer (image). When all the objects have been processed, the frame-buffer becomes the new image appearing in your window (double buffering). –Ideally 30 fps or more.

How OpenGL works? 10 Benjamin Mora University of Wales Swansea Rendering an image needs two main steps. –Setting up the parameters. Telling OpenGL where the camera (viewpoint) is located. Telling OpenGL about the lights. –position of the lights. –Type of lighting, colors. Many other parameters according to the needs. –Telling the system where the primitives (basic forms like triangles that represent the object) are located in space. Previous parameters will be taken into account for rendering. If the object is opaque, primitives can be drawn in any order. Every time a primitive is declared, OpenGL rasterizes (drawn) it on the frame-buffer, and keeps only its visible parts using the z- buffer test.

How OpenGL works? 11 Benjamin Mora University of Wales Swansea The vertices send to the OpenGL machine follow a projection pipeline, before performing an on-screen rasterization (area filling) using a scan-line algorithm. Camera System Projection Primitive

How OpenGL works? 12 Benjamin Mora University of Wales Swansea Example: Primitives enter the graphics pipeline when specifying their vertex (points) location. Initial Frame-Buffer After the first primitive rasterization After the second primitive rasterization

Different “drawable” primitives in OpenGL 13 Benjamin Mora University of Wales Swansea

OpenGL primitives 14 Benjamin Mora University of Wales Swansea GL_POINTSGL_LINES GL_TRIANGLES 1 GL_LINE_STRIPGL_LINE_LOOP GL_TRIANGLE_STRIP GL_TRIANGLE_FANGL_QUADSGL_QUAD_STRIP GL_POLYGON

Sending primitives to OpenGL 15 Benjamin Mora University of Wales Swansea A primitive mode must be setup first (e.g., glBegin(GL_TRIANGLES)). Vertex coordinates must then be send to the pipeline –glVertex function, see later for code! GL_TRIANGLES case –Every time 3 consecutive vertices have been sent to the pipeline, a new triangle rasterization occurs.

Primitive Rasterization 16 Benjamin Mora University of Wales Swansea Every pixel on the projection is called a “fragment”. For every fragment, many parameters like the colors and transparency (RGBA), depth, and the texture coordinates are linearly interpolated. RasterizationLinear Interpolation

Primitive Rasterization 17 Benjamin Mora University of Wales Swansea Different types (precisions) of colors can be used with OpenGL: [Black Value..White Value] –GL_UNSIGNED_BYTE:[0..255]. –GL_UNSIGNED_SHORT:[ ]. –GL_FLOAT:[0..1.0]. Usually, colors are clamped to [0..1].

OpenGL Pipeline and Matrix Transformations 18 Benjamin Mora University of Wales Swansea

(Regular) OpenGL Pipeline 19 Benjamin Mora University of Wales Swansea 4D vertex coordinates are expressed in the camera coordinate system by applying a sequence of (4D) transformations. –Pipeline and matrices fixed before processing a flow of vertices. Modelview Matrix Projection Matrix Perspective Division Viewport Transformation Window Coordinates World coordinates Clip coordinates Normalized device coordinates Eye/Camera coordinates

OpenGL Pipeline 20 Benjamin Mora University of Wales Swansea o x z World coordinate system Object as stored in memory

OpenGL Pipeline 21 Benjamin Mora University of Wales Swansea o x z 1-Modelview transform: Moving objects in space 2-Projection transform: Take into consideration the camera. Coordinates are now expressed in the camera coordinate system 3-w division followed by the viewport transform then occur to find the vertex projections. Once this done for a sufficient number vertices (e.g., 3 for a triangle), object rasterization can happen

OpenGL Pipeline 22 Benjamin Mora University of Wales Swansea OpenGL is a state machine. –The matrices must be set before sending the graphic primitives (e.g. triangles) into the pipeline. –2 main matrix stacks actually: GL_MODELVIEW –Used to specify the camera position and/or the model position. GL_PROJECTION –Used in order to specify the projection type, and clip coordinates. Before applying transformations, the relevant stack must be specified: –Setting up the current matrix to modelview: glMatrixMode(GL_MODELVIEW); –Use glLoadIdentity() to reset it.

OpenGL Pipeline 23 Benjamin Mora University of Wales Swansea The current matrix is the matrix in top of the stack. –void glPushMatrix(); Make a copy of the matrix in top of the stack and put it on the top. –void glPopMatrix(); Remove the top matrix from the stack. Loading the identity matrix. –glLoadIdentity(); –Required before doing any rotation translation. Stacks are used because they are useful to specify relative coordinate systems.

OpenGL Pipeline: Modelview matrix 24 Benjamin Mora University of Wales Swansea The modelview matrix can be used to both set the camera location and to move objects in space. The projection matrix should be used to specify either the orthographic projection or the perspective projection –Use of either glOrtho or glFrustum to specify them –Used for normalizing coordinates between -1 and 1. Required for the quantization of the z value Rotation matrix created from an angle and a line in the direction x,y,z that cross the origin Translation Matrix

Projection Matrix: glOrtho 25 Benjamin Mora University of Wales Swansea Need to specify a 6-face box with 6 parameters. Normalized coordinates between -1 and 1 after this stage. void glOrtho(glDouble left, glDouble right, glDouble. bottom,glDouble top, glDouble near, glDouble far);

Projection Matrix: glFrustum 26 Benjamin Mora University of Wales Swansea void glFrustum(glDouble left, glDouble right, glDouble bottom,glDouble top, glDouble near, glDouble far); Non Linearity:

Perspective Division 27 Benjamin Mora University of Wales Swansea Once the vertices have been transformed, we need to know their projection into the image space. Image coordinates are still expressed as [-1, 1] Projection on x [-1..1] Fragment Depth

Viewport 28 Benjamin Mora University of Wales Swansea Map the normalized x and y coordinates to a portion of the image. void glViewport(GLint x, GLint y, GLsizei width, GLsizei height); 0,0 x,y x+width, y+height image

Viewport 29 Benjamin Mora University of Wales Swansea Map the normalized x and y coordinates to a portion of the image. void glViewport(GLint x, GLint y, GLsizei width, GLsizei height); 0,0 x,y x+width, y+height image

Z-Buffer test 30 Benjamin Mora University of Wales Swansea Example: Final image Final z-buffer

Z-Buffer test 31 Benjamin Mora University of Wales Swansea Once the vertices projected, rasterization occurs. Primitives can be sent to the graphics hardware in any order, thanks to the z-buffer test that will keep the nearest fragments. A z value is stored for every pixel (z-buffer). Algorithm: If the rasterized z-value is less than the current z-value Then replace the previous color and z-value by the new ones

Stencil test 32 Benjamin Mora University of Wales Swansea A stencil buffer can be used for implementing complex algorithms (e.g., Shadow volumes). A value is associated with every pixel. The stencil test is performed after the z-test and compare the current stencil value with a reference value. The stencil value can possibly be incremented every time a fragment passes the stencil test.

Stencil test 33 Benjamin Mora University of Wales Swansea

Lighting. 34 Benjamin Mora University of Wales Swansea

OpenGL Lighting Model 35 Benjamin Mora University of Wales Swansea In real life, every material has its own reflection properties (called BRDF, i.e. Bidirectional Reflectance Distribution Function). Illumination is computed from the light source position, the surface orientation and the camera position. Illumination is computed at the vertices, and then interpolated for every fragment.

OpenGL Lighting Model (Phong) 36 Benjamin Mora University of Wales Swansea 3 components: –Ambiant. Do not depend of the light source. –Diffuse. The light is evenly reflected in all direction. –Specular. The reflection is predominant in a given direction. The specular coefficient can be varied. The light intensity can decrease according the distance (constant, linear or quadratic).

OpenGL Lighting Model 37 Benjamin Mora University of Wales Swansea

OpenGL Lighting Model 38 Benjamin Mora University of Wales Swansea OpenGL formula: A “light” can be created, specifying all the required constants for the light. A “material” can be created in OpenGL, specifying all the constants for the surface.

Model Limitations 39 Benjamin Mora University of Wales Swansea No native shadows. –Shadows can be implemented by using specific algorithms and texture mapping. Phong shading is just an imperfect model. –Global (i.e. realistic) illumination can not be done efficiently. Better to interpolate normals first, and then compute shading. Faked Normals. –The actual surface derivative do not usually match the specified normal.

Texture Mapping 40 Benjamin Mora University of Wales Swansea OpenGL interpolates the texture coordinates for every rasterized fragment and then fetches the pixel from the texture. Textures are stored on the graphics board and are highly optimized. –Textures must be loaded first. –Texture coordinates must be attributed to vertices at the same time as vertex normals and vertex coordinates. See next slides.

Initialization of the OpenGL Machine and OpenGL Coding. 41 Benjamin Mora University of Wales Swansea

OpenGL Coding 42 Benjamin Mora University of Wales Swansea First, set the parameters. –Viewpoint (camera). –Lights. –Materials. –Textures. –Etc… Second, tell OpenGL the primitives to render, possibly specifying for every vertex its: –Colors. –Normals. –Texture Coordinates.

OpenGL Coding 43 Benjamin Mora University of Wales Swansea #include Enabling some specific features: –void glEnable(GLenum cap); –void glDisable(GLenum cap); –glEnable(GL_DEPTH_TEST);//Enabling z-buffer –glEnable(GL_LIGHTING);//Enabling lighting. –glEnable(GL_LIGHT0);//Enabling light 0 (at least 8 lights) –glEnable(GL_TEXTURE_2D);//Enabling 2D textures –…

OpenGL Coding 44 Benjamin Mora University of Wales Swansea Specifying the current matrix: –void glMatrixMode (GLenum mode); glMatrixMode(GL_MODELVIEW); glMatrixMode(GL_PROJECTION); Initializing the current matrix: –void glLoadIdentity(); Handling the matrix stack: –void glPushMatrix ( );//New copy on the top of the stack. –void glPopMatrix ( ); //Remove the top of the stack.

OpenGL Coding 45 Benjamin Mora University of Wales Swansea Rotations (modifying the current matrix): –void glRotated ( GLdouble angle, GLdouble x, GLdouble y, GLdouble z ); –void glRotatef ( GLfloat angle, GLfloat x, GLfloat y, GLfloat z ); Translations (modifying the current matrix): –void glTranslated ( GLdouble x, GLdouble y, GLdouble z ); –void glTranslatef ( GLfloat x, GLfloat y, GLfloat z ); Scaling (modifying the current matrix): –void glScaled ( GLdouble x, GLdouble y, GLdouble z ); –void glScalef ( GLfloat x, GLfloat y, GLfloat z );

OpenGL Coding 46 Benjamin Mora University of Wales Swansea Erasing the Frame-Buffer: –void glClearColor ( GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha ); //Defines a clear color –void glClear ( GLbitfield mask ); //Clear the image Examples: –glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_ACCUM_BUFFER_BIT | GL_STENCIL_BUFFER_BIT );

OpenGL Coding 47 Benjamin Mora University of Wales Swansea Sending graphics primitives to the OpenGL machine: glBegin(GL_LINES); //Specify lines. Could be GL_TRIANGLES, etc… //First vertex glColor3f(1.0,0.,0.);//3 float colors for the first vertex glNormal3f(0.707,0.707,0); //first normal glTexcoord2f(0,0); //First texture coordinate glVertex3f(500,100,2); //first vertex //Second vertex glColor4f(1.0,0.,0.,1.);//4 float colors (last value: opacity) glNormal3fv(v); //gives a vector of float as parameters glTexcoord2f(1,1); //Second texture coordinate glVertex3d(500,100,2);//double instead of float glEnd(); // End of the vertex flow

OpenGL Coding 48 Benjamin Mora University of Wales Swansea Initializing lighting void GLRenderer::InitLighting() { float ambiant[4]= {0.2,0.2,0.2,1.}; float diffuse[4]= {0.7,0.7,0.7,1.}; float specular[4]= {1,1,1,1.}; float exponent=8; //glMatrixMode(GL_MODELVIEW); //glLoadIdentity(); //Be careful here: the lights go through the OpenGL transform pipeline float lightDir[4] = {0,0,1,0}; glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); glLightfv(GL_LIGHT0,GL_AMBIENT,ambiant); glLightfv(GL_LIGHT0,GL_DIFFUSE,diffuse); glLightfv(GL_LIGHT0,GL_SPECULAR,specular); glLightf(GL_LIGHT0,GL_SPOT_EXPONENT,exponent); glLightfv(GL_LIGHT0, GL_SPOT_DIRECTION, lightDir); }

OpenGL Coding 49 Benjamin Mora University of Wales Swansea Initializing texturing unsigned int *textureId=new unsigned int[nbOfTextures]; glGenTextures(nbOfTextures,textureId); for (i=0;i<nbOfTextures;i++) { glBindTexture(GL_TEXTURE_2D, textureId[i]); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexImage2D(GL_TEXTURE_2D, 0, 3, textureDimensionsX[i], textureDimensionsY[i], 0,GL_RGB,GL_UNSIGNED_BYTE, texture[i]); }

Advanced Features. 50 Benjamin Mora University of Wales Swansea

Advanced Features 51 Benjamin Mora University of Wales Swansea Limitations: –OpenGL 1.1 was limited to the Phong shading model. –Pixel precision may depend on the graphics card manufacturer (usually 8 bits per color). –Creating real-time shadows and more complex effects is difficult. –Power-of-two textures. –Fixed rendering pipeline. –Only one possible rendering per frame. Main manufacturers: ATI, NVidia, SGI, XGI. Functionalities and extensions may differ from the different manufacturers => Specific code must often be developed for each platform.

Advanced Features: Vertex Arrays 52 Benjamin Mora University of Wales Swansea On modern PC platforms, the video card communicate with the CPU through a “slow” AGP or PCI-express bus. Too much communication can kill performance. –e.g., processing a lot of small triangles. The fast video memory associated with the GPU can be used to store the vertices and reduce the communication bandwidth.

Advanced Features: Vertex Arrays 53 Benjamin Mora University of Wales Swansea Up to six arrays can be specified: void VertexPointer ( int size, enum type, sizei stride, void *pointer ) ; void ColorPointer ( int size, enum type, sizei stride, void *pointer ) ; void TexCoordPointer ( int size, enum type, sizei stride, void *pointer ) ; void IndexPointer ( enum type, sizei stride, void *pointer ) ; void NormalPointer ( enum type, sizei stride, void *pointer ) ; void EdgeFlagPointer ( sizei stride, void *pointer ) ;

Advanced Features: Vertex Arrays 54 Benjamin Mora University of Wales Swansea Other functions are required to make it work. void EnableClientState ( enum array ) ; void DisableClientState ( enum array ) ; void ArrayElement ( int i ) ; void DrawArrays ( enum mode, int first, sizei count ) ; void DrawElements ( enum mode, sizei count, enum type, void *indices ) ;

Advanced Features: Extensions 55 Benjamin Mora University of Wales Swansea Since OpenGL 1.2, extensions are supported. Main Extensions: –Floating-point extensions to get a better precision at the frame buffer level. ATI: 24 bit precision (now 32). NVidia: 16 or 32 bit precision. High Dynamic Range (HDR) images, Tone Mapping. –Non-Power-of-Two textures: Saves memory. –Render-to-Texture (Cube Maps). Shadow Maps. –Bump-Mapping. –Vertex and Fragment programs. Floating-point precision at the program level.

Advanced Features: Extensions 56 Benjamin Mora University of Wales Swansea char* extensionsList = (char*) glGetString(GL_EXTENSIONS); // All the supported extensions are inside the string // extensionsList. //Example for getting the 3D texture functionality. //First step: Declare a function type typedef void (APIENTRY * PFNGLTEXIMAGE3DPROC) (GLenum target, GLint level, GLint internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid *pixels) PFNGLTEXIMAGE3DPROC glTexImage3D; // Declare a function pointer glTexImage3D= (PFNGLTEXIMAGE3DPROC) wglGetProcAddress("glTexImage3D"); //Get the pointer address;

Advanced Features: Render to texture 57 Benjamin Mora University of Wales Swansea Allows rendering into an intermediate image that will be re-used in the final image. –Useful for (cube or spherical map) environmental mapping. –Mirroring effects. –Reflections. –Refractions. –Lighting effects. –Bump mapping. –Vertex Textures.

Advanced Features: Shadows 58 Benjamin Mora University of Wales Swansea How to efficiently compute shadows that are compatible with current graphics hardware ? Two possibilities: –Shadow Maps. See CS 307 –Shadow Volumes.

Advanced Features: Shadow Volume 59 Benjamin Mora University of Wales Swansea Image created by Steve Leach using OpenOffice Draw (v1.9.95), 30 May 2005 for use in the Shadow Volumes article.

Advanced Features: Shadow Volume 60 Benjamin Mora University of Wales Swansea Encode the surface of regions (volumes) of the scene that are located inside the penumbra. Make use of the stencil test after having rendered the scene. –Stencil buffer initialized to 0. –Every fragment that passes the z-test adds +1 to the stencil value. –If even count at the end => object visible from light source. Exact shadow contours. Shadow volumes are hard to update when the scene is complex and dynamic.