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

Rendering Point Sprites

Started by DOrmisher Mar 23, 2009 at 12:59 PM 0 replies 800+ views
Original Post
DOrmisher
DOrmisher
Hi, I'm currently trying to draw some point sprites but I seem to be having a problem. This is the relevant code:

// Vertex format and particle structure
struct SParticleVertex
{
	D3DXVECTOR3 m_Position;
	enum FVF
	{
		FVF_Flags = D3DFVF_XYZ|D3DFVF_DIFFUSE
	};
};

struct SParticle
{
	D3DXVECTOR3 m_Position;
};

const int MAX_PARTICLES = 2;
SParticle g_particles[MAX_PARTICLES];
LPDIRECT3DVERTEXBUFFER9 VertexBuffer = NULL;

LPDIRECT3DTEXTURE9 smokeTex;

// Vertex buffer creation and point sprite setup
D3DXCreateTextureFromFile( d3dManager->m_d3dDevice, "Smoke1.tga", &smokeTex );

	d3dManager->m_d3dDevice->CreateVertexBuffer( MAX_PARTICLES * sizeof(SParticleVertex),
											     D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY | D3DUSAGE_POINTS, 
											     SParticleVertex::FVF_Flags, D3DPOOL_DEFAULT, 
											     &VertexBuffer, NULL );

	for( int i = 0; i < MAX_PARTICLES; ++i )
    {
		g_particles.m_Position = D3DXVECTOR3(0.0f,i,0.0f);
	}

	d3dManager->m_d3dDevice->SetRenderState( D3DRS_POINTSPRITEENABLE, TRUE );
    d3dManager->m_d3dDevice->SetRenderState( D3DRS_POINTSCALEENABLE,  TRUE );

// Render point list
SParticleVertex *pPointVertices;

		VertexBuffer->Lock( 0, MAX_PARTICLES * sizeof(SParticleVertex),
									 (void**)&pPointVertices, D3DLOCK_DISCARD );

		for( int i = 0; i < MAX_PARTICLES; ++i )
		{
			pPointVertices->m_Position = g_particles.m_Position;
			pPointVertices++;
		}

		VertexBuffer->Unlock();

		CRenderMethod* method = Renderer->GetMethod( Texture );
		d3dManager->m_d3dDevice->SetVertexShader( method->m_vs->m_Shader );
		d3dManager->m_d3dDevice->SetPixelShader( method->m_ps->m_Shader );
		d3dManager->m_d3dDevice->SetTexture( 0, smokeTex );

		d3dManager->m_d3dDevice->SetStreamSource( 0, VertexBuffer, 0, sizeof(SParticleVertex) );
		d3dManager->m_d3dDevice->SetFVF( SParticleVertex::FVF_Flags );
		d3dManager->m_d3dDevice->DrawPrimitive( D3DPT_POINTLIST, 0, MAX_PARTICLES );

The point sprite isn't being rendered but 1 pixel directly in the middle of the screen is lit up so I assume something is happening. Can anyone spot where I am going wrong?
She got a hat and all that hat says is asshole
Supernat02
Supernat02
Try setting the D3DRS_POINTSIZE render state to a larger value, or add Point Size to the vertex structure, just to rule that out. You're in untransformed coordinates, so maybe your perspective is too far away from the point itself. Try moving your camera closer or reducing the FOV. I don't see that code below, so that's just a guess.
Chris ByersMicrosoft DirectX MVP - 2005

Topic Locked

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

Sign in to reply to this topic.