• Advertisement
Sign in to follow this  

[VB.Net][SlimDX] Vertexcolors not working

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

Hi, i have some troubles getting vertexcolors working in SlimDX. I've written a .ASE parser which puts all the vertexdata into a vertexbuffer, however, while positions, normals, and texture coordinates are correct, the vertexcolors don't change how the object looks when it's rendered. I explicitly set the color here for showing what i mean. It's here supposed to be a white sphere. Help greatly appreciated. http://img105.imageshack.us/img105/7132/sphereac8.jpg Device initalization code:
            Dim D3DPP As New PresentParameters
            Dim DispMode As New DisplayMode

            With D3DPP
                .AutoDepthStencilFormat = Format.D24S8
                .BackBufferCount = 1
                .BackBufferHeight = 480
                .BackBufferWidth = 640
                .DeviceWindowHandle = RenderWindow
                .EnableAutoDepthStencil = True
                .Windowed = Not isFullScreen
            End With
            With DispMode
                .Height = 480
                .Width = 640
            End With

            D3DDevice = New Device(0, DeviceType.Hardware, RenderWindow,_
 CreateFlags.HardwareVertexProcessing, D3DPP)
            With D3DDevice
                .VertexFormat = VertexFormat.Position Or VertexFormat.Diffuse_
 Or VertexFormat.Texture0 Or VertexFormat.Normal

                .SetRenderState(RenderState.ZEnable, True)
                .SetRenderState(RenderState.Lighting, False)
                .SetRenderState(RenderState.CullMode, Cull.None)

                .SetTransform(TransformState.World, Matrix.Identity)
                .SetTransform(TransformState.View, Matrix.LookAtLH(New_
 Vector3(0, 350, -350), New Vector3(0, 0, 0), New Vector3(0, 1, 0)))
 Matrix.PerspectiveFovLH(3.14 / 4, 1, 1, 500))
            End With

    Public Structure VertexPosTexNorCol
        Public Position As SlimDX.Vector3
        Public TexturePosition As SlimDX.Vector2
        Public NormalVector As SlimDX.Vector3
        Public Color As Integer
    End Structure

Mesh loading code:

        Dim tempContents() As String
        Dim tempRowContents() As String
        Dim I As Integer = 0

        tempContents = System.IO.File.ReadAllLines(Path)

        Dim Vertices(CInt(tempContents(0)) - 1) As VertexPosTexNorCol

        While I < tempContents.Length - 1
            tempRowContents = tempContents(I + 1).Split(CChar(" "))
            Vertices(I).Position.X = CSng(tempRowContents(0))
            Vertices(I).Position.Y = CSng(tempRowContents(1))
            Vertices(I).Position.Z = CSng(tempRowContents(2))
            Vertices(I).TexturePosition.X = CSng(tempRowContents(3))
            Vertices(I).TexturePosition.Y = CSng(tempRowContents(4))
            Vertices(I).NormalVector.X = CSng(tempRowContents(5))
            Vertices(I).NormalVector.Y = CSng(tempRowContents(6))
            Vertices(I).NormalVector.Z = CSng(tempRowContents(7))
            Vertices(I).Color = ColorValue.FromColor(Color.White).ToArgb <- This does nothing
            I = I + 1
        End While

        Level.Vertexbuffer = New VertexBuffer(D3DHandle, Vertices.Length * Marshal.SizeOf(New VertexPosTexNorCol)_
, Usage.WriteOnly, VertexFormat.Diffuse Or VertexFormat.Normal Or VertexFormat.Position_
 Or VertexFormat.Texture1, Pool.Default)
        Dim stream As DataStream = Level.Vertexbuffer.Lock(0, 0, LockFlags.None)
        stream.WriteRange(Of VertexPosTexNorCol)(Vertices)

Rendering code:
    Public Sub Render(ByRef model As VertexBuffer, ByVal Size As Integer)
        D3DHandle.SetStreamSource(0, model, 0, Size)
        D3DHandle.DrawPrimitives(PrimitiveType.TriangleList, 0, 960)
    End Sub

    Private Sub BeginScene()
        D3DHandle.Clear(ClearFlags.Target Or ClearFlags.ZBuffer, Drawing.Color.CadetBlue, 1, 0)
    End Sub

    Private Sub EndScene()
    End Sub

[Edited by - JustMe1984 on November 21, 2007 12:42:23 PM]

Share this post

Link to post
Share on other sites
I don't see where you set the Device.VertexFormat for the fixed function pipeline or the Device.VertexDeclaration for the programmable pipeline, if using shaders. DirectX needs to know how to process your vertices.

EDIT: OK. I see where you set your vertex format. Not used to VB.

[Edited by - GrasshopperDotNet on November 22, 2007 12:17:25 AM]

Share this post

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

  • Advertisement