Jump to content
  • Advertisement
Sign in to follow this  
Bargaust

[SlimDX] Vertex format

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

I have a vertex format which currently only specifies the vertex Position and the Texture Coordinates. The structure is as follows:
    [StructLayout(LayoutKind.Sequential)]
    struct TestVertex
    {
        public Vector4 Position;
        public Vector2 TextureCoords;

        public static VertexFormat Format
        {
            get
            {
                return VertexFormat.Position | VertexFormat.Texture1;
            }
        }

        public static int SizeInBytes
        {
            get
            {
                return Marshal.SizeOf(typeof(TestVertex));
            }
        }
    }
I need to be able to transform the vertices, so I'm used Position instead of PositionRhw. However, when I try to render a square using this format, I just get a black square with no texture. If I change Position to PositionRhw, I get the texture showing properly, but don't get the transformation applied. Can anyone see what I'm doing wrong? Here is some of the other code if it helps: Initialising the rectangle:
            this.vertices = new VertexBuffer(device, 4 * TestVertex.SizeInBytes, Usage.WriteOnly, TestVertex.Format, Pool.Default);

            DataStream stream = vertices.Lock(0, 0, LockFlags.None);

            TestVertex[] vertexData = new TestVertex[4];

            vertexData[0].Position = new Vector4(0F, 256F, 1F, 1F);
            vertexData[0].TextureCoords = new Vector2(0F, 1F);

            vertexData[1].Position = new Vector4(0F, 0F, 1F, 1F);
            vertexData[1].TextureCoords = new Vector2(0F, 0F);

            vertexData[2].Position = new Vector4(256F, 0F, 1F, 1F);
            vertexData[2].TextureCoords = new Vector2(1F, 0F);

            vertexData[3].Position = new Vector4(256F, 256F, 1F, 1F);
            vertexData[3].TextureCoords = new Vector2(1F, 1F);

            stream.WriteRange(vertexData);

            vertices.Unlock();

Rendering the rectangle:
            this.device.SetTexture(0, texture);
            this.device.SetStreamSource(0, vertices, 0, TestVertex.SizeInBytes);
            this.device.VertexFormat = TestVertex.Format;

            this.device.DrawPrimitives(PrimitiveType.TriangleFan, 0, 2);

Share this post


Link to post
Share on other sites
Advertisement
When you use the VertexFormat.Position specifier, Direct3D expects your position data to come in XYZ format, not XYZW. I'd guess that it's looking for your texture coordinates four bytes early and getting the W coordinate of the position instead.

Share this post


Link to post
Share on other sites
I've changed my Vertex structure to:

    [StructLayout(LayoutKind.Sequential)]
struct TestVertex
{
public Vector3 Position;
public Vector2 TextureCoords;

public static VertexFormat Format
{
get
{
return VertexFormat.Position | VertexFormat.Texture1;
}
}

public static int SizeInBytes
{
get
{
return Marshal.SizeOf(typeof(TestVertex));
}
}
}



And... I'm still getting the same. :(


Thanks though, I'm sure that was an issue too.

Share this post


Link to post
Share on other sites
Have you disabled lighting (i.e. called device.SetRenderState( RenderState.Lighting, false ); )? In Direct3D lighting is enabled by default and, as far as I remebmer is skipped if you're using transformed coordinates.

Share this post


Link to post
Share on other sites
Sign in to follow this  

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