OpenGL Objects Finalised. Debugging Tip For Debugging your applications remember: glGetError(); gluErrorString(); Don’t use these in release code (the.

Slides:



Advertisements
Similar presentations
Chapter 11. Faster Geometry Throughput Presented by Garrett Yeh.
Advertisements

1Computer Graphics Building Models John Shearer Culture Lab – space 2
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Building Models modified by Ray Wisman Ed Angel Professor of Computer Science,
1 Building Models. 2 Objectives Introduce simple data structures for building polygonal models ­Vertex lists ­Edge lists OpenGL vertex arrays.
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.
CS 4363/6353 BASIC RENDERING. THE GRAPHICS PIPELINE OVERVIEW Vertex Processing Coordinate transformations Compute color for each vertex Clipping and Primitive.
03/12/02 (c) 2002 University of Wisconsin, CS559 Last Time Some Visibility (Hidden Surface Removal) algorithms –Painter’s Draw in some order Things drawn.
CAP4730: Computational Structures in Computer Graphics Visible Surface Determination.
Hidden Surface Removal Why make the effort?  Realistic models.  Wasted time drawing. OpenGL and HSR  OpenGL does handle HSR using the depth buffer.
2IV60 Computer graphics Graphics primitives and attributes Jack van Wijk TU/e.
 The success of GL lead to OpenGL (1992), a platform-independent API that was  Easy to use  Close enough to the hardware to get excellent performance.
1 Dr. Scott Schaefer Hidden Surfaces. 2/62 Hidden Surfaces.
Meshes Dr. Scott Schaefer. 3D Surfaces Vertex Table.
CGDD 4003 THE MASSIVE FIELD OF COMPUTER GRAPHICS.
Computer Graphics Ben-Gurion University of the Negev Fall 2012.
Introduction to OpenGL Joseph Kider University of Pennsylvania CIS 565 – Fall 2011 (Source: Patrick Cozzi)
Hidden Surface Elimination Wen-Chieh (Steve) Lin Institute of Multimedia Engineering I-Chen Lin’ CG Slides, Rich Riesenfeld’s CG Slides, Shirley, Fundamentals.
Visible-surface Detection Computer Graphics Seminar MUM
Vertices and Fragments III Mohan Sridharan Based on slides created by Edward Angel 1 CS4395: Computer Graphics.
COMP Advanced Graphics Advanced Graphics: Performance.
10/11/2001CS 638, Fall 2001 Today Kd-trees BSP Trees.
Sprite Batching and Texture Atlases Randy Gaul. Overview Batches Sending data to GPU Texture atlases Premultiplied alpha Note: Discussion on slides is.
09/18/03CS679 - Fall Copyright Univ. of Wisconsin Last Time Bump Mapping Multi-pass algorithms.
Hidden Surface Removal
Shadows Computer Graphics. Shadows Shadows Extended light sources produce penumbras In real-time, we only use point light sources –Extended light sources.
Computer Graphics: Programming, Problem Solving, and Visual Communication Steve Cunningham California State University Stanislaus and Grinnell College.
Basic OpenGL Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Wednesday, September 10, 2003.
Modeling. Geometric Models  2D and 3D objects  Triangles, quadrilaterals, polygons  Spheres, cones, boxes  Surface characteristics  Color  Texture.
CS559: Computer Graphics Lecture 33: Shape Modeling Li Zhang Spring 2008.
CSE 381 – Advanced Game Programming Basic 3D Graphics
Triangulation Introduction to Computer Graphics and Animation (Principle of Computer Graphics) Rattapoom Waranusast.
Texturing A picture is worth a thousand words. Texturing Texturing is the art of doing this with any picture to any model.  (This is Opus the Penguin.
COMP 261 Lecture 16 3D Rendering. input: set of polygons viewing direction direction of light source(s) size of window. output: an image Actions rotate.
Speeding Up Rendering After Deciding What to Draw.
CSC418 Computer Graphics n BSP tree n Z-Buffer n A-buffer n Scanline.
Visible-Surface Detection Jehee Lee Seoul National University.
Emerging Technologies for Games Alpha Sorting and “Soft” Particles CO3303 Week 15.
CS 638, Fall 2001 Multi-Pass Rendering The pipeline takes one triangle at a time, so only local information, and pre-computed maps, are available Multi-Pass.
Interactive Computer Graphics CS 418 – Spring 2015 Mesh Rendering, Transformation, Camera Viewing and Projection in OpenGL TA: Zhicheng Yan Sushma S Kini.
State Management and Drawing Geometry Objects
DirectX Objects Finalised Paul Taylor Packing Your Objects
CS-378: Game Technology Lecture #2.2: Clipping and Hidden Surfaces Prof. Okan Arikan University of Texas, Austin Thanks to James O’Brien, Steve Chenney,
Representation. Objectives Introduce concepts such as dimension and basis Introduce coordinate systems for representing vectors spaces and frames for.
Implementation II Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico.
Computer Graphics Bing-Yu Chen National Taiwan University.
Implementation II.
1 3D API OPENGL ES v1.0 Owned by Silicon Graphics (SGL) Control was then transferred to Khronos Group Introduction.
09/16/03CS679 - Fall Copyright Univ. of Wisconsin Last Time Environment mapping Light mapping Project Goals for Stage 1.
UniS CS297 Graphics with Java and OpenGL State Management and Drawing Primative Geometric Objects.
Computer Graphics I, Fall 2010 Implementation II.
1 CSCE 441: Computer Graphics Hidden Surface Removal Jinxiang Chai.
OpenGL Vertex Arrays OpenGL vertex arrays store vertex properties such as coordinates, normal vectors, color values and texture coordinates. These properties.
BSP Tree Supplement Jyun-Ming Chen. Fall Kd-Tree and BSP tree kd-tree is a special kind of bsp tree.
Computer Graphics I, Fall 2010 Building Models.
Computer Graphics Inf4/MSc 1 Computer Graphics Lecture 5 Hidden Surface Removal and Rasterization Taku Komura.
A study of efficiency INDEX BUFFERS JEFF CHASTINE 1.
09/23/03CS679 - Fall Copyright Univ. of Wisconsin Last Time Reflections Shadows Part 1 Stage 1 is in.
Introduction to OpenGL (INF 250) Veronika Solteszova et al., UiB Dept. of Informatics,
Texture Mapping CEng 477 Introduction to Computer Graphics.
UMBC GDC Programming Tutorial
Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009
Scene Manager Creates and places movable objects like lights and cameras so as to access them efficiently, e.g. for rendering. Loads and assembles world.
Computer Graphics Implementation II
Hidden Surfaces Dr. Scott Schaefer.
CSCE 441: Computer Graphics Hidden Surface Removal
Building Models Ed Angel
Isaac Gang University of Mary Hardin-Baylor
Angel: Interactive Computer Graphics5E © Addison-Wesley 2009
Geometric Objects and Transformations (I)
Computer Graphics Vertex Array Object
Presentation transcript:

OpenGL Objects Finalised

Debugging Tip For Debugging your applications remember: glGetError(); gluErrorString(); Don’t use these in release code (the render loop), as fetching the error from the card is slow!!!

Packing Your Objects

My Stupid Tetrahedron glBegin( GL_TRIANGLE_FAN ); glColor3f(1.0f,0.0f,0.0f); glVertex3f( 0.0f, 1.0f, 0.0f ); glColor3f(0.0f,1.0f,0.0f); glVertex3f( 0.5f, 0.0f, 0.0f ); glColor3f(0.0f,0.0f,1.0f); glVertex3f( -0.5f, 0.0f, 0.0f ); glColor3f(0.0f,1.0f,1.0f); glVertex3f( 0.0f, 0.0f, -1.0f ); glColor3f(1.0f,0.0f,1.0f); glVertex3f( 0.5f, 0.0f, 0.0f ); glEnd(); glBegin( GL_TRIANGLES ); glColor3f(0.5f,1.0f,0.5f); glVertex3f( 0.5f, 0.0f, 0.0f ); glVertex3f( -0.5f, 0.0f, 0.0f ); glVertex3f( 0.0f, 0.0f, -1.0f ); glEnd();

The Basic Packing Code GLuInt Beef = glGenLists( 1); glNewList( Beef) ……\\ Object List glEndList(); content/uploads/2007/04/heres-the-beef.jpg

Lists can work in a hierarchy glNewList(Cow); glTranslatef(…) glCallList(Beef); glTranslatef(…) glCallList(Beef); glTranslatef(…) glCallList(Beef); glEndList(); content/uploads/2007/04/heres-the-beef.jpg

Old Old way of drawing the Tetrahedron glBegin( GL_TRIANGLE_FAN ); glColor3f(1.0f,0.0f,0.0f); glVertex3f( 0.0f, 1.0f, 0.0f ); glColor3f(0.0f,1.0f,0.0f); glVertex3f( 0.5f, 0.0f, 0.0f ); glColor3f(0.0f,0.0f,1.0f); glVertex3f( -0.5f, 0.0f, 0.0f ); glColor3f(0.0f,1.0f,1.0f); glVertex3f( 0.0f, 0.0f, -1.0f ); glColor3f(1.0f,0.0f,1.0f); glVertex3f( 0.5f, 0.0f, 0.0f ); glEnd(); glBegin( GL_TRIANGLES ); glColor3f(0.5f,1.0f,0.5f); glVertex3f( 0.5f, 0.0f, 0.0f ); glVertex3f( -0.5f, 0.0f, 0.0f ); glVertex3f( 0.0f, 0.0f, -1.0f ); glEnd();

New Way glCallList(Tetrahedron); om/Geometry/Tetrahedr on_files/image004.jpg

Our Objects are now in nice packages – glCallList(Cow) Rendering code looks very nice But it still requires a lot of calls to OpenGL

glNewList(Tetrahedron); glBegin( GL_TRIANGLE_FAN ); glColor3f(1.0f,0.0f,0.0f); glVertex3f( 0.0f, 1.0f, 0.0f ); glColor3f(0.0f,1.0f,0.0f); glVertex3f( 0.5f, 0.0f, 0.0f ); glColor3f(0.0f,0.0f,1.0f); glVertex3f( -0.5f, 0.0f, 0.0f ); glColor3f(0.0f,1.0f,1.0f); glVertex3f( 0.0f, 0.0f, -1.0f ); glColor3f(1.0f,0.0f,1.0f); glVertex3f( 0.5f, 0.0f, 0.0f ); glEnd(); glBegin( GL_TRIANGLES ); glColor3f(0.5f,1.0f,0.5f); glVertex3f( 0.5f, 0.0f, 0.0f ); glVertex3f( -0.5f, 0.0f, 0.0f ); glVertex3f( 0.0f, 0.0f, -1.0f ); glEnd(); glEndList(); What Really Happens glCallList(Tetrahedron);

Say Hello to Vertex Arrays Array Types: Vertex Normal Colour Index Texture Coordinate Array Edge Flag Array

Declaring an Array GLfloat vertices[8] = { (0.0,1.0,0.0), (0.5,0.0,0.0), (-0.5,0.0,0.0), (0.0,0.0,-1.0), (0.5,0.0,0.0), (0.0,0.0,-1.0), (-0.5,0.0,-0.0.0), (0.0,0.0,-1.0), };

Enabling and Disabling your Arrays glEnableClientState(array); glDisableClientState(array); Client state refers to system memory!! GL_COLOR_ARRAY – Array for Vertex Colours GL_EDGE_FLAG_ARRAY – Array for Wireframe (Line Drawing) GL_INDEX_ARRAY – Array of Arrays GL_NORMAL_ARRAY – Normals (typically Per Vertex) GL_TEXTURE_COORD_ARRAY – Duh! GL_VERTEX_ARRAY – Duh!

Accessing Your Array glVertexPointer(): specify pointer to vertex coordinates array glNormalPointer(): specify pointer to normal array glColorPointer(): specify pointer to RGB colour array glIndexPointer(): specify pointer to indexed colour array glTexCoordPointer(): specify pointer to texture cordinates array glEdgeFlagPointer(): specify pointer to edge flag array

Drawing From an Array Set The Vertex Pointer – glVertexPointer(…); Use the array in the Draw Function – glDrawArrays();

Old Way of Drawing the Tetrahedron glBegin( GL_TRIANGLE_FAN ); glColor3f(1.0f,0.0f,0.0f); glVertex3f( 0.0f, 1.0f, 0.0f ); glColor3f(0.0f,1.0f,0.0f); glVertex3f( 0.5f, 0.0f, 0.0f ); glColor3f(0.0f,0.0f,1.0f); glVertex3f( -0.5f, 0.0f, 0.0f ); glColor3f(0.0f,1.0f,1.0f); glVertex3f( 0.0f, 0.0f, -1.0f ); glColor3f(1.0f,0.0f,1.0f); glVertex3f( 0.5f, 0.0f, 0.0f ); glEnd(); glBegin( GL_TRIANGLES ); glColor3f(0.5f,1.0f,0.5f); glVertex3f( 0.5f, 0.0f, 0.0f ); glVertex3f( -0.5f, 0.0f, 0.0f ); glVertex3f( 0.0f, 0.0f, -1.0f ); glEnd();

Drawing the Tetrahedron With an Array GLfloat vertices[8] = { (0.0,1.0,0.0), (0.5,0.0,0.0), (-0.5,0.0,0.0), (0.0,0.0,-1.0), (0.5,0.0,0.0), (0.0,0.0,-1.0), (-0.5,0.0,-0.0.0), (0.0,0.0,-1.0), }; // Enable the vertex Array glEnableClientState(GL_VERTEX_ARRAY); glVertexPointer(3, GL_FLOAT, 0, vertices); // draw a tetrahedron glDrawArray(GL_TRIANGLE_FAN, 0, 4); glDrawArray(GL_TRIANGLES, 3, 3; // deactivate vertex array glDisableClientState(GL_VERTEX_ARRAY);

Even Faster Ways of Drawing We have used glDrawArrays(mode, first, count); The other options we have are: – glDrawElements(mode, count, type, indices); – glDrawRangeElements(mode, start, end, count, type, indicies); // An optimised version of glDrawElements

Declaring a Better Array GLfloat vertices[4] = { (0.0,1.0,0.0), (0.5,0.0,0.0), (-0.5,0.0,0.0), (0.0,0.0,-1.0)}; Glfloat indicies[12] = {0,1,2, 0,2,3, 0,3,1, 1,2,3};

Drawing the Tetrahedron Faster GLfloat vertices[4] = {...} Glflaot indicies[12] = {…} // Enable the vertex Array glEnableClientState(GL_VERTEX_ARRAY); glVertexPointer(3, GL_FLOAT, 0, vertices); // draw a tetrahedron glDrawElements(GL_TRIANGLES, 12, GL_UNSIGNED_BYTE, indices); // deactivate vertex array glDisableClientState(GL_VERTEX_ARRAY);

You can’t always share your normals!

Partitioning your world ClearCut.jpg

Binary Spacial Partitioning (BSP) In today's gaming world, there are two important reasons for dividing the world – Rendering without the Z-Buffer – Rendering Translucent (Alpha Blend) Polygons

Why? Modern games have so many polygons that stretching the z buffer to cover the entire object range would result in many visual glitches, as many polygons start falling into the same depth levels of the buffer. Translucent Polygons are created using a blend function which requires back-to-front rendering (Painters algorithm)

How? There are many differing ways and methods to create maps of polygons, especially static collections One of the most common and a very efficient way is utilising BSP trees. – The first use of a BSP tree was Doom in 1993 It was only used in a 2D implementation!

A BSP is a specialised implementation of a Binary Data Tree Binary Trees are used because: the ability to be efficiently traversed in both directions The ability to add data randomly during the building of the tree The speed in which a random location can be found

Binary Data Trees gif/CompleteBinaryTree_1000.gif /features/trees2/BuildTree1.gif

The Principal to creating a BSP Tree Each polygon (3D) / line (2D) creates a dividing line / plane in the tree where every other Polygon/line is either in front or behind.

Cutting your Polygons The offending Polygon / Line must be cut into two parts It then becomes two separate polygons / lines One infront of the division, the other behind

Reordering the split If we split using the red/green line first, our tree would require no splitting

Problems Creating BSP Lists Minimising Polygon Cuts Balancing the Tree

A short 2D Example

Creating a BSP Tree for Lines (Doom Style)