Sign in to follow this  

random colors with my point sprites

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

hey, I am trying to finish building my particle engine that I have been working on for a little bit now and I am having some problems with my colors just randomly changing throughout the particles life. I only set the color once per life and yet the colors flash in a rainbow effect. Here is what my CreateVertexBuffer looks like as well as my custom vertex format and where I add to the vb.
// Create our vertext buffer
m_pD3DDevice->CreateVertexBuffer(
    nMaxStartParticles * sizeof( CUSTOMVERT ),	D3DUSAGE_POINTS|D3DUSAGE_DYNAMIC|D3DUSAGE_WRITEONLY,	
		CUSTOMVERT::FVF,  // FVF format	
		D3DPOOL_DEFAULT,  // memory pool
		&m_pVertexBuffer, // stored buffer
		NULL );	// reserved

// our custom FVF
typedef struct _CUSTOMVERT
{
    D3DXVECTOR3 pos;       
	DWORD dwColor;
	const static DWORD FVF = (D3DFVF_XYZRHW|D3DFVF_DIFFUSE);
} CUSTOMVERT;

m_pVertexBuffer->Lock( 0, size * sizeof(CUSTOMVERT), (void**)&pVBufferData, D3DLOCK_DISCARD );
  for(unsigned i = 0; i < size-1; ++i)
  {	
    if(!m_particleList[i].m_isAlive) 
       continue;
    pVBufferData->pos = m_particleList[i].pos;
    pVBufferData->dwColor = D3DCOLOR_ARGB(m_particleList [i].color[0],m_particleList[i].color[1],m_particleList[i].color[2],m_particleList[i].color[3]);
	pVBufferData++;
  }
 m_pVertexBuffer->Unlock();





and i appologize if the format for is hard to read. m_particleList is a vector, I store the RGBA in an array of unsigned chars. Thanks EDIT: Any help is appreciated :P

Share this post


Link to post
Share on other sites
I'm not sure if this would help any... but when I only move the particles in the y direction... their colors... although not what I specified, stay the same. But if i move them in the x direction they change in rainbow like colors.

Share this post


Link to post
Share on other sites
Your problem is that D3DFVF_XYZRHW specifies a pos vector with 4 floats (x,y,z,w) whereas your custom vertex structure has a Vector3 for its pos. As a result pos data is being written into the colour space and hence the random colours. Use the D3DFVF_XYZ flag instead and it should work.

Share this post


Link to post
Share on other sites
Quote:
Original post by Motorherp
Your problem is that D3DFVF_XYZRHW specifies a pos vector with 4 floats (x,y,z,w) whereas your custom vertex structure has a Vector3 for its pos. As a result pos data is being written into the colour space and hence the random colours. Use the D3DFVF_XYZ flag instead and it should work.


But if he uses the XYZ flag, he loses his transformed verts. Just use a D3DXVECTOR4 and put a 1 for the w component.

Share this post


Link to post
Share on other sites
Has that got something to do with points has it cause I just use XYZ for my meshes and they transform fine. Also you might want to check that for loop gamerxr, it looks like you'll drop out one too early.

Share this post


Link to post
Share on other sites
Quote:
Original post by Motorherp
Has that got something to do with points has it cause I just use XYZ for my meshes and they transform fine. Also you might want to check that for loop gamerxr, it looks like you'll drop out one too early.


XYZRHW is a transformed vertex, so you specify the screen coordinates for the vertex and it skips the whole transformation part of the pipeline. It's great for menu's or hud's.

Share this post


Link to post
Share on other sites
wahoo! :) that fixed it alright! This is my first particle engine and I'm still new direct x so I'm still learning. Thanks for the help guys, much appreciated.

Share this post


Link to post
Share on other sites
Quote:
Original post by Motorherp
Has that got something to do with points has it cause I just use XYZ for my meshes and they transform fine. Also you might want to check that for loop gamerxr, it looks like you'll drop out one too early.


heh.... where did that -1 come from ....

Share this post


Link to post
Share on other sites

This topic is 4813 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.

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