Skip to main content
GameDev.net gamedev.net
🔒 Locked

DrawPrimitiveUP keeps crashing

Started by TheGecko Jun 15, 2002 at 8:13 PM 3 replies 500+ views
Original Post
TheGecko
TheGecko
Hey people. I'm having a little bit of a problem with drawing this one quad. I don't want to create an index and vertex buffer for it since it's only a single quad on it's own.(It's actually a single particle in a particle system) Now I know this is not the way particles should be rendered, but I'm doing this as a benchmark kind of thing. Anyway,here's what my particle vertex structure and FVF looks like:
      
//----------------------------------------------------

typedef struct
{
	float	x,y,z;
	DWORD	Diffuse;
	float	u,v;

}ParticleVertex;
//-------------------------------------------------

#define D3DFVF_PARTICLEVERTEX (D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_TEX1)

//-------------------------------------------------

    
And I have created an array or ParticleVertex[4] like so:
  
ParticleVertex Vertices[4];
    
Now my problem is drawing the damn thing.This is what my render function looks like:
  
	//Bind the texture and set the shader

	EngineGetD3DDevice()->SetVertexShader(D3DFVF_PARTICLEVERTEX);
	EngineGetD3DDevice()->SetTexture(0,m_pTexture);
...
	//Draw the particle

	EngineGetD3DDevice()->DrawPrimitiveUP(D3DPT_TRIANGLELIST,2,(const void*)Vertices,0);
      
Like I said,it keeps crashing on that last statement. I know this because if I comment it out,then everything works fine but nothing is being drawn to the screen. Any ideas?
[edited by - TheGecko on June 15, 2002 9:16:30 PM]
IndirectX
IndirectX
1. Your FVF and vertex definition must have either normal or rhw components. (D3DFVF_XYZ | D3DFVF_NORMAL or D3DFVF_XYZRHW).

2. Use the debug runtime.

3. Try setting the last argument of DrawPrimitiveUP to something sensible, like sizeof(ParticleVertex).
---visit #directxdev on afternet <- not just for directx, despite the name
DrunkenHyena
DrunkenHyena
quote:
Original post by IndirectX
1. Your FVF and vertex definition must have either normal or rhw components. (D3DFVF_XYZ | D3DFVF_NORMAL or D3DFVF_XYZRHW).


No they don''t. I''ve quite successfully used vertices that have neither.


Stay Casual,

Ken
Drunken Hyena
Stay Casual,KenDrunken Hyena</FON
Dirge
Dirge
Yeah, quite simply directx doesn't know the size of your vertex structure. Try sizeof(ParticleVertex) as the last argument instead of 0.

Here is what I use to render bullets in my game.


  
// Setup Render States.

m_pd3dDevice->SetRenderState( D3DRS_LIGHTING, FALSE );

// Render the Bullet at it's position.

m_pd3dDevice->SetVertexShader( D3DFVF_VERTEX_XYZ_DIFF_TEX );
m_pd3dDevice->DrawPrimitiveUP( D3DPT_TRIANGLESTRIP, 2, (LPVOID)m_Vertices, sizeof(VERTEX_XYZ_DIFF_TEX) );

// Restore Render States.

m_pd3dDevice->SetRenderState( D3DRS_LIGHTING, TRUE );


Now all this does is dump your verts straight to the video card. I wonder though, is there any speed decrease from this method (supposedly Vertex Buffers are optimized for Video Card drivers, but then again I've heard sending small Vertex Buffers is bad).

p.s. Almost forgot! You are using a triangle list. Use a triangle strip instead. It's better, trust me!

"Love all, trust a few. Do wrong to none." - Shakespeare

Dirge - Aurelio Reis
www.CodeFortress.com

[edited by - Dirge on June 15, 2002 12:41:38 AM]
"Artificial Intelligence: the art of making computers that behave like the ones in movies."www.CodeFortress.com
TheGecko
TheGecko
Thanx all! My problem was with the DrawPrimitiveUP() function where I was using 0 as the last parameter instead of sizeof(ParticleVertex). I though stride meant how many byte IN BETWEEN vertices instead of how many bytes BETWEEN vertices.(This is from my OpenGL programming experiences)

So,now everything is working Thanx alot for the help!

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.