Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

xsirxx

Problem with Particles, all red? arent changing color and texture not loading?

This topic is 5403 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 a weird problem with my particle system, this is C++ Directx 8.0. The problem is, numebr one, if my texture doesnt load, and my colors arent changing when I tell them to? Any1 have some ideas, if u need anymore code tell me... thanks guys! --------------------------------------------------------------

void ParticleEmitter::Render(D3DXVECTOR3 vecCameraSource){
	D3DXMATRIX matWorld;
	D3DXMatrixIdentity( &matWorld );
	matWorld._41 = vecCameraSource.x;//0;

	matWorld._42 = vecCameraSource.y;//0;

	matWorld._43 = vecCameraSource.z;//+70;//0;//-530;

	pd3dDevice->SetTransform( D3DTS_WORLD, &matWorld );
	
	
	pd3dDevice->SetRenderState( D3DRS_ZWRITEENABLE, FALSE );
    pd3dDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, TRUE );
    pd3dDevice->SetRenderState( D3DRS_SRCBLEND, D3DBLEND_ONE );
    pd3dDevice->SetRenderState( D3DRS_DESTBLEND, D3DBLEND_ONE );

	
//	pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );

//	pd3dDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_MODULATE );

//	pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE );

//	pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE );

//	pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_MODULATE );

//	pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE );

//	pd3dDevice->SetTextureStageState( 1, D3DTSS_COLOROP, D3DTOP_DISABLE );

//	pd3dDevice->SetTextureStageState( 1, D3DTSS_ALPHAOP, D3DTOP_DISABLE );


	pd3dDevice->SetRenderState( D3DRS_POINTSPRITEENABLE, TRUE );
	pd3dDevice->SetRenderState( D3DRS_POINTSCALEENABLE,  TRUE );
	pd3dDevice->SetRenderState( D3DRS_POINTSIZE,     FtoDW(5.0f) );
	pd3dDevice->SetRenderState( D3DRS_POINTSIZE_MIN, FtoDW(0.00f) );
//	pd3dDevice->SetRenderState( D3DRS_POINTSIZE_MAX, FtoDW(1000.00f) );

	pd3dDevice->SetRenderState( D3DRS_POINTSCALE_A,  FtoDW(0.00f) );
	pd3dDevice->SetRenderState( D3DRS_POINTSCALE_B,  FtoDW(1.00f) );
	pd3dDevice->SetRenderState( D3DRS_POINTSCALE_C,  FtoDW(1.00f) );
	
	pd3dDevice->SetStreamSource( 0, vbParticles, sizeof(VERTEX_PARTICLE) );
	pd3dDevice->SetVertexShader( D3DFVF_PARTICLE );
	pd3dDevice->SetTexture(0, texParticle);
	
	VERTEX_PARTICLE *pVertices;
	DWORD dwNumParticlesToRender = 0;

	vbParticles->Lock(0, iVBSize * sizeof(VERTEX_PARTICLE), (BYTE **) &pVertices, D3DLOCK_DISCARD);
 
	 for (int i=0; i < NUMPARTICLES; i++) {
    
    // Render each particle a bunch of times to get a blurring effect

    if (partArray[i].IsAlive()) {
      Particle &part = partArray[i];
    
      pVertices->position = part.vPos;
      pVertices->pointsize = part.fSize;
      pVertices->color = (DWORD)part.cColor;
      pVertices++;

      if( ++dwNumParticlesToRender == iVBSize ) {

		vbParticles->Unlock();
		pd3dDevice->DrawPrimitive(D3DPT_POINTLIST, 0, dwNumParticlesToRender);
		dwNumParticlesToRender = 0;
      }
    }
  }

	pd3dDevice->SetRenderState( D3DRS_POINTSPRITEENABLE, FALSE );
	pd3dDevice->SetRenderState( D3DRS_POINTSCALEENABLE,  FALSE );
	pd3dDevice->SetRenderState( D3DRS_ZWRITEENABLE, TRUE );


}
--------------------------------------------------------------- and here is my loading of the texture and color info ---------------------------------------------------------------
void ParticleEmitter::LoadSprite(const char *strTextureFilename){
	D3DXCreateTextureFromFile(pd3dDevice, strTextureFilename, &texParticle);
}
---------------------------------------------------------------
void Particle::CreateRainDrop(void){
	iType		= 1;
	vPos.x		= RandomNumber((float)(-ScreenWidth/2), (float)(ScreenWidth/2));
	vPos.y		= (float)(0 + ScreenHeight/2);
	vPos.z		= RandomNumber(1.0, 700.0);
	cColor		= D3DCOLOR_RGBA(255,255,255,255);
	bAlive		= TRUE;
	vDir.y		= RandomNumber(-6.5f, -9.8f);
	fSize		= 20.0f;
	fLifeTime	= RandomNumber(10.0f ,7.0f);
	
}
---------------------------------------------------------------
#define D3DFVF_PARTICLE (D3DFVF_XYZ|D3DFVF_DIFFUSE|D3DFVF_PSIZE)

