CreateFlags.TriangleStrip
The Pentium Guyhey, 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-
VBBRI think you did something wrong when creating the buffer. Look in [url]www.directx4vb.com[/url] for a good tutorial on D3D9.
The Pentium Guyoh, no, it's right, i realized what i did wrong, TriangleStrip reads the vertices this order: 012, 123, 234, 345, 456.. etc and the order that i have them in, it doesnt like :p
Eric ColemanI think you have the logic wrong in creating your cube. A cube face is comprised of 2 triangles. That translates to 6 vertices per "square" face. With 6 faces that's a total of 36 vertices, not 12. You can reduce this if you use indexed primitives, but from what you're doing, you're not indexing them, so I won't explain that.
The Pentium Guyyeah ur right, i did have the logic wrong - what i jsut did was created a Triangle class, and then created a Rectangle Class which inherited from the triangle class, and then created a CUBE class which inherited from the RECTANGLE class and put it all together and it worked o_O, its a much bigger releif doing that then just creating a cube class.. and plus its a little bit more organized :) thanks, pent
VBBROne more thing, the primitive count of DrawPrimitives is the number of TRIANGLES and not number of vertices.
The Pentium Guyoh yeah, sorry that's what i meant :)
Eric ColemanA triangle as a class seems a bit overboard IMHO.
PeterYeah, thats oop taken to an insane level And it cant be fast ;)