Sign in to follow this  
Calin

Slimdx vertex format question

Recommended Posts

I'm trying to port some C++ code to slimdx The tutorial in question has a custom defined vertex structure:
struct TVertex
{
	D3DXVECTOR3 pos;
	D3DXVECTOR3 otherPos;
	D3DXVECTOR4 texOffset;
	D3DXVECTOR3 thickness;
	static const DWORD FVF = D3DFVF_XYZ | D3DFVF_NORMAL |
		D3DFVF_TEX2 | // D3DFVF_TEX2 specifies we have two sets of texture coordinates.
		D3DFVF_TEXCOORDSIZE4(0) | // This specifies that the first (0th) tex coord set has size 4 floats.
		D3DFVF_TEXCOORDSIZE3(1); // Specifies that second tex coord set has size 2 floats.
};


and it does the drawing like so
VOID RenderLine( D3DXVECTOR3& v0, D3DXVECTOR3& v1 )
{
	TVertex vrts[4];
	vrts[0].pos = v0;		vrts[0].otherPos = v1;
	vrts[1].pos = v1;		vrts[1].otherPos = v0;
	vrts[2].pos = v0;		vrts[2].otherPos = v1;
	vrts[3].pos = v1;		vrts[3].otherPos = v0;

	vrts[0].thickness = D3DXVECTOR3( -g_fThickness, 0.f, g_fThickness * 0.5f );
	vrts[1].thickness = D3DXVECTOR3(  g_fThickness, 0.f, g_fThickness * 0.5f );
	vrts[2].thickness = D3DXVECTOR3(  g_fThickness, 0.f, g_fThickness * 0.5f );
	vrts[3].thickness = D3DXVECTOR3( -g_fThickness, 0.f, g_fThickness * 0.5f );

	vrts[0].texOffset = D3DXVECTOR4( g_fThickness, g_fThickness, 0.f, 0.f );
	vrts[1].texOffset = D3DXVECTOR4( g_fThickness, g_fThickness, 0.25f, 0.f );
	vrts[2].texOffset = D3DXVECTOR4( g_fThickness, g_fThickness, 0.f, 0.25f );
	vrts[3].texOffset = D3DXVECTOR4( g_fThickness, g_fThickness, 0.25f, 0.25f );

	g_pD3DDevice->DrawPrimitiveUP( D3DPT_TRIANGLESTRIP, 2, vrts, sizeof( TVertex ) );
}


How would I port this code to C#/SDX? I'm using the SDX particle sample as starting point however it uses a (non FVF) vertex buffer and VertexFormat.Position for vertex format [Edited by - Calin on October 14, 2008 7:19:47 AM]

Share this post


Link to post
Share on other sites
Here's the equivalent C#/SlimDX code:


VertexFormat TexCoordSize3(int index)
{
return (VertexFormat)(1 << (index * 2 + 16));
}

VertexFormat TexCoordSize4(int index)
{
return (VertexFormat)(2 << (index * 2 + 16));
}

[StructLayout(LayoutKind.Sequential)]
struct TVertex
{
public Vector3 pos;
public Vector3 otherPos;
public Vector4 texOffset;
public Vector3 thickness;

public static VertexFormat Format = VertexFormat.Position | VertexFormat.Normal |
VertexFormat.Texture2 | TexCoordSize4(0) | TexCoordSize3(1);
}

void RenderLine(Vector3 v0, Vector3 v1)
{
TVertex[] vrts = new TVertex[4];
vrts[0].pos = v0; vrts[0].otherPos = v1;
vrts[1].pos = v1; vrts[1].otherPos = v0;
vrts[2].pos = v0; vrts[2].otherPos = v1;
vrts[3].pos = v1; vrts[3].otherPos = v0;

vrts[0].thickness = new Vector3( -g_fThickness, 0.0f, g_fThickness * 0.5f );
vrts[1].thickness = new Vector3( g_fThickness, 0.0f, g_fThickness * 0.5f );
vrts[2].thickness = new Vector3( g_fThickness, 0.0f, g_fThickness * 0.5f );
vrts[3].thickness = new Vector3( -g_fThickness, 0.0f, g_fThickness * 0.5f );

vrts[0].texOffset = new Vector4( g_fThickness, g_fThickness, 0.0f, 0.0f );
vrts[1].texOffset = new Vector4( g_fThickness, g_fThickness, 0.25f, 0.0f );
vrts[2].texOffset = new Vector4( g_fThickness, g_fThickness, 0.0f, 0.25f );
vrts[3].texOffset = new Vector4( g_fThickness, g_fThickness, 0.25f, 0.25f );

g_pD3DDevice.DrawUserPrimitives( PrimitiveType.TriangleList, 2, vrts );
}




Share this post


Link to post
Share on other sites

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