typedef struct 
{
    D3DXVECTOR3 position;
    float       pointsize;
    D3DCOLOR    color;
} VERTEX_PARTICLE;
[edited by - xsirxx on February 29, 2004 4:14:25 PM] [edited by - xsirxx on February 29, 2004 4:15:26 PM]

Share this post


Link to post
Share on other sites
Advertisement
Is this part supposed to be commented out?


// pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );

// pd3dDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_MODULATE );

// pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE );

// pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE );

// pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_MODULATE );

// pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE );

// pd3dDevice->SetTextureStageState( 1, D3DTSS_COLOROP, D3DTOP_DISABLE );

// pd3dDevice->SetTextureStageState( 1, D3DTSS_ALPHAOP, D3DTOP_DISABLE );





| TripleBuffer Software |
| Plug-in Manager :: System Information Class :: C++ Debug Kit :: DirectX Tutorials :: Awesome Books |

Share this post


Link to post
Share on other sites
Yea I forgot to mention, i commented them out because the effects had no bareing on my particles, all though they did change my other items(ground, airplane) to white, not a selected color. My particles had stayed red? strange. So no luck with those, although im SURE i need some texture state changes to make this work... thats why i have not deleted them yet.. thanks though.

Share this post


Link to post
Share on other sites
I don''t know if it''s the problem, but I got something similar and the problem was having the incorrect FVF for my vertices... double check that.

Share this post


Link to post
Share on other sites
I think the source blend should be the default of D3DBLEND_SRCALPHA.

Load your texture in with D3DXCreateTextureFromFileEx(...)

Share this post


Link to post
Share on other sites
vbParticles->Lock(0, iVBSize * sizeof(VERTEX_PARTICLE), (BYTE **) &pVertices, D3DLOCK_DISCARD);

Where do you set iVBSize to a value?

Share this post


Link to post
Share on other sites
ms291052,
Can u explain a lil more about that problem with the FVF? What was wrong, what else happened??
---------------------------------------------------------------
GroZZleR,

ParticleEmitter:articleEmitter(void){
pd3dDevice = NULL;
iVBSize = (NUMPARTICLES -1);
}
---------------------------------------------------------------

also with the red color, my plane(airplane) is drawn right before the particles and it is red as well... Maybe i am missing something completely simple?

--X

[edited by - xsirxx on February 29, 2004 3:33:09 PM]

Share this post


Link to post
Share on other sites
Uhhh...Would you please re-format your initial post?
Edit it and place your source code inside [ source ][ /source ] formatting tags, without the spaces between the square brackets and the word "source".

Muhammad Haggag

[edited by - Coder on February 29, 2004 3:41:31 PM]

Share this post


Link to post
Share on other sites
Sorry had no idea how to do that, great now I know, makes it alot easier . Any ideas though on the code?

Thanks for the sourceing info.

Share this post


Link to post
Share on other sites
I've found your problem, I believe.


vbParticles->Lock(0, iVBSize * sizeof(VERTEX_PARTICLE), (BYTE **) &pVertices, D3DLOCK_DISCARD);

for (int i=0; i < NUMPARTICLES; i++) {

// Render each particle a bunch of times to get a blurring effect

if (partArray.IsAlive()) {
Particle ∂ = partArray[i];

pVertices->position = part.vPos;
pVertices->pointsize = part.fSize;
pVertices->color = (DWORD)part.cColor;
pVertices++;


pVertices->pointsize = part.fSize;

DirectX has no idea what pointsize is, it shouldn't be in your vertex definition.

You're gonna have to set it before rendering, like so:
pd3dDevice->SetRenderState( D3DRS_POINTSIZE, FtoDW(part.fSize) );

EDIT: Hrm, according to your FVF, it does. BUT your FVF is out of order, you're listing your Vertex in the order: XYZ, DIFFUSE, PSIZE but when you define your vertex, you're doing XYZ, PSIZE, DIFFUSE so either rearrange your D3DFVF_PARTICLE or your VERTEX_PARTICLE struct.

EDIT2: Is PSIZE even a valid FVF entry?

[edited by - GroZZleR on February 29, 2004 4:21:17 PM]

[edited by - GroZZleR on February 29, 2004 4:30:35 PM]

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!