Jump to content
  • Advertisement

Archived

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

HexDump

please gimme a hand with point sprites

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

Well, this is fast render function I made for a point sprite. I made this fast example because wanna have a look at how point sprites were. But I have found a weird prob. If I set the position to (0,0,2), the point sprite is well positioned and it shows nice. But If I set position for example to (1,0,2) the point sprites moves a lot to the right... it sometimes disapears (depending on the camera). The thing is, what am I doing wrong? I have checked a lot of sources and they do the same I do here . Could anybody help me here pls? I would be really greatefull. Heres is the source code:
  

bool CnParticleSystem::Update(float fElapsedTime)
{

	LPDIRECT3DDEVICE9 pD=pDev;
	
	//Set Render States for Sprites

	pDev->SetRenderState(D3DRS_CULLMODE,D3DCULL_NONE);
	pDev->SetRenderState(D3DRS_FILLMODE,D3DFILL_SOLID);
	pDev->SetRenderState(D3DRS_LIGHTING, FALSE);
	pDev->SetRenderState(D3DRS_ZENABLE, FALSE);

	// Set the render states for using point sprites

	pDev->SetRenderState(D3DRS_POINTSPRITEENABLE, TRUE);
	pDev->SetRenderState(D3DRS_POINTSCALEENABLE,  TRUE);
	pDev->SetRenderState(D3DRS_POINTSIZE, FtoDW(100.0f));
	pDev->SetRenderState(D3DRS_POINTSCALE_A,  FtoDW(0.00f));
	pDev->SetRenderState(D3DRS_POINTSCALE_B,  FtoDW(0.00f));
	pDev->SetRenderState(D3DRS_POINTSCALE_C,  FtoDW(1.00f));
	pDev->SetRenderState( D3DRS_POINTSIZE_MIN, FtoDW(0.00f) );
	pDev->SetRenderState( D3DRS_POINTSIZE_MAX, FtoDW(1000.00f) );
	
	
	
	D3DXMATRIX WorldMatrix;
	//Set Project and View Transformation matrices

	D3DXMATRIX matProj;
	D3DXMatrixPerspectiveFovLH (&matProj,45/180,640/480,1,1000);
	pDev->SetTransform(D3DTS_PROJECTION, &matProj);
	
	D3DXMATRIX matView;
        D3DXMatrixLookAtLH(&matView,&D3DXVECTOR3(0.0f, 0.0f, -10.0f),
		                   &D3DXVECTOR3(0.0f, 0.0f, 1.0f),
		                   &D3DXVECTOR3(0.0f, 1.0f, 0.0f));
	pDev->SetTransform(D3DTS_VIEW, &matView);
	
	
	D3DXMatrixIdentity(&WorldMatrix);
	pDev->SetTransform(D3DTS_WORLD, &WorldMatrix);
	
	//some vars used to access vertex buffer

	LPDIRECT3DDEVICE9 m_pD=pDev;
	TParticleVertex* pVertices;
		

	TPD3DVB pVB=m_oVB.GetPointer();
	void* pVBData;
	
	if(pVB->Lock(0,sizeof(TParticleVertex)*1,(void**)&pVBData,0) != D3D_OK)
	{		
		CnLog::SysLog(eLowLevel,"\r\r\nError Could not lock vertex buffer.","Error!");
		return false;
	}
	
	pVertices=(TParticleVertex*)pVBData;

	
	pVertices[0].Pos.x=0.0f; //it shows now but if I set it to

	pVertices[0].Pos.y=0;    //1.0f for example, it doesn´t :(

	pVertices[0].Pos.z=2;
	pVertices[0].Color=0xFFFFFFFF;
	
	
	//Render the point sprites

	if(pVB->Unlock() != D3D_OK)
	{		
		CnLog::SysLog(eLowLevel,"Could not UnLock Vertex Buffer");
		return false;
	}
	
	
	if(pDev->SetTexture(0,((CnTexture*)CnGraphicApp::m_oTexMgr.Get(m_nTexID))->GetData())!=D3D_OK)
		return false;

	//decimos a d3d de donde ha de sacar los vertices y los indices

	if(pDev->SetStreamSource(0, pVB, 0, sizeof(TParticleVertex))!=D3D_OK)
		return false;
	//SetVertexShader(NULL);

	if(pDev->SetFVF(PARTICLE_FVF)!=D3D_OK)
		return false;
			
	


	if(pDev->DrawPrimitive(D3DPT_POINTLIST,0,1)!=D3D_OK){
		return false;
	}
	
	pDev->SetRenderState(D3DRS_POINTSPRITEENABLE, FALSE);
	pDev->SetRenderState(D3DRS_POINTSCALEENABLE,  FALSE);
	return true;
}


  
thanks in advance, HexDump.

Share this post


Link to post
Share on other sites
Advertisement

  • 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!