Error passing VertexBuffer to Draw function (VB.NET)

Obvious

Newcomer
Joined
Dec 23, 2003
Messages
2
I'm using VB.NET 2003 with D3D9 and having problems with drawing and vertex buffers. I'm creating a graphics class for my upcoming 2d tile-based game.

I have a working version, and decided to rewrite it for more organization, but the new version doesn't work.

The problem comes when I try and pass a vertex buffer as an argument for my draw function (I get an unknown error).

My first version kept the vertexbuffer inside the graphics class in scope with the D3D device, but my rewrite is using a separate class which passes it's vertexbuffer to the graphics class. Besides that, there's no difference. Here's my code:


Code:
    'separate class
    Private Texture1 As Texture
    Private VertexBuffer1 As VertexBuffer

    Public Sub New()
        Graphics.PlotQuad(VertexBuffer1, New Drawing.Rectangle(50, 50, 64, 128))
    End Sub

    Public Sub Draw()
        Graphics.DrawQuad(VertexBuffer1)
    End Sub

Code:
    'Graphics class
    Public Sub PlotQuad(ByVal Buffer As VertexBuffer, ByVal rDest As Drawing.Rectangle)
        Buffer = New VertexBuffer(GetType(CustomVertex.TransformedTextured), 4, D3DDev, 0, CustomVertex.TransformedTextured.Format, Pool.Default)

        Dim v As CustomVertex.TransformedTextured() = CType(Buffer.Lock(0, 0), CustomVertex.TransformedTextured())
        v(0) = New CustomVertex.TransformedTextured(rDest.Left, rDest.Top, 0, 1, 0, 0)
        v(1) = New CustomVertex.TransformedTextured(rDest.Right, rDest.Top, 0, 1, 1, 0)
        v(2) = New CustomVertex.TransformedTextured(rDest.Left, rDest.Bottom, 0, 1, 0, 1)
        v(3) = New CustomVertex.TransformedTextured(rDest.Right, rDest.Bottom, 0, 1, 1, 1)
        Buffer.Unlock()
    End Sub

    Public Sub DrawQuad(ByVal Buffer As VertexBuffer)
        D3DDev.SetStreamSource(0, Buffer, 0)
        D3DDev.VertexFormat = CustomVertex.TransformedTextured.Format
        D3DDev.DrawPrimitives(PrimitiveType.TriangleStrip, 0, 2)
    End Sub

I get the error on the D3DDev.DrawPrimitives line, if anyone needs the source code to understand better let me know.
 
Back
Top