problem with VBO

Hi there,

I cant implement vbo … vertex array is fine. This is a little bit code:


			glGenBuffersARB( 1, &Colr );
			glBindBufferARB( GL_ARRAY_BUFFER_ARB, Colr );
			glBufferDataARB( GL_ARRAY_BUFFER_ARB, NumVertex*sizeof(float), Colors, GL_STATIC_DRAW_ARB );
			glColorPointer(3, GL_FLOAT, 0, 0);


			glGenBuffersARB( 1, &VertV );
			glBindBufferARB( GL_ARRAY_BUFFER_ARB, VertV );
			glBufferDataARB( GL_ARRAY_BUFFER_ARB, NumVertex*sizeof(float), Vertices, GL_STATIC_DRAW_ARB );
			glVertexPointer(3, GL_FLOAT, 0, 0);

(this code is before glEnableClientState’s)

in test i used these variables:

float Vertices[12]={0,0,0, 1,0,0, 1,1,0, 0,1,0};
float Colors[12]={255,0,0, 255,0,0, 255,0,0, 255,0,0};

unsigned int VertV;
unsigned int Colr;

(works fine without vbo)

Am I missing sth? Thanks for the time and help.

Do you call glBindBufferARB( GL_ARRAY_BUFFER_ARB, Colr ); ,glColorPointer(3, GL_FLOAT, 0, 0); and glBindBufferARB( GL_ARRAY_BUFFER_ARB, VertV );, glVertexPointer(3, GL_FLOAT, 0, 0); just before your drawing call?

yes.

I’ve also tried to call everything on start, and only glBufferDataARB and pointer before drawing function - no change.

I keep getting these:
Access violation reading location 0x00000000

Access violation reading location 0x00000000
This seem to be there is a null pointer somewhere. Can you post your entire drawing call.

You use an OpenGL extension do you get the proc address of the function glBindBufferARB,glGenBuffersARB and glBufferDataARB.

yes, im using this:

// 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

And the whole drawinf part:

glGenBuffersARB( 1, &Colr );
glBindBufferARB( GL_ARRAY_BUFFER_ARB, Colr );
glBufferDataARB( GL_ARRAY_BUFFER_ARB, NumVertex*sizeof(float), Colors, GL_STATIC_DRAW_ARB );
glColorPointer(3, GL_FLOAT, 0, 0);

glGenBuffersARB( 1, &VertV );
glBindBufferARB( GL_ARRAY_BUFFER_ARB, VertV );
glBufferDataARB( GL_ARRAY_BUFFER_ARB, NumVertex*sizeof(float), Vertices, GL_STATIC_DRAW_ARB );
glVertexPointer(3, GL_FLOAT, 0, 0);

glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_COLOR_ARRAY);

glDrawArrays(GL_QUADS, 0, NumVertex);

glDisableClientState(GL_COLOR_ARRAY);
glDisableClientState(GL_VERTEX_ARRAY);

SwapBuffers(hdc);

In the code you post I don’t see a wglGetProcAddress(“glGenBuffersARB”)…, just before you call glBindBufferARB,glGenBuffersARB and glBufferDataARB can you check the address of this functions (must not be NULL).


glGenBuffersARB( 1, &Colr );
glBindBufferARB( GL_ARRAY_BUFFER_ARB, Colr );
glBufferDataARB( GL_ARRAY_BUFFER_ARB, NumVertex*sizeof(float), Colors, GL_STATIC_DRAW_ARB );
glColorPointer(3, GL_FLOAT, 0, 0);


glGenBuffersARB( 1, &VertV );
glBindBufferARB( GL_ARRAY_BUFFER_ARB, VertV );
glBufferDataARB( GL_ARRAY_BUFFER_ARB, NumVertex*sizeof(float), Vertices, GL_STATIC_DRAW_ARB );
glVertexPointer(3, GL_FLOAT, 0, 0);

Call these only in your init function.


glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_COLOR_ARRAY);
glBindBufferARB( GL_ARRAY_BUFFER_ARB, VertV );
glVertexPointer(3, GL_FLOAT, 0, 0);
glBindBufferARB( GL_ARRAY_BUFFER_ARB, Colr );
glColorPointer(3, GL_FLOAT, 0, 0);
glDrawArrays(GL_QUADS, 0, NumVertex);
glDisableClientState(GL_COLOR_ARRAY);
glDisableClientState(GL_VERTEX_ARRAY);

This is your drawing code.

I updated my code as You said, and pasted this code before building section with these:


glGenBuffersARB = (PFNGLGENBUFFERSARBPROC) wglGetProcAddress("glGenBuffersARB");
glBindBufferARB = (PFNGLBINDBUFFERARBPROC) wglGetProcAddress("glBindBufferARB");
glBufferDataARB = (PFNGLBUFFERDATAARBPROC) wglGetProcAddress("glBufferDataARB");
glDeleteBuffersARB = (PFNGLDELETEBUFFERSARBPROC)
wglGetProcAddress("glDeleteBuffersARB");

Now everything works fine :slight_smile:

Thanks very much for Your help!!