PDA

View Full Version : problem with VBO



aistee
10-27-2008, 12:42 PM
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.

trinitrotoluene
10-27-2008, 01:01 PM
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?

aistee
10-27-2008, 01:43 PM
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

trinitrotoluene
10-27-2008, 02:16 PM
Access violation reading location 0x00000000 This seem to be there is a null pointer somewhere. Can you post your entire drawing call.

trinitrotoluene
10-27-2008, 02:20 PM
You use an OpenGL extension do you get the proc address of the function glBindBufferARB,glGenBuffersARB and glBufferDataARB.

aistee
10-27-2008, 02:30 PM
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);

trinitrotoluene
10-27-2008, 02:39 PM
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.

aistee
10-27-2008, 08:46 PM
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 :)

Thanks very much for Your help!!