Sign in to follow this  

DX9: Vertex Buffers and flickering

This topic is 4812 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 have the following code to use up the remainder of a VB:
if(m_iBufferSize - m_iCurrentPosition - 3 > 0) //-3 because we the largest group of vertices is a triangle
	{ //If we have space for at least one vertex in this buffer, then put it in
		VerticesToRender = min(RemainingVerticesCount,m_iBufferSize - m_iCurrentPosition);
		m_pVertexBuffer->Lock(m_iCurrentPosition * iVertexSize,
							  VerticesToRender*iVertexSize,
							  (void**)&vertices,D3DLOCK_DISCARD);

		memcpy(vertices,VertArray,VerticesToRender*iVertexSize);
		
		m_pVertexBuffer->Unlock();
		
		RemainingVerticesCount -=VerticesToRender;
		TL2DRemainingVertices += VerticesToRender;
		L3DRemainingVertices += VerticesToRender;
		switch(PrimitiveType)
		{
		case D3DPT_TRIANGLEFAN:
			g_pD3DDevice->DrawPrimitive(PrimitiveType,m_iCurrentPosition,VerticesToRender - 2);
			break;
		case D3DPT_TRIANGLELIST:
			g_pD3DDevice->DrawPrimitive(PrimitiveType,m_iCurrentPosition,VerticesToRender / 3);
			break;
		}
		m_iCurrentPosition = 0; //Don't move the current positoin along since it causes flickering
		//If i uncomment the following two lines flickering occurs!!

		//m_iCurrentPosition += VerticesToRender;
		//if(m_iCurrentPosition == m_iBufferSize) m_iCurrentPosition = 0;
	}
Note, if i change the lock mode to D3DLOCK_NOOVERWRITE i get random polygons drawn (i.e. garbage rendered). I've looked at numerous examples here and elsewhere, but just can't work out where the problem lies, or what i'm doing wrong. Any suggestions would be appreciated. :)

Share this post


Link to post
Share on other sites
Hi,

I am coding an engine in C# w/ Managed DX and we were having random artifacts being rendered from our IndexBuffer. The problem turned out that we weren't calling device.SetIndices = mibTerrain; (where mibTerrain = our IndexBuffer). There is a method in C# called device.SetStreamSource(VertexBufferToSetToHere); and I think there is an equivalent in C++. Make sure that you are setting your stream source to your VertexBuffer before drawing to the screen. Not sure if that helps any, but it fixed our problem.

Nathan

Share this post


Link to post
Share on other sites
Try this:
Control panal->DirectX->Direct 3D tab

Change from Debug version of DirectX to retail version.

If you are useing Visual Studio you can do the same from:
Tools->Options->Debugging->DirectX

This fixed the problem for me once.

Share this post


Link to post
Share on other sites

This topic is 4812 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this