I know the content of this is DirectX but the problem I have is the mechanics of the usage of the array hence posting here
I don't follow how this code works and hope someone can explain.
Here goes;
In the procedure CreateTextures() Verts is declared as CUSTOMVERTEX() which is a structure. So Verts is an array of structures?
This line, SquareVertices(Verts), passes Verts to the SquareVertices procedure ByVal again an array of structures?
In SquareVertices it assigns values to each array element.
But how come the redim staement is not required? I spent a lot of time trying to get this to work and by trial and error found if I removed the redim line it work??
Duh.....don't get it
I don't follow how this code works and hope someone can explain.
Here goes;
Visual Basic:
Public Function CreateTextures() As Boolean
Dim Verts As CustomVertex()
Dim intX As Integer
Dim strTexturePath As String
Try
For intX = 1 To 10
strTexturePath = Application.StartupPath & "\walk" & CStr(intX) & ".bmp"
Textures(intX - 1) = TextureLoader.FromFile(m_objDevice, strTexturePath)
Next
VertBuffer = New VertexBuffer(GetType(CustomVertex), NUM_VERTS, m_objDevice, Usage.WriteOnly, FVF_CUSTOMVERTEX, Pool.Default)
Verts = VertBuffer.Lock(0, 0)
SquareVertices(Verts)
VertBuffer.Unlock()
Return True
Catch objException As Exception
Return False
End Try
End Function
Private Function SquareVertices(ByVal Vertices As CUSTOMVERTEX())
Vertices(0) = CreateFlexVertex(60, 60, 0, 1, 0, 0)
Vertices(1) = CreateFlexVertex(240, 60, 0, 1, 1, 0)
Vertices(2) = CreateFlexVertex(60, 240, 0, 1, 0, 1)
Vertices(3) = CreateFlexVertex(240, 240, 0, 1, 1, 1)
End Function
Private Function CreateFlexVertex(ByVal X As Single, ByVal Y As Single, ByVal Z As Single, ByVal rhw As Single, _
ByVal tu As Single, ByVal tv As Single) As CUSTOMVERTEX
CreateFlexVertex.X = X
CreateFlexVertex.Y = Y
CreateFlexVertex.Z = Z
CreateFlexVertex.rhw = rhw
CreateFlexVertex.tu = tu
CreateFlexVertex.tv = tv
End Function
In the procedure CreateTextures() Verts is declared as CUSTOMVERTEX() which is a structure. So Verts is an array of structures?
This line, SquareVertices(Verts), passes Verts to the SquareVertices procedure ByVal again an array of structures?
In SquareVertices it assigns values to each array element.
But how come the redim staement is not required? I spent a lot of time trying to get this to work and by trial and error found if I removed the redim line it work??
Duh.....don't get it