Jump to content
  • Advertisement
Sign in to follow this  

unknown problem with particle engine

This topic is 4090 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

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 displaying anything. 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.fLifeTime > 0)				//if on

				//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.vPos;
				//set texture
				Graphics->p_device->SetTexture(0, Graphics->Textures[10]); //30 should be a variable
				//unlock and render
				//move to next slot
					if ( iCurrentVertex > iVBsize-1 ) { iCurrentVertex = 0; }


	PostRender();			//reset after render
void cParticleCollection::Init()
	r = Graphics->p_device->CreateVertexBuffer(iVBsize * sizeof(cVertex),
												D3DFVF_XYZ | D3DFVF_DIFFUSE,

[Edited by - alundgren on May 3, 2007 12:51:47 PM]

Share this post

Link to post
Share on other sites
Could you please re-format the code and put it into [source] [/source] tags? That would help a lot with trying to read it.

Share this post

Link to post
Share on other sites
Since you say you code hangs, it's likely that running it in the debugger and breaking when it hangs will show you where it hangs, which should help find the problem.

Share this post

Link to post
Share on other sites

Sorry was using [code ] tags. I worded the problem poorly - it doesn't hang up, it just doesn't display anything. There are no errors and it runs fine, just nothing's displayed.

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!