Jump to content
  • Advertisement
Sign in to follow this  

Cant fix VBO problem!

This topic is 4079 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

Hello again. Currently I'm working with the VBOs. I have no idea where the problem is. This picture shows a shpere! Currently not a sphere, because not all vertices are drawn. But this depends strongly on how many vertices I copy to the graphics card. This sphere is with an delta angle of 45 degrees. This angle is 10 degrees. I dont know what to do! I checked everything. Especially the indices and the sizes. The worst thing is, that this code works on Direct3D. I also tried another object, which worked, but this object was made just out of 4 vertices. And the sphere has, for example, with 45 degrees, 45 vertices. Maybe there is any alignment problem or so? One vertex has a DWORD for color and three float for x,y,z. See glInterleavedArrays in the render section. As you can imagine, ib is index buffer and vb is vertex buffer., The index buffer uses GL_ELEMENT_ARRAY_BUFFER, the vb uses GL_ARRAY_BUFFER
// create the indices.
	int index = 0 ; 

	WORD *w = NULL  ;

	pib->Initialize( (iFieldHeight) * (iLineWidth) *6, sizeof(WORD), NULL, GL_STATIC_DRAW ) ;
	pib->Lock( 0, 0, GL_READ_WRITE, (void**)&w ) ;

	for( int y=0; y<(iFieldHeight-1); y++ ){
		for( int x=0; x<(iLineWidth-1); x++ )

			w[index]	= (y+1) * (iLineWidth) + (x) ;
			w[index+1]	= (y)		* (iLineWidth) + (x) ;
			w[index+2]	= (y)		* (iLineWidth) + (x+1) ;
			w[index+3]	= w[index] ;
			w[index+4]	= w[index+2] ;
			w[index+5]	= (y+1)	* (iLineWidth) + (x+1) ;

			index += 6 ;

	pib->Unlock() ;

This code makes the indices. The initialize() funciton utilizes glBufferData with respective parameters. The next piece of code describes how the vertex data is copied. The lock functions, also for the index buffer, uses glMapBuffer to get a pointer to the memory on the graphics card. pVertices is a std vector.

pvb->Initialize( pVertices->size(), sizeof(VERTEX_CP), NULL, GL_STATIC_DRAW ) ;
pvb->Lock( 0, 0, GL_READ_WRITE, (void**)&v ) ;

// copy the data:
memcpy( v, (void*)&pVertices[0], sizeof(VERTEX_CP) * pVertices->size() ) ;

pvb->Unlock() ;

And now, just the vertex buffer initalize function, because that one from the index buffer is similar. I also unbind the buffer object, if it isn't needed anymore or meanwhile.
bool CIndexBuffer::Initialize( int iElemCount, int iElemSize, void *pData, GLenum usage )
	if( !iElemCount || !iElemSize )
		return false ;

	m_iBufferElems = iElemCount ;
	m_iElemSize = iElemSize ;

	// 1. generate id 
	GetIdentifier() ;

	// 2. Bind the index buffer 
	BindBuffer() ;

	// 3. UploadData, if pData is not null
	glBufferData( GL_ELEMENT_ARRAY_BUFFER, iElemSize * iElemCount, pData, usage ) ;

	// 4. done uploading the index data, do unbind the buffer
	UnbindBuffer() ;

	// if everything worked correctly, return true
	return true ;

Here the vertices are drawn.
vb->BindBuffer() ;
ib->BindBuffer() ;

glInterleavedArrays( GL_C4UB_V3F, 0,0 ) ;
glDrawElements(GL_LINES,3888,GL_UNSIGNED_SHORT,0 );

vb->UnbindBuffer() ;
ib->UnbindBuffer() ;

The number 3888 is the exact number of indices within the index buffer. I need help. I need those buffer objects. They are great. And the performace is also nice, nicer than glVertex* or somthing similar. If you need a specific ogl code section, please write it. I'm absolutly dead! I'm on this problem for hours now, and now its half three in the morning. I cant see this piece of sh... anymore. Please help. Grateful Alex [Edited by - directNoob on April 21, 2007 6:42:30 AM]

Share this post

Link to post
Share on other sites
Since you have all the vertices created in RAM, why not try immediate mode to draw them? This will make sure that it's a VBO problem. Most likely your parameters are wrong. (pointers to data, how much data to draw)

Share this post

Link to post
Share on other sites
glBufferData(GL_ARRAY_BUFFER, sizeof(float)*3*num_vertices, NULL, models->vertices);

2nd parameter is number of bytes , 3 because (x,y,z).

Share this post

Link to post
Share on other sites

Sorry to say, but you have made a mistake:
glBufferData(GL_ARRAY_BUFFER, sizeof(float)*3*num_vertices, NULL, models->vertices);

Bur it must be
glBufferData(GL_ARRAY_BUFFER, sizeof(float)*3*num_vertices, models->vertices, NULL);

But null is also not allowed there. The must be a usage flag.


Here I have drawn the the sphere in immediate mode.

I mean, VBOs are so simple.
I do it this way:

1.) Call glGenBuffers() for the ib and vb

2.) Bind each buffer in order to upload data.

3.) Upload data

4.) Unbind buffers.

And when drawing:

1.) Bind both Buffers

2.) Call glInerleavedArrays() with GL_C4UB_V3F Flag

3.) Call glDrawElements() with exact amount of indices

4.) Unbind buffers.

5.) Finished

Now, that I posted the sphere in immediare mode, successfully, where
could the problem be?

I posted the creation of the indices on top.
Per face, 6 indices.

I dont know.

Do you have any assumption?


Share this post

Link to post
Share on other sites
I found a little strange thing.

Look at this:

Here you can see the pointer to the graphics card memory.
Aren't these values strange?

And than, after the copy action(memcpy) it looks like this:

But pVertices look like this:

You see it?
The first vertex in pVertices is 1, 1, 1.
But the pointer to the memory on the gc looks different.

What can I do?

I looks like, that nothing gets copied or not all vertices.


Share this post

Link to post
Share on other sites
Got it.
This little a..h...

for( int i=0; i<pVertices->size(); i++ )
v = pVertices->at(i) ;

I replaced the memcpy call with the code from above.
Suddenly I saw, that the pointer v, pointing to the graphics card, had the
vector( 1,1,1) in front. At this point, it was clear that it will work.

But why doesnt it work with memcpy? I mean, a pointer is a pointer.
I mean, I copy the data to a IDIRECT3DVERTEXBUFFER9 with memcpy, and this works perfectly.

Whats the problem?


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!