Sign in to follow this  
alundgren

Rendering vertex buffer - nothing displayed

Recommended Posts

alundgren    115
Hi all, I am working on my graphics engine. Have skybox, meshes displaying properly. Currently working on the particle engine. I have completed coding it and feel it should work. No errors, but nothing displayed. I adapted this from an example from a book, and it looks solid. Don't know why it's not rendering the vertex buffer. Anyone see anything? I feel it's something small I'm forgetting. I've only included the primary methods, any q's plz ask.
void cParticleCollection::PreRender()
{
//TODO: move some of these one-time settings to constructor.. not sure which ones

//general settings
Graphics->p_device->SetRenderState(D3DRS_LIGHTING, false);
Graphics->p_device->SetRenderState(D3DRS_POINTSPRITEENABLE, true);
Graphics->p_device->SetRenderState(D3DRS_POINTSCALEENABLE, true);
Graphics->p_device->SetRenderState(D3DRS_POINTSIZE, FloatToDWORD(2.5f) );
Graphics->p_device->SetRenderState(D3DRS_POINTSIZE_MIN, FloatToDWORD(0.1f) );

//set the size of the particle relative to distance
Graphics->p_device->SetRenderState(D3DRS_POINTSCALE_A, FloatToDWORD(0.0f) );
Graphics->p_device->SetRenderState(D3DRS_POINTSCALE_B, FloatToDWORD(0.0f) );
Graphics->p_device->SetRenderState(D3DRS_POINTSCALE_C, FloatToDWORD(1.0f) );

//use alpha from texture
Graphics->p_device->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
Graphics->p_device->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);

Graphics->p_device->SetRenderState(D3DRS_ALPHABLENDENABLE, true);
Graphics->p_device->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
Graphics->p_device->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);

//set vertex format
Graphics->p_device->SetFVF(D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_PSIZE);
//set stream source
Graphics->p_device->SetStreamSource(0, ParticleBuffer, 0, sizeof(cVertex));

}
void cParticleCollection::PostRender()
{
Graphics->p_device->SetRenderState(D3DRS_LIGHTING, true);
Graphics->p_device->SetRenderState(D3DRS_POINTSPRITEENABLE, false);
Graphics->p_device->SetRenderState(D3DRS_POINTSCALEENABLE, false);
Graphics->p_device->SetRenderState(D3DRS_ALPHABLENDENABLE, false);
}
void cParticleCollection::Render()
{
	if (Particles.size() > 0) //if there are entries
	{
	PreRender();				//prepare to render

	//render collection:
	cVertex *v = 0;
	int iCurrentVertex = 0;

		//counter number of particles that are on
		for (int i = 0; i <= Particles.size(); i++) 	//loop thru all
		{
			if (Particles[i].fLifeTime > 0)				//if on
			{	
				//RENDER THIS PARTICLE

				//lock a slot
				ParticleBuffer->Lock(iCurrentVertex * sizeof(cVertex),							//beginning of lock
									 sizeof(cVertex),											//size of lock range
									 (void**)&v,												//address of vertex
									 iCurrentVertex ? D3DLOCK_NOOVERWRITE : D3DLOCK_DISCARD);	//flags
				//fill info
				v->d3dColor = d3d::GREEN;						//sould ba var
				v->fSize	= 50.0f;								//should be a var
				v->vPos		= Particles[i].vPos;
				//set texture
				Graphics->p_device->SetTexture(0, Graphics->Textures[10]); //30 should be a variable
				
				//unlock and render
				ParticleBuffer->Unlock();
				Graphics->p_device->DrawPrimitive(D3DPT_POINTLIST,
												  iCurrentVertex,
												  1);
				//move to next slot
				iCurrentVertex++;
					if ( iCurrentVertex > iVBsize-1 ) { iCurrentVertex = 0; }


			}
		}


	PostRender();			//reset after render
	}
}
void cParticleCollection::Init()
{
	r = Graphics->p_device->CreateVertexBuffer(iVBsize * sizeof(cVertex),
												D3DUSAGE_DYNAMIC | D3DUSAGE_POINTS | D3DUSAGE_WRITEONLY,
												D3DFVF_XYZ | D3DFVF_DIFFUSE,
												D3DPOOL_DEFAULT,
												&ParticleBuffer,
												0);
}


Share this post


Link to post
Share on other sites
blaze02    100
CreateVertexBuffer is not getting the correct FVF. You are leaving off the D3DFVF_PSIZE.

If that doesn't fix the problem, check your vertex structure. The data should be 3 floats for position, 1 float for point size, and 1 DWORD for color (so says your FVF). A common bug is the ordering. Make sure position is first, then point size, then color. More details.

Hope that helps.

Share this post


Link to post
Share on other sites

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