| DevMaster.net |
| [[ Home | Forums | 3D Engines Database | Wiki | Articles/Tutorials | Game Dev Jobs | IRC Chat Network | Contact Us ]] |
| Using OpenGL's Vertex Buffer Extension (ARB_vertex_buffer_object) |
|
|
|
08/07/2003
|
||
IntroductionNote: This tutorial assumes basic OpenGL/extensions knowledge. InitializationFirst of all, we need to be able to actually use the extension's functions. Since the OpenGL headers and library files haven't been updated since OpenGL 1.1 (on Windows), we need to use wglGetProcAddress() to get the functions. PFNGLBINDBUFFERARBPROC glBindBufferARB = NULL;
PFNGLGENBUFFERSARBPROC glGenBuffersARB = NULL;
PFNGLBUFFERDATAARBPROC glBufferDataARB = NULL;
[check whether extension is supported]
glBindBufferARB = (PFNGLBINDBUFFERARBPROC) wglGetProcAddress("glBindBufferARB");
glGenBuffersARB = (PFNGLGENBUFFERSARBPROC) wglGetProcAddress("glGenBuffersARB");
glBufferDataARB = (PFNGLBUFFERDATAARBPROC) wglGetProcAddress("glBufferDataARB");
We also need a buffer and something to put in it. GLfloat data[] = { -1.0f, 1.0f, 0.0f,
-1.0f, -1.0f, 0.0f,
1.0f, -1.0f, 0.0f };
GLuint buffer = 0;
Creating a bufferThe functions used for creating buffers are just like the standard OpenGL texture functions. glGenBuffersARB(1, &buffer); glBindBufferARB(GL_ARRAY_BUFFER_ARB, buffer); glBufferDataARB(GL_ARRAY_BUFFER_ARB, sizeof(data), data, GL_STATIC_DRAW_ARB); So what does this block of code do? glGenBuffersARB creates a buffer, glBindBufferARB binds it (duh) and glBufferDataARB uploads the vertex array to the graphics card. Using the bufferThis is the easy part :) glBindBufferARB(GL_ARRAY_BUFFER_ARB, buffer); glVertexPointer(3, GL_FLOAT, 0, 0); glDrawArrays(GL_TRIANGLE_STRIP, 0, 3); Easy eh? ConclusionWell, now you should have some basic vertex buffers up and running. I hope this was of some use to you! |
|
|
| © 2003-2004 DevMaster.net. All Rights Reserved. Terms of Use & Privacy Policy | Want to write for us? Click here |