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

Vertex Declaration trouble...

Started by devronious Jan 24, 2007 at 9:02 AM 4 replies 700+ views
Original Post
devronious
devronious
I've created a structure that has the first elements of data assign as follows:
[source lang = "c#"]
        /// <summary>
        /// The X location of the vertex.
        /// </summary>
        public float X;
        /// <summary>
        /// The Y location of the vertex.
        /// </summary>
        public float Y;
        /// <summary>
        /// The X location of the vertex.
        /// </summary>
        public float Z;
        /// <summary>
        /// The horizontal texture coordinate for the vertex.
        /// </summary>
        public float Tu;
        /// <summary>
        /// The vertical texture coordinate for the vertex.
        /// </summary>
        public float Tv;
        /// <summary>
        /// The color for the vertex.
        /// </summary>
        public int color;
        /// <summary>
        /// The clipping left value.
        /// </summary>
        public float Cl;
        /// <summary>
        /// The clipping right value.
        /// </summary>
        public float Cr;
        /// <summary>
        /// The clipping top value.
        /// </summary>
        public float Ct;
        /// <summary>
        /// The clipping bottom value.
        /// </summary>
        public float Cb;

and then in the struct it has a field that describes the format:
[source lang = "c#"]
        /// <summary>
        /// Gets the clipped vertex format.
        /// </summary>
        public static VertexFormats Format
        {
            get
            {
                return 
                    VertexFormats.Position |
                    VertexFormats.Texture1 |
                    VertexFormats.Diffuse |
                    VertexFormats.Normal;
            }
        }

I tried using Texture0 for the texture but I get an error and says that Texture0 is None. I also declare the format as such:
[source lang = "c#"]
        private void InitializeVertexFormats()
        {
            VertexElement[] elements = new VertexElement[]
            {
                new VertexElement(0, 0, DeclarationType.Float3,
                DeclarationMethod.Default,
                DeclarationUsage.Position, 0),
                            
                new VertexElement(0, 12, DeclarationType.Float2,
                DeclarationMethod.Default,
                DeclarationUsage.TextureCoordinate, 0),

                new VertexElement(0, 20, DeclarationType.Color,
                DeclarationMethod.Default,
                DeclarationUsage.Color, 0),

                new VertexElement(0, 24, DeclarationType.Float4,
                DeclarationMethod.Default,
                DeclarationUsage.Normal, 0),
                            
                VertexElement.VertexDeclarationEnd 
            };

            ClippedVertex.vdec = new VertexDeclaration(device, elements);

        }

Is this correct. I'm getting strange results from my vertex shader which is really super basic which I'm sure is not causing the problems.
Scet
Scet
I think that when using FVFs the order things have to be declared is Position->Normal->Diffuse->Texcoord. Also normals are 3 floats long, not 4.
devronious
devronious
I'm trying to trick the system. I'm not actually using normal data but using it for clipping data which requires 4 numbers. I must stream in the clipping with the vertex data so that the clip can change per vertex in the draw call.

Thanks,

Devin
Schrompf
Schrompf
You might want to kick FVFs and start using Vertex Declarations. With them, you have the freedom to stuff anything into you vertex buffers you like. I'm not sure if there's another way, maybe there's some "placeholder" define that takes 4 floats.

Bye, Thomas
----------
Gonna try that "Indie" stuff I keep hearing about. Let's start with Splatter.
devronious
devronious
I'm unfamiliar with the term FVF. Could someone explain? I'm declaring the vertex too. See the code above. When you make a draw call you have to specify format so i'm still stuck with using format enums. Texture0 does not seem to work on my system and I'm at the december 2006 sdk.
devronious
devronious
Schrompf,

You were right I was confused about FVF and VertexDeclarations. I switched the whole deal over to VertexDeclaration and got it to work now.

Thanks,

Your big helps.

Topic Locked

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

Sign in to reply to this topic.