   Particlesystem rendering trouble
  Hello allI´m doing a simple particlesystem in DirectX 9 and I´m having trouble rendering the particles correctly. This is what my particle looks like when rendered:http://upl.mine.nu/uplfolders/upload9/particlescrewup.JPGHere´s the Direct3D initiation code i use:    if (FAILED(m_pd3d9Interface = Direct3DCreate9(D3D_SDK_VERSION))){return false;}if (FAILED(m_pd3d9Interface->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &m_d3ddm))){return false;}ZeroMemory(&m_d3dparams, sizeof(m_d3dparams));m_d3dparams.Windowed = true;m_d3dparams.SwapEffect = D3DSWAPEFFECT_DISCARD;  m_d3dparams.BackBufferFormat = m_d3ddm.Format;   m_d3dparams.EnableAutoDepthStencil = true;m_d3dparams.AutoDepthStencilFormat = D3DFMT_D16;m_d3dparams.hDeviceWindow = sys_hwnd;   if (FAILED(m_pd3d9Interface->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, sys_hwnd, D3DCREATE_HARDWARE_VERTEXPROCESSING, &m_d3dparams, &m_pd3dDevice))){if (FAILED(m_pd3d9Interface->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, sys_hwnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &m_d3dparams, &m_pd3dDevice))){return false;}}// get device capsm_pd3dDevice->GetDeviceCaps(&m_d3dCaps);// get backbuffer surface descLPDIRECT3DSURFACE9 pBackBuffer = NULL;   m_pd3dDevice->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &pBackBuffer);   pBackBuffer->GetDesc(&m_d3dsdBackBuffer);   pBackBuffer->Release();// set projection matrixD3DXMATRIXA16 matrix;// field of view, aspectratio, nearclip, farclipD3DXMatrixPerspectiveFovLH(&matrix, DEG2RAD(60), (float)WINDOW_WIDTH / (float)WINDOW_HEIGHT, 1.0f, 8000.0f);   m_pd3dDevice->SetTransform(D3DTS_PROJECTION, &matrix);   // set view matrixD3DXVECTOR3 eye(0.0f, 0.0f, -20.0f);D3DXVECTOR3 lookAt(0.0f, 0.0f, 0.0f);D3DXVECTOR3 up(0.0f, 1.0f, 0.0f);D3DXMatrixLookAtLH(&matrix, &eye, &lookAt, &up);   m_pd3dDevice->SetTransform(D3DTS_VIEW, &matrix);// create a dynamic vertexbuffer that can be filled in with the updated particlesm_iNumVerts = 4;if (FAILED(m_pd3dDevice->CreateVertexBuffer(PARTICLE_MAX_NUM*m_iNumVerts*sizeof(customVertex_s), D3DUSAGE_DYNAMIC|D3DUSAGE_WRITEONLY, D3DFVF_CUSTOMVERTEX, D3DPOOL_DEFAULT, &m_pVertexBuffer, NULL))){return false;}   return true;BTW the D3DFVF_CUSTOMVERTEX looks like this:#define D3DFVF_CUSTOMVERTEX (D3DFVF_XYZ|D3DFVF_NORMAL|D3DFVF_DIFFUSE|D3DFVF_TEX1)And here´s the particle rendering code: D3DXMATRIX matView;customVertex_s *pVertices;bool render = false;int i, i2;D3DXVECTOR3 transPos;D3DXCOLOR color;// get the view matrixm_pd3dDevice->GetTransform(D3DTS_VIEW, &matView);// fill the dynamic vertexbuffer with the particlesif (FAILED(m_pVertexBuffer->Lock(0, 0, (void**)&pVertices, D3DLOCK_DISCARD)))return;for(i=0, i2=0; i<PARTICLE_MAX_NUM && i<m_iNumParticlesAlive; i++, i2+=m_iNumVerts){if (m_particle[i].m_fAge >= 0.0f){// a particle is a billboard with this form:////// 23//  X--------X//  |x  |//  | x |//  |  x|//  |   O    |//  |    x   |//  |x  |//  | x |//  X--------X// 01//// extract the up and right vectors of the view matrix and use them// to make the particles face the cameratransPos.x = m_particle[i].m_vecCurLocation.x * matView(0, 0) + m_particle[i].m_vecCurLocation.y * matView(1, 0) + m_particle[i].m_vecCurLocation.z * matView(2, 0) + matView(3, 0);transPos.y = m_particle[i].m_vecCurLocation.x * matView(0, 1) + m_particle[i].m_vecCurLocation.y * matView(1, 1) + m_particle[i].m_vecCurLocation.z * matView(2, 1) + matView(3, 1);   transPos.z = m_particle[i].m_vecCurLocation.x * matView(0, 2) + m_particle[i].m_vecCurLocation.y * matView(1, 2) + m_particle[i].m_vecCurLocation.z * matView(2, 2) + matView(3, 2);color = D3DXCOLOR(m_particle[i].m_fColor[0], m_particle[i].m_fColor[1],m_particle[i].m_fColor[2], m_particle[i].m_fColor[3]);pVertices[i2].position = transPos + D3DXVECTOR3(-0.5f*m_particle[i].m_fSize, 0.5f*m_particle[i].m_fSize, -0.0f);pVertices[i2].vecNorm = D3DXVECTOR3(0.0f, 0.0f, 1.0f);pVertices[i2].color = color;pVertices[i2].tu = 0.0f;pVertices[i2].tv = 1.0f;pVertices[i2+1].position = transPos + D3DXVECTOR3(0.5f*m_particle[i].m_fSize, 0.5f*m_particle[i].m_fSize, -0.0f);pVertices[i2+1].vecNorm = D3DXVECTOR3(0.0f, 0.0f, 1.0f);pVertices[i2+1].color = color;pVertices[i2+1].tu = 1.0f;pVertices[i2+1].tv = 1.0f;pVertices[i2+2].position = transPos + D3DXVECTOR3(-0.5f*m_particle[i].m_fSize, -0.5f*m_particle[i].m_fSize, -0.0f);pVertices[i2+2].vecNorm = D3DXVECTOR3(0.0f, 0.0f, 1.0f);pVertices[i2+2].color = color;pVertices[i2+2].tu = 0.0f;pVertices[i2+2].tv = 0.0f;pVertices[i2+3].position = transPos + D3DXVECTOR3(0.5f*m_particle[i].m_fSize, -0.5f*m_particle[i].m_fSize, -0.0f);pVertices[i2+3].vecNorm = D3DXVECTOR3(0.0f, 0.0f, 1.0f);pVertices[i2+3].color = color;pVertices[i2+3].tu = 1.0f;pVertices[i2+3].tv = 0.0f;render = true;}}m_pVertexBuffer->Unlock();if (render){// set alphablendingm_pd3dDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, true);m_pd3dDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);m_pd3dDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);// set depth buffer testm_pd3dDevice->SetRenderState(D3DRS_ZWRITEENABLE, true);m_pd3dDevice->SetRenderState(D3DRS_ZENABLE, true);// set texturestagestatesm_pd3dDevice->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE);m_pd3dDevice->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);m_pd3dDevice->SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_DIFFUSE);// turn off lightingDWORD oldLightMode;m_pd3dDevice->GetRenderState(D3DRS_LIGHTING, &oldLightMode);m_pd3dDevice->SetRenderState(D3DRS_LIGHTING, false);// turn off cullingDWORD oldCullMode;m_pd3dDevice->GetRenderState(D3DRS_CULLMODE, &oldCullMode);m_pd3dDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);m_pd3dDevice->SetTexture(0, GetTexture(m_iTexture));m_pd3dDevice->SetStreamSource(0, m_pVertexBuffer, 0, sizeof(customVertex_s));m_pd3dDevice->SetFVF(D3DFVF_CUSTOMVERTEX);// draw all the particles, 2 primitives per particlem_pd3dDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, m_iNumParticlesAlive*2);// reset renderstatesm_pd3dDevice->SetTexture(0, NULL);m_pd3dDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, false);m_pd3dDevice->SetRenderState(D3DRS_LIGHTING, oldLightMode);m_pd3dDevice->SetRenderState(D3DRS_CULLMODE, oldCullMode);m_pd3dDevice->SetRenderState(D3DRS_ZWRITEENABLE, false);}Can anyone see where I´m going wrong with this?EDIT: Typos[edited by - eckbw on February 13, 2004 4:20:16 AM][edited by - eckbw on February 13, 2004 4:27:05 AM]
  I believe for what your doing you''re going to have to either:Render each particle as a triangle strip individually (bad) orUse a Triangle LIST to render them all at once. The problem your having is that each particle thinks it should be connected to the next one (because they''re all a strip). Try making each particle out of six vertices (two triangles) and rendering as a list. ;  Great thanks, that did it! Here´s what it looks like now:http://upl.mine.nu/uplfolders/upload9/partsys.JPG ;  Woooo, pretty rainbow. Good job. ;  OMG I just changed the D3DBLEND_SRCALPHA and D3DBLEND_INVSRCALPHA to D3DBLEND_ONE and now the particles look like this:http://upl.mine.nu/uplfolders/upload9/particles58.JPGYou can see the emitter in the middle and the particles are coming towards the screen and changing colors along the way. 