Jump to content
  • Advertisement
Sign in to follow this  
masterbubu

vbo - need help

This topic is 3169 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hi, i'm trying use vbo for mesh with texture and normals.

//from create vbo func
My_GL_ext::_glGenBuffersARB(3, _mesh->_buffer);

//from draw function

        glEnableClientState(GL_TEXTURE_COORD_ARRAY);
	glEnableClientState(GL_NORMAL_ARRAY);
	glEnableClientState(GL_VERTEX_ARRAY);

	My_GL_ext::_glBindBufferARB(GL_ARRAY_BUFFER_ARB, _mesh->_buffer[2]);
	My_GL_ext::_glBufferDataARB(GL_ARRAY_BUFFER_ARB, _mesh->_trianglesCount * numOfcomonutsonTri * sizeof(Vector2), _mesh->_uvs, GL_STATIC_DRAW_ARB);
	glTexCoordPointer(2, GL_FLOAT, 0, 0 );	

	My_GL_ext::_glBindBufferARB(GL_ARRAY_BUFFER_ARB, _mesh->_buffer[1]);
	My_GL_ext::_glBufferDataARB(GL_ARRAY_BUFFER_ARB, _mesh->_trianglesCount * numOfcomonutsonTri * sizeof(Vector3),_mesh->_normals, GL_STATIC_DRAW_ARB);
	glNormalPointer( GL_FLOAT, 0, 0 );

	My_GL_ext::_glBindBufferARB(GL_ARRAY_BUFFER_ARB, _mesh->_buffer[0]);
	My_GL_ext::_glBufferDataARB(GL_ARRAY_BUFFER_ARB, _mesh->_trianglesCount * numOfcomonutsonTri * sizeof(Vector3), _animation->_frames[_animation->_currentFrame]->_vertcies, GL_DYNAMIC_DRAW_ARB);
	glVertexPointer(3, GL_FLOAT, 0, 0 );

the mesh did draw right, but the normals and uvs didn't. so to check if something is wrong on my arrays setup, i drawed the arrays using vertex arrays:
	glTexCoordPointer(2, GL_FLOAT, 0, _mesh->_uvs );	

        glNormalPointer( GL_FLOAT, 0, _mesh->_normals );

	glVertexPointer(3, GL_FLOAT, 0, _animation->_frames[_animation->_currentFrame]->_vertcies );

now its worked. what am I doing wrong?

Share this post


Link to post
Share on other sites
Advertisement
I don't know if this will solve your problem, but I would do
glTexCoordPointer(2, GL_FLOAT, sizeof(Vector2), 0 );
glNormalPointer( GL_FLOAT, sizeof(Vector3), 0 );
glVertexPointer(3, GL_FLOAT, sizeof(Vector3), 0 );


because the data packing might varry from compiler to compiler and system to system.

Share this post


Link to post
Share on other sites
I think some problem with your offset,vertex pointer is taking fine because its offset is zero .In second case you are
specifiying directly poinetr thats why it is working.

Share this post


Link to post
Share on other sites
I have tried separate the array to 3 vbo. (but i think it the same as before).

[Source]

My_GL_ext::_glBindBufferARB(GL_ARRAY_BUFFER_ARB, _mesh->_buffer2);
My_GL_ext::_glBufferDataARB(GL_ARRAY_BUFFER_ARB, _mesh->_trianglesCount * numOfcomonutsonTri * sizeof(Vector2), _mesh->_uvs, GL_STATIC_DRAW_ARB);
glTexCoordPointer(2, GL_FLOAT, 0, 0 );

My_GL_ext::_glBindBufferARB(GL_ARRAY_BUFFER_ARB, _mesh->_buffer1);
My_GL_ext::_glBufferDataARB(GL_ARRAY_BUFFER_ARB, _mesh->_trianglesCount * numOfcomonutsonTri * sizeof(Vector3),_mesh->_normals, GL_STATIC_DRAW_ARB);
glNormalPointer( GL_FLOAT, 0, 0 );

My_GL_ext::_glBindBufferARB(GL_ARRAY_BUFFER_ARB, _mesh->_buffer0);
My_GL_ext::_glBufferDataARB(GL_ARRAY_BUFFER_ARB, _mesh->_trianglesCount * numOfcomonutsonTri * sizeof(Vector3), _animation->_frames[_animation->_currentFrame]->_vertcies, GL_DYNAMIC_DRAW_ARB);
glVertexPointer(3, GL_FLOAT, 0, 0 );

