Jump to content
  • Advertisement
Sign in to follow this  
George Duckett

DX9: Vertex Buffers and flickering

This topic is 5007 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
Advertisement
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
Thanks for your reply.

I've just double-checked and i'm definatly setting the stream source correctly.
FYI i'm not using indexed buffers at all, so that couldn't be a problem.

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
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!