Presentation is loading. Please wait.

Presentation is loading. Please wait.

Computer Graphics Ben-Gurion University of the Negev Fall 2012.

Similar presentations


Presentation on theme: "Computer Graphics Ben-Gurion University of the Negev Fall 2012."— Presentation transcript:

1 Computer Graphics Ben-Gurion University of the Negev Fall 2012

2  Display Lists  Vertex Arrays  Vertex Buffer Objects 2

3  Group of OpenGL commands that have been compiled for later execution  Vertex and pixel data are evaluated and copied into the display list memory  You can reuse it repeatedly without re-evaluating and re- transmitting data  It reduces CPU cycles to perform the actual data transfer  Expensive computations (transformation, lighting …) are processed only once while display list is created Static or Dynammic ? 3

4  Drawing a cube consists of:  Drawing 6 Quads – Faces  Each face needs 4 glVertex*() calls  24 glVertex*() calss in total  What about glColor* ( 24 ) and glNormals*( 24 ) ?  We can notice that vertices are shared among faces 4

5  Using vertex array reduces the number of function calls  It also reduces the redundant usage of shared vertices 5 arrays are transferred to the video adapter every frame drawing

6  OpenGL provides functions to activate and deactivate 6 different types of arrays glEnableClientState(), glDisableClientState()  There are 6 functions to specify the exact positions of arrays  glVertexPointer(): specify pointer to vertex coords array  glNormalPointer(): specify pointer to normal array  glColorPointer(): specify pointer to RGB color array  glTexCoordPointer(): specify pointer to texture cords array 6

7 glVertexPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *pointer)  size: specifies the number of coordinates per vertex. Default is 4.  type: GL_SHORT, GL_INT, GL_FLOAT, or GL_DOUBLE are accepted  stride: specifies the byte offset between consecutive vertices  pointer: specifies a pointer to the first coordinate of the first vertex in the array. 7

8  Enhances the performance of OpenGL  providing the benefits of vertex array and display list while avoiding their downsides  Allows vertex array data to be stored in graphics memory  Vertex buffer objects can be modified after its creation 8

9  Creating a VBO requires 3 steps:  Generate a new buffer object with glGenBuffersARB().  Bind the buffer object with glBindBufferARB().  Copy vertex data to the buffer object with glBufferDataARB(). 9

10  Requires 2 parameters:  the first one is the number of buffer objects to create  the second parameter is the address of a GLuint variable or array to store a single ID or multiple IDs glGenBuffersARB(GLsizei n, GLuint* ids) 10

11  Hooks the buffer object with the corresponding ID glBindBufferARB(GLenum target, GLuint id)  Target is a hint to tell VBO whether this buffer object will store vertex array data or index array data  GL_ARRAY_BUFFER_ARB (vertex array)  Vertex coordinates  Texture coordinates  Normals  and more  GL_ELEMENT_ARRAY_BUFFER_ARB (index array) 11

12 glBufferDataARB(GLenum target, GLsizei size, const void* data, GLenum usage)  target: GL_ARRAY_BUFFER_ARB/ GL_ELEMENT_ARRAY_BUFFER_ARB  size: number of bytes of data to transfer  data: pointer to the source data  Usage: provide how the buffer object is going to be used  GL_STATIC_DRAW_ARB  GL_DYNAMIC_DRAW_ARB 12

13 13

14 14 Switch VBO off


Download ppt "Computer Graphics Ben-Gurion University of the Negev Fall 2012."

Similar presentations


Ads by Google