• Advertisement
Sign in to follow this  

Problems with Drawing Lines (D3DPT_LINESTRIP related)

This topic is 3315 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'm trying to draw some 3D lines using DrawPrimitive and a linestrip, and for some reason I'm getting a bunch of extra lines being drawn in all from 0,0,0. I'm drawing a series of short lines to create a rough curve, and I'm 99.5% certain that how I do that isn't the problem because I get the same problem when I try to draw the bones. Picture since I'm sure this description doesn't make any sense: http://img.photobucket.com/albums/v238/billerwjustin/Graphics/lines.png Here is how I'm attempting to do this (everything thrown together):
#define D3DFVF_MY_VERTEX ( D3DFVF_XYZ | D3DFVF_DIFFUSE )

LPDIRECT3DVERTEXBUFFER9 m_helperLines;

pDevice->SetFVF( D3DFVF_MY_VERTEX );

pDevice->CreateVertexBuffer(sizeof(vector3) * 2, 
				0, 
			D3DFVF_MY_VERTEX, 
			D3DPOOL_DEFAULT, 
			&m_helperLines, 
			NULL);

void Graphics::DrawLine( vector3 p1, vector3 p2 )
{
	matrix view = camera.LookAtMatrix();
	pDevice->SetTransform(D3DTS_VIEW, &view);

	vector3* pVerts;
	m_helperLines->Lock(0, 0, (void**)&pVerts, 0);
	*pVerts = p1; pVerts++;
	*pVerts = p2;
	m_helperLines->Unlock();

	pDevice->SetStreamSource( 0, m_helperLines, 0, sizeof(vector3) );

	pDevice->SetFVF( D3DFVF_MY_VERTEX );

	pDevice->DrawPrimitive( D3DPT_LINESTRIP, 0, 2 );
}


I set up the project and world matrices when I initialize DirectX. The thing that is bothering me is that I swore this worked before. Going nuts.

Share this post


Link to post
Share on other sites
Advertisement
Your problem is here:

vector3* pVerts;
m_helperLines->Lock(0, 0, (void**)&pVerts, 0);
*pVerts = p1; pVerts++;
*pVerts = p2;
m_helperLines->Unlock();



Your vertex buffer doesn't contain an array of vector3's, it contains an array of vertices, which according to your FVF is a struct containing a vector3 and a D3DCOLOR.

EDIT: Actually, I see the VB does contain vector3's, although that's not what D3D is expecting. I'd highly recommend enabling the Debug Runtimes, which would spew a bunch of errors at you for doing this.

Share this post


Link to post
Share on other sites
Quote:
Original post by Namethatnobodyelsetook
Your draw primitive call says you're drawing 2 primitives. You're drawing 1 (one line). It will be reading garbage past the end of your vertex buffer to draw the second line.


Thanks sooooo much. I was thinking two vertices there instead one line, but I fixed it and it looks perfect. Thanks a bunch!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement