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

D3DFVF_DIFFUSE crash help

Started by Omnipotent Dec 17, 2002 at 2:00 PM 5 replies 350+ views
Original Post
Omnipotent
Omnipotent
Hi All, I am new at using d3d and need a little help. I am making a particle engine and I am having trouble whenever I add D3DFVF_DIFFUSE as a flag and to my struct. It crashes my program, whenever I have this flag. I want to be able to change the color of my particles but I am unable to do so whenever I try to use D3DFVF_DIFFUSE. Maybe I am forgetting to do something. Here is my code that is relevant to my problem: struct PARTICLEVERTEX { D3DXVECTOR3 vecPos; D3DXCOLOR clrDiffuse; FLOAT tu; FLOAT tv; }; #define D3DFVF_PARTICLEVERTEX ( D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_TEX1 ) //RestoreDevice Code HRESULT hr; PARTICLEVERTEX v[4]; UINT k = 0; v[k].vecPos = D3DXVECTOR3( -1.0f, -1.0f, 0.0f ); v[k].clrDiffuse = D3DCOLOR_ARGB( 255, 0, 0, 255 ); v[k].tu = 0.0f; v[k].tv = 1.0f; k++; v[k].vecPos = D3DXVECTOR3( -1.0f, 1.0f, 0.0f ); v[k].clrDiffuse = D3DCOLOR_ARGB( 255, 0, 0, 255 ); v[k].tu = 0.0f; v[k].tv = 0.0f; k++; v[k].vecPos = D3DXVECTOR3( 1.0f, 1.0f, 0.0f ); v[k].clrDiffuse = D3DCOLOR_ARGB( 255, 0, 0, 255 ); v[k].tu = 1.0f; v[k].tv = 0.0f; k++; v[k].vecPos = D3DXVECTOR3( 1.0f, -1.0f, 0.0f ); v[k].clrDiffuse = D3DCOLOR_ARGB( 255, 0, 0, 255 ); v[k].tu = 1.0f; v[k].tv = 1.0f; k++; if( FAILED( hr = m_pd3dDevice->CreateVertexBuffer( sizeof(v), D3DUSAGE_WRITEONLY, D3DFVF_PARTICLEVERTEX, D3DPOOL_MANAGED, &m_pParticleVB ) ) ) { return hr; } VOID* pVertices; // Fill in the grid vertex data m_pParticleVB->Lock( 0, sizeof(v), (BYTE**)&pVertices, 0 ); memcpy( pVertices, v, sizeof(v) ); m_pParticleVB->Unlock(); return S_OK; //RENDER CODE D3DXMATRIX ViewMatrix; D3DXMatrixIdentity( &ViewMatrix ); // get the ViewMatrix from D3D m_pd3dDevice->GetTransform( D3DTS_VIEW, &ViewMatrix ); D3DXMATRIX InvViewMatrix; D3DXMatrixIdentity( &InvViewMatrix ); D3DXMatrixInverse( &InvViewMatrix, NULL, &ViewMatrix ); m_pd3dDevice->SetRenderState( D3DRS_LIGHTING, FALSE ); m_pd3dDevice->SetRenderState( D3DRS_ZWRITEENABLE, FALSE ); m_pd3dDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, TRUE ); m_pd3dDevice->SetRenderState( D3DRS_SRCBLEND, D3DBLEND_ONE ); m_pd3dDevice->SetRenderState( D3DRS_DESTBLEND, D3DBLEND_ONE ); m_pd3dDevice->SetStreamSource( 0, m_pParticleVB, sizeof( PARTICLEVERTEX ) ); m_pd3dDevice->SetVertexShader( D3DFVF_PARTICLEVERTEX ); m_pd3dDevice->SetTexture( 0, m_pParticleTexture ); for( int i = 0; i < m_iNumberParticles; i++ ) { InvViewMatrix._41 = m_pParticles.m_vPosition.x; InvViewMatrix._42 = m_pParticles[i].m_vPosition.y; InvViewMatrix._43 = m_pParticles[i].m_vPosition.z; // Set the new world transform and render the particle m_pd3dDevice->SetTransform( D3DTS_WORLD, &InvViewMatrix ); m_pd3dDevice->DrawPrimitive( D3DPT_TRIANGLEFAN, 0, 2 ); } m_pd3dDevice->SetRenderState( D3DRS_LIGHTING, TRUE ); m_pd3dDevice->SetRenderState( D3DRS_ZWRITEENABLE, TRUE ); m_pd3dDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, FALSE ); m_pd3dDevice->SetTexture( 0, NULL ); return S_OK;
mdias
mdias
Try to use a D3DMATERIAL8 instead of D3DFVF_DIFFUSE

KaMiKaZe
Sharky
Sharky
quote:
Original post by Omnipotent

struct PARTICLEVERTEX
{
D3DXVECTOR3 vecPos;
D3DXCOLOR clrDiffuse;
FLOAT tu;
FLOAT tv;
};




Try changing the D3DXCOLOR to D3DCOLOR .
D3DXCOLOR is equivalent to 4 float values for each of the R,G,B and A components, whilst D3DCOLOR is equivalent to the DWORD type. In this case you need DWORD and, hence, D3DCOLOR.

This should hopefully fix the problem.

Regards,
Sharky
Omnipotent
Omnipotent
The missing was just a cut and paste error. But good eye. I have figured out the problem. It was the D3DXCOLOR variable in the struct, it should be either D3DCOLOR or DWORD. Now everything works great.
Omnipotent
Omnipotent
Hey thanks Sharky must have replied just as I was sending my reply. And yup you are right the D3DXCOLOR was the error.

Thanks for the help,

Omnipotent
mdias
mdias
quote:
Original post by Jim Adams
Error here:

InvViewMatrix._41 = m_pParticles.m_vPosition.x;
InvViewMatrix._42 = m_pParticles.m_vPosition.y;
InvViewMatrix._43 = m_pParticles[i].m_vPosition.z;

The 1st line is missing [i]




I don''t think so... it''s missing due to [ i] = "Italic" hehehe,
in your code it''s missing a [ i] too on the 2nd line, lololol

KaMiKaZe

Topic Locked

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

Sign in to reply to this topic.