Jump to content
  • Advertisement
Sign in to follow this  
Dragon_Strike

vertex buffer not drwing?

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

i cant get my vertex buffer drawin a terrain mesh... dunno why.. everthing semes ok.. maybe something ive missed?

void CTERRAIN::CreateVertexBuffer()
{
	glEnableClientState(GL_VERTEX_ARRAY);
	
	if (VertexBuffer > 0)
		glDeleteBuffers(1, &VertexBuffer);
	glGenBuffers(1, &VertexBuffer);
	

	// 'allocate' memory for the vertex list.
	glBindBuffer(GL_ARRAY_BUFFER_ARB, VertexBuffer);
	glBufferData(GL_ARRAY_BUFFER_ARB, sizeof(GLfloat) * m_iSize * m_iSize * 3 , NULL, GL_STATIC_DRAW_ARB);

	// Calculate the offset in the array for the vertex, normal, and colors.
	vertOffset = 0;

	// Copy data into the buffer objects.
	GLfloat *vertBuff = (GLfloat *)glMapBuffer(GL_ARRAY_BUFFER_ARB, GL_WRITE_ONLY_ARB);
	
	for (int z = 0; z < m_iSize; z++)
	{
		for (int x = 0; x < m_iSize; x++)
		{
			// Verticies.
			vertBuff[vertOffset]   = (float)x;		
			vertBuff[vertOffset+1] = GetHeight(x,z);
			vertBuff[vertOffset+2] = (float)z;
			vertOffset += 3;
		}
	}
	glUnmapBuffer(GL_ARRAY_BUFFER_ARB);
}

void CTERRAIN::CreateIndexBuffer()
{
	glEnableClientState(GL_VERTEX_ARRAY);
	glEnableClientState(GL_TEXTURE_COORD_ARRAY);

	if (IndexBuffer > 0)
		glDeleteBuffers(1, &IndexBuffer);
	glGenBuffers(1, &IndexBuffer);
	

	int numElements = ((m_iSize-1) * (m_iSize*2+2))-2;
	// 'allocate' memory for the vertex list.
	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER_ARB, IndexBuffer);
	glBufferData(GL_ELEMENT_ARRAY_BUFFER_ARB, sizeof(GLuint) * numElements, NULL, GL_STATIC_DRAW_ARB);


	// Copy data into the buffer objects.
	GLuint *triBuff = (GLuint *)glMapBuffer(GL_ELEMENT_ARRAY_BUFFER_ARB, GL_WRITE_ONLY_ARB);
	int currentIndex = 0;

	for (int z = 0; z < m_iSize; z++)
	{
		for (int x = 0; x < m_iSize; x++)
		{					
			if (x == 0 && z != 0)
				triBuff[currentIndex++] = x + (z * m_iSize);

			triBuff[currentIndex++] = x + (z * m_iSize);
			triBuff[currentIndex++] = x + ((z+1) * m_iSize);

			if (x == m_iSize-1 && z != m_iSize-2)
				triBuff[currentIndex++] = x + ((z+1) * m_iSize);
		}
	}
	glUnmapBuffer(GL_ARRAY_BUFFER_ARB);
}

void CTERRAIN::Render()
{	
	//ShaderProg.use();


	Update();

	glBindBuffer(GL_ARRAY_BUFFER_ARB, VertexBuffer);
	glVertexPointer(3, GL_FLOAT, 0, 0);

	int numElements = ((m_iSize-1) * (m_iSize*2+2))-2;
	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER_ARB, IndexBuffer);
	glDrawElements(GL_TRIANGLE_STRIP, numElements, GL_UNSIGNED_INT, 0);


        // ShaderProg.disable();		
}

Share this post


Link to post
Share on other sites
Advertisement
You must check if your gfx card and driver support the extension for OpenGL vertex buffer objects. It is GL_ARB_vertex_buffer_object.

If it does you will have to use the ARB extension functions.
glBindBufferARB
glBufferDataARB
glBufferSubDataARB
....

A complete description on how to use them is given here

The paper does not mention ARB functions, but I am sure you have you use the ARB extension. I am using it and it works for me just fine.

Check this link out. They have given an example.

Share this post


Link to post
Share on other sites
Are you sure your OpenGL drivers/gfx card supports the VBO extension GL_ARB_vertex_buffer_object?
The way to check it is using the glGetString(GL_EXTENSIONS)
VBOs were introduced only in OpenGL v1.5.
You will need to update the drivers if your OpenGL version is older.

Not all gfx cards/drivers support OpenGL VBOs. You will have to fall back on vertex arrays in that case.

Ok there is an easier way to determine. Download the code from this tutorial. It uses VBOs if avaialable and falls back on Vertex arrays if not. You can study the code.

Share this post


Link to post
Share on other sites
Quote:
Original post by _neutrin0_
Are you sure your OpenGL drivers/gfx card supports the VBO extension GL_ARB_vertex_buffer_object?
The way to check it is using the glGetString(GL_EXTENSIONS)
VBOs were introduced only in OpenGL v1.5.
You will need to update the drivers if your OpenGL version is older.

Not all gfx cards/drivers support OpenGL VBOs. You will have to fall back on vertex arrays in that case.

Ok there is an easier way to determine. Download the code from this tutorial. It uses VBOs if avaialable and falls back on Vertex arrays if not. You can study the code.


ive got a 7800 GT with the latest driver and im using the altest version of GLee.. soo im pretty certain it supports VBOs.. and also the demo i took teh code form when i compile it, it works jsut fine.. its just when i put it into my own program...

but ill check out that tuorial maybe ive missed somethin.. thx

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!