So, I'm relatively new to graphics programming, as I'm mostly a tools guy by trade. I'm trying to play around with VertexBufferObjects/DrawArrays (are they synonyms? Seems like it, or at least they go hand in hand), but I'm not having any luck.
I've basically used Luke Philpot's code from the DevMaster wiki, with some modification in parts (it's not really correct and doesn't compile straight-away), but for some odd reason nothing shows up. My coordinates seem to be OK (if I use a standard glBegin()/glEnd(), I get a nice shiny triangle), but nothing shows up!
I've tried making a colour buffer, tried putting glEnable/DisableClientState() calls at the beginning/end of every frame, and various other things, but to no avail.
Can anyone see what I don't? All the tutorials I'm finding are so mixed up with other things I don't want to confuse myself with, I can't find a simple VBO-only tutorial.
Cheers.
// Framework
// (c) 2003 Luke Philpot.
#define BUFFER_OFFSET(i) ((char *)NULL + (i))
#define win32 // comment out for non win32
#ifdef win32
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#endif
#include <SDL/SDL.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include "glext.h"
// VBO Extension Definitions, From glext.h
#define GL_ARRAY_BUFFER_ARB 0x8892
#define GL_STATIC_DRAW_ARB 0x88E4
typedef void (APIENTRY * PFNGLBINDBUFFERARBPROC) (GLenum target, GLuint buffer);
typedef void (APIENTRY * PFNGLDELETEBUFFERSARBPROC) (GLsizei n, const GLuint *buffers);
typedef void (APIENTRY * PFNGLGENBUFFERSARBPROC) (GLsizei n, GLuint *buffers);
typedef void (APIENTRY * PFNGLBUFFERDATAARBPROC) (GLenum target, int size, const GLvoid *data, GLenum usage);
// VBO Extension Function Pointers
PFNGLGENBUFFERSARBPROC glGenBuffersARB = NULL; // VBO Name Generation Procedure
PFNGLBINDBUFFERARBPROC glBindBufferARB = NULL; // VBO Bind Procedure
PFNGLBUFFERDATAARBPROC glBufferDataARB = NULL; // VBO Data Loading Procedure
PFNGLDELETEBUFFERSARBPROC glDeleteBuffersARB = NULL; // VBO Deletion Procedure
int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR lpCmdLine, int nshow)
{
SDL_Event e; // for input
// init window
SDL_Init(SDL_INIT_VIDEO);
SDL_SetVideoMode(640, 480, 32, 2);
// set up OpenGL
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45, (float) 640 / (float) 480, 1, 512);
glBindBufferARB = (PFNGLBINDBUFFERARBPROC)wglGetProcAddress("glBindBufferARB");
glGenBuffersARB = (PFNGLGENBUFFERSARBPROC)wglGetProcAddress("glGenBuffersARB");
glBufferDataARB = (PFNGLBUFFERDATAARBPROC)wglGetProcAddress("glBufferDataARB");
// enable depth testing
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
GLfloat vertexData[] = { 0.f, 1.f, 0.f
, -1.f, -1.f, 0.f
, 1.f, -1.f, 0.f
};
GLuint vertexBuffer = 0;
glGenBuffersARB(1, &vertexBuffer);
glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0);
glBufferDataARB(GL_ARRAY_BUFFER_ARB, sizeof(vertexData), vertexData, GL_STATIC_DRAW_ARB);
glEnableClientState(GL_VERTEX_ARRAY);
while (!SDL_PollEvent(&e) || e.key.keysym.sym != SDLK_ESCAPE) // check whether esc has been pressed
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0, 0, -5);
glBindBufferARB(GL_ARRAY_BUFFER_ARB, vertexBuffer);
glVertexPointer(3, GL_FLOAT, 0, 0);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 3);
SDL_GL_SwapBuffers();
}
glDisableClientState( GL_VERTEX_ARRAY );
return 0;
}












