The Pentium Guy | hey, i tried making a function that creates a cube easily, unfortunately, the compiler doesnt like the number of primitaves i provided(a cube has 6 faces, thus 12 vertices..)
here's my function
[vb]
Public Function CreateCube(ByVal TopLeftPos As Vector3, ByVal Width As Integer, ByVal Height As Integer, ByVal Depth As Integer, ByVal ImageLocation As String) As CustomVertex.PositionTextured
Dim vertices() As CustomVertex.PositionTextured
Dim ColorKeyVal As Color = Color.FromArgb(255, 0, 255, 0) 'LimeGreen
Try
SprTexture = TextureLoader.FromFile(d3ddev, ImageLocation)
VertBuffer = New VertexBuffer(GetType(CustomVertex.PositionTextured), 8, d3ddev, Usage.WriteOnly, CustomVertex.PositionTextured.Format, Pool.Default)
vertices = VertBuffer.Lock(0, 0)
'-----------------------------
' Front face - The Z's are the same
'Top Left
vertices(0) = CreateFlexVertex(TopLeftPos.X, TopLeftPos.Y, TopLeftPos.Z, 0, 0)
'Bottom Left
vertices(1) = CreateFlexVertex(TopLeftPos.X, TopLeftPos.Y + Height, TopLeftPos.Z, 0, 1)
'Top Right
vertices(2) = CreateFlexVertex(TopLeftPos.X + Width, TopLeftPos.Y, TopLeftPos.Z, 1, 0)
'Bottom Right
vertices(3) = CreateFlexVertex(TopLeftPos.X + Width, TopLeftPos.Y + Height, TopLeftPos.Z, 1, 1)
'------------------------------
'-----------------------------
' Top face - The Y's are the same
'***Note: The Front Face's Top Left and Top Right are shared by the Top Face's Bottom Left and Bottom Right, so we don't need them
'
'Top Left(Prentend you're looking at this face from the top)
vertices(4) = CreateFlexVertex(TopLeftPos.X, TopLeftPos.Y, TopLeftPos.Z + Depth, 0, 0)
'Top Right
vertices(5) = CreateFlexVertex(TopLeftPos.X + Width, TopLeftPos.Y, TopLeftPos.Z + Depth, 1, 0)
'------------------------------
'-----------------------------
' Bottom face - The Y's are the same
'***Note: The Front Face's Bottom Left and Bottom Right are shared by the Bottom Face's Top Left and Top Right
'
'Bottom Left(Prentend you're "underneath" this face)
vertices(6) = CreateFlexVertex(TopLeftPos.X, TopLeftPos.Y + Height, TopLeftPos.Z + Depth, 0, 0)
'Bottom Right
vertices(7) = CreateFlexVertex(TopLeftPos.X + Width, TopLeftPos.Y + Height, TopLeftPos.Z + Depth, 1, 0)
'------------------------------
'-----------------------------
' Left face - The X's are the same
'***Note: All of the Left Face's vertices are shared by the other vertices
'-----------------------------
'-----------------------------
' Right face - The X's are the same
'***Note: All of the Left Face's vertices are shared by the other vertices
'-----------------------------
'-----------------------------
' Back face - The Z's are the same
'***Note: All of the Left Face's vertices are shared by the other vertices
'-----------------------------
VertBuffer.Unlock()
Catch de As Exception
MessageBox.Show("Something stupid happened while creating your cube... so yeah. Error: " & de.Message, "3D Initialization.", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Function
[/vb]
and here's the render sub(where the problem is)
[vb]
Public Sub Render()
d3ddev.VertexFormat = CustomVertex.PositionTextured.Format
d3ddev.SetStreamSource(0, VertBuffer, 0)
d3ddev.SetTexture(0, SprTexture)
d3ddev.DrawPrimitives(PrimitiveType.TriangleStrip, 0, 12) '<-- right here
End Sub
[/vb]
does anyone know waht im doing wrong here?,
thanks,
-Pent- |