[/Source]


and the genBuffers
[Source]

My_GL_ext::_glGenBuffersARB(1, &_mesh->_buffer0);
My_GL_ext::_glGenBuffersARB(1, &_mesh->_buffer1);
My_GL_ext::_glGenBuffersARB(1, &_mesh->_buffer2);

[/Source]


still it gave me the same results. i looked at NeHe VBO tutorial, and their
binding is pretty much the same.

Share this post


Link to post
Share on other sites
I reviewed your code, i think after generating the VBO id you can send the
data to VBO and in your draw function just bind the same id before draw call.No need to send data in draw call.
Other thing you can check are you disabling all the client state.
Like glDisableClientState(GL_VERTEX_ARRAY)in draw function.

Share this post


Link to post
Share on other sites
I'm assuming you are not specifying the data for the VBOs using glBufferData on every frame you draw, are you? (At least for those bound as GL_STATIC_DRAW there is no point to). In that case what you posted is probably not the sequence of calls you actually use when drawing is it? Could you post the exact sequence of drawing calls until you call glDrawArrays? (Again, I'm assuming you are not using glDrawElements because you are not constructing an element buffer.)

Share this post


Link to post
Share on other sites

Just go through from this Link for VBO creation and how to send data.
http://www.songho.ca/opengl/gl_vbo.html

Share this post


Link to post
Share on other sites
hi, this is the sequence of calls



//-----------------------------------------------------------------------------
Object::Object() : _mesh(NULL) , _ObjectIndex(-1)

{
My_GL_ext::_glGenBuffersARB(1, &_mesh->_buffer0);
My_GL_ext::_glGenBuffersARB(1, &_mesh->_buffer1);
My_GL_ext::_glGenBuffersARB(1, &_mesh->_buffer2);
}


//-----------------------------------------------------------------------------
GLvoid Object::draw()
{
int numOfcomonutsonTri = 3;

glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glEnableClientState(GL_NORMAL_ARRAY);
glEnableClientState(GL_VERTEX_ARRAY);

My_GL_ext::_glBindBufferARB(GL_ARRAY_BUFFER_ARB, _mesh->_buffer2);
My_GL_ext::_glBufferDataARB(GL_ARRAY_BUFFER_ARB, _mesh->_trianglesCount * numOfcomonutsonTri * sizeof(Vector2), _mesh->_uvs, GL_STATIC_DRAW_ARB);
glTexCoordPointer(2, GL_FLOAT, 0, 0 );

My_GL_ext::_glBindBufferARB(GL_ARRAY_BUFFER_ARB, _mesh->_buffer1);
My_GL_ext::_glBufferDataARB(GL_ARRAY_BUFFER_ARB, _mesh->_trianglesCount * numOfcomonutsonTri * sizeof(Vector3),_mesh->_normals, GL_STATIC_DRAW_ARB);
glNormalPointer( GL_FLOAT, 0, 0 );

My_GL_ext::_glBindBufferARB(GL_ARRAY_BUFFER_ARB, _mesh->_buffer0);
My_GL_ext::_glBufferDataARB(GL_ARRAY_BUFFER_ARB, _mesh->_trianglesCount * numOfcomonutsonTri * sizeof(Vector3), _animation->_frames[_animation->_currentFrame]->_vertcies, GL_DYNAMIC_DRAW_ARB);
glVertexPointer(3, GL_FLOAT, 0, 0 );

_mesh->drawMesh();

glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glDisableClientState(GL_NORMAL_ARRAY);
glDisableClientState(GL_VERTEX_ARRAY);

}
//---------------------------------------------------------------------------------
void Mesh::drawMesh()
{
if ( _material->_diffuseMap )
{
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, _material->_diffuseMap->_textID);
}
else
glDisable(GL_TEXTURE_2D);

glDrawArrays(GL_TRIANGLES, 0 , _trianglesCount * 3 );
}





Share this post


Link to post
Share on other sites
even if i change the flag of the normals and uv's to GL_DYNAMIC_DRAW_ARB
it does not work.
(if i'll manage it to work,I will bind the uvs and normals not on draw function. its there only for tests).

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!