Jump to content
  • Advertisement
Sign in to follow this  
directNoob

OpenGL Cant draw VBO

This topic is 4211 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. Currently I have to learn OpenGL and now I want to use VBOs just like the vertexbuffer and indexbuffer in D3D... The object I want to draw has many VBOs. It is a Sirpinski tetrahedron. This object is drawn well under D3D. In my opinion, it must be possible to just alter the parts where I used the d3dVB and d3dIB. This goes like this: 1. Here, I prepare the VBOs but I dont render then.
bool CNode::PrepareBufferObject( void )
{
	// allocate some memory for translating 
	// the vertex date to the server...
	VERTEX_CP vertices[4] ;

	// access the member points and
	// save it in the vertex list.
	for(int i=0; i<4; i++)
	{
		vertices = VERTEX_CP( 0xFFFFFFFF, m_vcPoints.x, m_vcPoints.y, m_vcPoints.z  );
	}

	// Now, create the indices
	GLubyte w[9] ;

	// prepare indices
	w[0]= 0; w[1]= 1; w[2]= 2;
	w[3]= 0; w[4]= 2; w[5]= 3;
	w[6]= 3; w[7]= 1; w[8]= 0;

	// now prepare a interleavedArray
	//glInterleavedArrays( GL_C4UB_V3F,sizeof(VERTEX_CP),(void*)vertices ) ;

	// generate buffer identifiers
	glGenBuffers( NUM_BUFFERS, m_uiBufferIdentifier ) ;

	// specifiy the vertex buffer
	glBindBuffer( GL_ARRAY_BUFFER, m_uiBufferIdentifier[VERTEXDATA] ) ;
	glBufferData( GL_ARRAY_BUFFER, 4*sizeof(VERTEX_CP), vertices, GL_STATIC_DRAW ) ;

	// specify the index buffer
	glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, m_uiBufferIdentifier[INDEXDATA] ) ;
	glBufferData( GL_ELEMENT_ARRAY_BUFFER, 9*sizeof(GLubyte), w, GL_STATIC_DRAW ) ;

	// unbind buffers
	glBindBuffer( GL_ARRAY_BUFFER, NULL ) ;
	glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, NULL ) ;

	m_bLastElem = true ;

	return true ;
	
}
This is very clean, only gl code. In order to have the objects rendered, I just save the VBO identivier from glGenBuffers(). Now, here is the render method:
void CNode::Render( void )
{
	if( !m_bLastElem )
	{
		for( int i=0; i<4; i++ )
			m_Children.Render( ) ;
	}else{

		glBindBuffer( GL_ARRAY_BUFFER, m_uiBufferIdentifier[VERTEXDATA] ) ;
		glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, m_uiBufferIdentifier[INDEXDATA] ) ;

		// now prepare a interleavedArray
		glInterleavedArrays( GL_C4UB_V3F,sizeof(VERTEX_CP),NULL) ;
		// now, draw the elements...
		glDrawElements(GL_TRIANGLES, 9,GL_UNSIGNED_BYTE,0);
	}
	
}

When the reset depth of the object is reached, the function sets the aforementioned identifiers with glBindBuffer() in order to render the geometrie. But maybe the glInterleavedArrays() is not supposed to be called there... The matrices are set elsewhere. When I include the following in the render function:
...
glBegin(GL_TRIANGLES);
glVertex3f(...)
glVertex3f(...)
glVertex3f(...)
glEnd() ;
...

the triangle gets drawn. So it must be the VBO. Grateful if someone can help me. Alex

Share this post


Link to post
Share on other sites
Advertisement
Ok, now it works. The problem was in the VERTEX_CP structure.

I defined and unsigned int for the color, which was the problem.
I changed it to DWORD.

The vertecies are defined like

for(int i=0; i<4; i++)
{
vertices = VERTEX_CP( 0xFFFFFFFF, m_vcPoints.x, m_vcPoints.y, m_vcPoints.z );
}



With unsigned int, the problem is 0xFFFFFFFF in the initialization.
But why???

I mean, a DWORD is nothing else than an unsigned int!!!
Or am I wrong.
So why cant I assign 0xFFFFFFFF to an unsigned int?

And furthermore, in the glInterleavedArrays I used the mode GL_C4UB_V3F
which is exactly the what I defined.
C4UB is 4 * unsigned byte (4 uByte) for color.
And in my vertex decl there also was a 4 uByte slot(unsigned int = 4*uByte).
What happend?

Grateful for answers.
Alex

Share this post


Link to post
Share on other sites
I now this isn't going to be what you want for an answer, but don't use glInterleavedArrays, use your own, and offset in to the VBO. Check out spek's posting on VBO and tangents I suggested how he do it there. It's simple and more user friendly than the built in types which I hear are crap...

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!