Jump to content
  • Advertisement
Sign in to follow this  

dynamic vertex buffer problem

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

Hya, I'm having trouble getting a dynamic vertex buffer to work. Belows the render code and the vertex structure
bool CLANDSCAPE::RenderTriangle( LPDIRECT3DDEVICE9 pD3DDevice,
									const D3DXVECTOR3 &v1, const D3DXVECTOR3 &v2, const D3DXVECTOR3 &v3) {

	if( m_svbLandscape == NULL ) return false;

	// default nooverwrite

	// check for space left in the buffer
	if( m_suintVertexCount + 3 > m_suintMaxVertices ) {

		FlushBuffers( pD3DDevice );

		// discard the buffer
		dwLockFlag = D3DLOCK_DISCARD;

	// append vertices to buffer
	VERTEX_LAND vertices[3];
	vertices[0].vPos = v1;
	vertices[0].diffuse = 1;
	vertices[1].vPos = v2;
	vertices[1].diffuse = 0;
	vertices[2].vPos = v3;
	vertices[2].diffuse = 0;

	VOID* pBuffer;
	if( FAILED( m_svbLandscape->Lock( m_suintVertexCount * sizeof(VERTEX_LAND), 3 * sizeof(VERTEX_LAND), &pBuffer, dwLockFlag ) ) ) {

		return false;

	memcpy( pBuffer, vertices, 3 * sizeof(VERTEX_LAND) );

	//increment count of vertices in buffer

	return true;

void CLANDSCAPE::FlushBuffers( LPDIRECT3DDEVICE9 pD3DDevice ) {

	if( !m_suintVertexCount ) return;

	// draw primitive
	pD3DDevice->DrawPrimitive( D3DPT_TRIANGLELIST, 0, m_suintVertexCount / 3  );

	m_suintVertexCount = 0;


	if( m_svbLandscape == NULL ) return;

	pD3DDevice->SetStreamSource( 0, m_svbLandscape, 0, sizeof(VERTEX_LAND) );

	for( UINT i = 0; i < CLANDSCAPE_PATCHES_PER_SIDE; ++i ) {

		for( UINT j = 0; j < CLANDSCAPE_PATCHES_PER_SIDE; ++j ) {

			m_cPatches[j].Render( pD3DDevice );

Here's the vertex struct and fvf
struct VERTEX_LAND {

	DWORD diffuse;


Here's the code for initialising the vertex buffer

	return pD3DDevice->CreateVertexBuffer( m_suintMaxVertices * sizeof(VERTEX_LAND), D3DUSAGE_DYNAMIC,
									LANDSCAPE_FVF, D3DPOOL_DEFAULT, &m_svbLandscape, NULL );

The diffuse value was added just to see if that was the problem. The problem is that the drawprimitive call doesn't work. I just get first-chance exceptions. At the drawprimitive call I've unlocked the buffer and checked the vertices and they seem fine. m_suintVertexCount and m_svbLandscape are static variables in CLANDSCAPE and RenderTriangle and FlushBuffers are static functions in CLANDSCAPE. This code's being used to render a ROAM algorithm heavily based on the tutorial on gamasutra. The CLANDSCAPE::Render function is called first and calls render functions for each ROAM patch (CPATCH). The patches recourse two triangle trees and when they reach a leaf they call the static CLANDSCAPE::RenderTriangle function. Any ideas what I'm doing wrong? Thanks Matt

Share this post

Link to post
Share on other sites
Actually, just posting the code made me notice that I hadn't set the FVF (pD3DDevice->SetFVF()). It works now. What an idiot lol.



Share this post

Link to post
Share on other sites
It never fails, just post your problem and your code, and ask for help, and the answer will magically come to you a few minutes later! :D

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!