Sign in to follow this  

Once more into flexible vertex formats

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

http://newtons.bit.googlepages.com/Image11-13-08.jpg I'm still having problems getting flexible vertex formats to work. The FVF's:
Public Structure FVF_Position
    '<-->'Positions
    Public x As Single
    Public y As Single
    Public z As Single

    Shared FVFFormat As VertexFormats = VertexFormats.Position

    Public Sub New(ByVal ix As Single, ByVal iy As Single, ByVal iz As Single)

        Me.x = ix
        Me.y = iy
        Me.z = iz

    End Sub
End Structure

Public Structure FVF_Tex
    '<-->'UV Texture
    Public tu0 As Single
    Public tv0 As Single

    Shared FVFFormat As VertexFormats = VertexFormats.Texture2

    Public Sub New(ByVal itu0 As Single, ByVal itv0 As Single)

        Me.tu0 = itu0
        Me.tv0 = itv0

    End Sub
End Structure

Public Structure FVF_Terrain
    Shared FVFFormat As VertexFormats = VertexFormats.Position Or VertexFormats.Texture2


    Public x As Single
    Public y As Single
    Public z As Single

    Public tu0 As Single
    Public tv0 As Single

End Structure

The renderer:
Private Sub FrameRender()
        '<-->'0. Variables

        '<-->'1.  Clear Target
        D3DDev.Clear(ClearFlags.Target Or ClearFlags.ZBuffer, Drawing.Color.FromArgb(0, 55, 55), 1.0F, 0)

        '<-->'2.  Begin Scene
        D3DDev.BeginScene()

        '<-->'3.  Render Objects
        '<->'Render terrain
        If Not _terrain.VBPos Is Nothing Then
            D3DDev.SetStreamSource(0, _terrain.VBPos, 0)
            D3DDev.SetStreamSource(1, _terrain.VBTex0, 0)

            D3DDev.VertexFormat = FVF_Terrain.FVFFormat

            D3DDev.SetTexture(0, _terrain.Texture0)

            'D3DDev.SetTextureStageState(1, TextureStageStates.ColorArgument1, TextureArgument.TextureColor)
            'D3DDev.SetTextureStageState(1, TextureStageStates.ColorArgument2, TextureArgument.Current)
            'D3DDev.SetTextureStageState(1, TextureStageStates.ColorOperation, TextureOperation.SelectArg1)

            D3DDev.DrawPrimitives(PrimitiveType.TriangleList, 0, Me._terrain.Primitives)
        End If

        '<->Left Bar

        '<->'Draw hud text
        fHudFont.DrawText(Nothing, fFrameRate, D3DPP.BackBufferWidth - 15, 0, Color.White) 'top right

        fHudFont.DrawText(Nothing, _GameDate, 0, 0, Color.White) 'top left.

        fHudFont.DrawText(Nothing, sGamePaused, 0, 10, Color.White) 'top left, second row.

        '<-->'4.  End Scene
        D3DDev.EndScene()

        '<-->'5.  Present
        D3DDev.Present()
    End Sub


I have no idea why I can't get this work. I've tried just about everything. Any help?

Share this post


Link to post
Share on other sites
An FVF describes the contents of stream 0 only. If you want multiple streams use vertex declarations.

You're telling D3D you have 2 sets of texture coords, while you only have 1. Use Texture1, not Texture2. Another value can be mixed in to choose the size of each texcoord, but the default size is 2, so you can ignore that.

Also, you're never setting texture stage 0 to anything, just stage 1. You most likely want to just sample the texture in stage 0.


FVF describes input of stream 0 into vertex shader or fixed vertex processing.

VDecl describes input of all streams into vertex shader or fixed vertex processing.

Fixed vertex processing will select any UV from any texcoord input and output them to any stage (via D3DTSS_TEXCOORDINDEX). So you *could* tell your first texcoord to go to stage 1 if you wanted, but that's not needed here.

Fixed pixel processing processes stages in order until it hits a disabled one, so you start with setting up stage 0, not stage 1.

So, if you want multiple streams...
1. Change to a vertex declaration.
2. Change pixel processing to stage 0.
3. Set stage 1's colorop to disable to ensure you don't accidentally do unexpected pixel processing.

Share this post


Link to post
Share on other sites
Anybody else want to comment? Perhaps someone that knows that ' comments a line in vb.net?

Or perhaps someone who knows how to actually do a vertex declaration in vb.net. #declare doesn't work.

I know I'm being a bit pissy, but I've looked at a crapton of tutorials available on the web, they all do it differently, they all claim it works. And regardless of what I do (and I've spent 10+ hours trying to figure this out) it never works. Half of them use vertexformats.texture0 for multiple textures and others use texture 2, and some use both.

Saying just switch to vertex declaration DOESN'T HELP.

Share this post


Link to post
Share on other sites
No need to get nasty when you don't hear the results you want.. It deters people from wanting to help you.

As I mentioned in the other thread ( http://www.gamedev.net/community/forums/topic.asp?topic_id=514332 ) you need to use vertex declarations for what you are trying to do. You cannot have multiple streams without using them.

Namethatnobodyelsetook gave really good advice, and it's exactly what you need in order to make your code work.

If you insist on using FVFs (you'll hit many more problems down the road, trust me), then stop using multiple streams, set your second texture sampler (you're only setting the first texture sampler index, not a second), and combine your UV coordinates into the same vertex struct that your positions are in. Your code was closer in the original thread. This code you are using features only available to the programmable pipeline with vdecls, not fixed function.

~Graham

Share this post


Link to post
Share on other sites
Quote:
Original post by gwihlidal
No need to get nasty when you don't hear the results you want.. It deters people from wanting to help you.

As I mentioned in the other thread ( http://www.gamedev.net/community/forums/topic.asp?topic_id=514332 ) you need to use vertex declarations for what you are trying to do. You cannot have multiple streams without using them.

Namethatnobodyelsetook gave really good advice, and it's exactly what you need in order to make your code work.

If you insist on using FVFs (you'll hit many more problems down the road, trust me), then stop using multiple streams, set your second texture sampler (you're only setting the first texture sampler index, not a second), and combine your UV coordinates into the same vertex struct that your positions are in. Your code was closer in the original thread. This code you are using features only available to the programmable pipeline with vdecls, not fixed function.

~Graham


Really good advice on how to use flexible vertex formats is to switch to something else? I'm sorry, but that's not a solution unless that original method doesn't work anymore. I'm not going to throw away hours and hours of work just because someone else thinks something else is better. If what I'm doing doesn't work at all anymore due to deprecated code that's one thing. But just saying I should switch to something else because it's better is completely another. It smacks of zealotry and it's exceedingly annoying because it does nothing to address the actual topic of the thread.

Now then, I've seen a dozen different ways of this working on an equal number of tutorials in an equal number of languages. That's with just FVF's, not vertex declarations. So I knew it would work.

Also, I got it to work. It does exactly what I need it to do without adding additional topics that I know nothing about. I have everything I need now from Directx.

Cheers.

Edit: incidentally, I should apologize to Namethatnobodyelsetook upon rereading his post. He was a lot closer to the mark than I initially thought. He mistook a few commented lines for actual code so I took the rest of his post as uninformed and garbage (when it wasn't).

Share this post


Link to post
Share on other sites

This topic is 3315 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.

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