Sign in to follow this  
DuckMaster

VBO help

Recommended Posts

Ok guys, I've searched the internet, forums (including these ones), documentation, I just dont know what to do. I was making a sort of VBO wrapper, and everything was going nice and smooth until I realized it didn't work lol. So basically my problem is, the whole glVertexPointer thing. Your supposed to pass an offset to the buffer as the last argument, but when I do that, it just crashes. It only works if I pass the pointer to the vertices in it, like a normal vertex array. I am binding buffers before I make these calls, and im not really sure what the problem is so maybe someone can help me out. Ill paste a compact version of my code too eVboID is just an enum I pass to find out which buffer im going to be using. I was setting up this wrapper so you could pass in a buffer id to setup vertices, indices, texture verts, and normals int CVBO :: Create( eVboID eID, eVboType eType, int iNumOfVerts ) { if ( iNumOfVerts < 3 ) return 1; VBO_t* pCurrent = GetObj( eID ); if ( pCurrent != NULL ) { pCurrent->m_NumOfVerts = iNumOfVerts; glGenBuffersARB( 1, &pCurrent->m_ID ); if ( !glIsBufferARB( pCurrent->m_ID ) ) return 1; //Not techincally created until data //has been written to the buffer pCurrent->Created = false; } return 0; } void CVBO :: WriteNewBufferData( eVboID eID, int iNewSize, const void* cvpVerts ) { GLenum BindFlag = Bind( eID ); VBO_t* pCurrent = GetObj( eID ); if ( pCurrent == NULL ) return; if ( pCurrent->m_ID == 0 ) return; int NumSize = 0; if ( iNewSize > 3 ) { pCurrent->m_NumOfVerts = iNewSize; if ( eID == ID_TEXVERTS ) NumSize = iNewSize * 2; else NumSize = iNewSize * 3; if ( eID == ID_INDICIES ) NumSize *= sizeof( unsigned int ); else NumSize *= sizeof( float ); } glBufferDataARB( BindFlag, NumSize, cvpVerts, GetVboType( eTU_Draw ) ); //Set a pointer to the verts, vbos not working pCurrent->m_pVerts = (float*)cvpVerts; Unbind(); pCurrent->Created = true; } void CVBO :: DrawBuffer( GLenum ePolygonType ) { if ( m_Verts.Created ) { glEnableClientState( GL_VERTEX_ARRAY ); Bind( ID_VERTS ); //glVertexPointer( 3, GL_FLOAT, 0, m_Verts.m_pVerts ); glVertexPointer( 3, GL_FLOAT, 0, (char*)NULL ); Unbind(); glDrawArrays( ePolygonType, 0, m_Verts.m_NumOfVerts ); } if ( m_Verts.Created ) glDisableClientState( GL_VERTEX_ARRAY ); Unbind(); } Ok so thats pretty much it, I know theres a cool way to put it in a code window, but I dont know how and its like 2:20 in the morning, so im really tired, and desperate. I've been trying to figure this out for a while, I just want to get back to normal programming again lol so someone help me k thnx :) heh heh

Share this post


Link to post
Share on other sites
You have to bind the buffer before you call glBufferData. If no buffer is bound at the time glBufferData is called, it will interpret the last argument just as pointer, and therefore crash.

Edit: ah sorry, i missed that you're already binding it. In that case i would recheck your binding code and also check for GL errors.

Share this post


Link to post
Share on other sites
Ok so i've done a bit of experimenting today, and I realized now that after I gen the buffers in my create function, the glIsBufferARB test returns GL_FALSE.

Something that confuses me about this is, isn't glIsBuffer and glIsBufferARB pretty much the same thing? When I call glIsBuffer, it crashes, glIsBuffer apparently points to NULL, but glIsBufferARB works, it just says that my buffer isn't really a buffer. Is it telling the truth? And why would the genBuffers call be failing?

EDIT: BTW, I checked for errors after glGenBuffers and there were none.

Just so everyone knows also, just to make sure, I changed the code from
if ( !glIsBufferARB( id ) ) return 1;

to

if ( glIsBufferARB( id ) == GL_FALSE ) return 1;

Not sure if that mattered, but so the checks should be working.

Also, I checked my bind function and I am getting a GL_INVALID_ENUM error, but I get that error before I call the bind function as well.

Share this post


Link to post
Share on other sites
Quote:

Ok so i've done a bit of experimenting today, and I realized now that after I gen the buffers in my create function, the glIsBufferARB test returns GL_FALSE.

That's ok, the glGen* functions simply reserve some number for use, and the handle is not considered in use until it is bound.

Quote:

Something that confuses me about this is, isn't glIsBuffer and glIsBufferARB pretty much the same thing? When I call glIsBuffer, it crashes, glIsBuffer apparently points to NULL, but glIsBufferARB works, it just says that my buffer isn't really a buffer. Is it telling the truth? And why would the genBuffers call be failing?

Yeah, glIsBufferARB() is from the extension GL_ARB_vertex_buffer_object which was later promoted to OpenGL 1.5 as core function glIsBuffer(). It simply means your driver/card may not support OpenGL 1.5, but does support the extension in question.

Quote:

EDIT: BTW, I checked for errors after glGenBuffers and there were none.

Just so everyone knows also, just to make sure, I changed the code from
if ( !glIsBufferARB( id ) ) return 1;

to

if ( glIsBufferARB( id ) == GL_FALSE ) return 1;

Not sure if that mattered, but so the checks should be working.

Also, I checked my bind function and I am getting a GL_INVALID_ENUM error, but I get that error before I call the bind function as well.


I would focus on this error. How does your binding function look like ?

Share this post


Link to post
Share on other sites
Heres my bind function

GLenum CVBO :: Bind( eVboID eID )
{
switch ( eID )
{
case ID_VERTS:

if ( m_Verts.Created >= _BUFFER_CREATED )
{
//Not great at debugging, I just put breakpoints
GLenum Err = glGetError();
int cool = 2;
if ( Err == GL_INVALID_ENUM )
cool = 1; // I get this error
else
cool = 0;

//I tryed both GL_ARRAY_BUFFER and
// GL_ARRAY_BUFFER_ARB, I know there the same but yea
glBindBufferARB( GL_ARRAY_BUFFER, m_Verts.m_ID );

Err = glGetError();
if ( Err == GL_INVALID_ENUM )
cool = 1; // This one too
else
cool = 0;

/*if ( Err == GL_INVALID_OPERATION )
int man = 2; //No error here
else
int man = 3;*/

return GL_ARRAY_BUFFER_ARB;
}
}

//Nothing found/or created yet
return NULL;
}

Thats pretty much it, just boggled up with my error checking.
(I took out the other switch statements values because all im using right now is
vertices)

I might not be on here for a while because of a lot of school work, but anyone feel free to post answers still and thanks snoutmate for your help so far.

[Edited by - DuckMaster on March 2, 2008 9:37:33 PM]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this