Semi-Transparent Primitives

Started by
0 comments, last by Hodgman 17 years ago
Ok, nothing fancy heare, I am just trying to learn about primitives, vertices and colors. Using the following code, I get a cube that rotates around, but some of the faces of the cube are semi-transparent. (I can see thru them to the face on the other side.) Can someone tell me what is going on here? verts = new CustomVertex.PositionColored[8]; verts[0].X = -1.0f; verts[0].Y = 1.0f; verts[0].Z = -1.0f; verts[0].Color = System.Drawing.Color.Red.ToArgb(); verts[1].X = 1.0f; verts[1].Y = 1.0f; verts[1].Z = -1.0f; verts[1].Color = System.Drawing.Color.Green.ToArgb(); verts[2].X = -1.0f; verts[2].Y = -1.0f; verts[2].Z = -1.0f; verts[2].Color = System.Drawing.Color.Blue.ToArgb(); verts[3].X = 1.0f; verts[3].Y = -1.0f; verts[3].Z = -1.0f; verts[3].Color = System.Drawing.Color.Yellow.ToArgb(); verts[4].X = -1.0f; verts[4].Y = 1.0f; verts[4].Z = 1.0f; verts[4].Color = System.Drawing.Color.Red.ToArgb(); verts[5].X = -1.0f; verts[5].Y = -1.0f; verts[5].Z = 1.0f; verts[5].Color = System.Drawing.Color.Blue.ToArgb(); verts[6].X = 1.0f; verts[6].Y = 1.0f; verts[6].Z = 1.0f; verts[6].Color = System.Drawing.Color.Green.ToArgb(); verts[7].X = 1.0f; verts[7].Y = -1.0f; verts[7].Z = 1.0f; verts[7].Color = System.Drawing.Color.Yellow.ToArgb(); indicies = new int [24]; indicies[0] = 0; indicies[1] = 1; indicies[2] = 2; indicies[3] = 3; indicies[4] = 4; indicies[5] = 5; indicies[6] = 6; indicies[7] = 7; indicies[8] = 4; indicies[9] = 6; indicies[10] = 0; indicies[11] = 1; indicies[12] = 5; indicies[13] = 2; indicies[14] = 7; indicies[15] = 3; indicies[16] = 1; indicies[17] = 6; indicies[18] = 3; indicies[19] = 7; indicies[20] = 0; indicies[21] = 2; indicies[22] = 4; indicies[23] = 5; vertexBuffer = new VertexBuffer(typeof(CustomVertex.PositionColored), verts.Length, device, Usage.Dynamic | Usage.WriteOnly, CustomVertex.PositionColored.Format, Pool.Default); GraphicsStream gStream = vertexBuffer.Lock(0, 0, LockFlags.None); gStream.Write(verts); vertexBuffer.Unlock(); indexBuffer = new IndexBuffer(typeof(int), indicies.Length, device, Usage.WriteOnly, Pool.Default); gStream = indexBuffer.Lock(0, 0, LockFlags.None); gStream.Write(indicies); indexBuffer.Unlock(); My Render Code: device.VertexFormat = CustomVertex.PositionColored.Format; device.SetStreamSource(0, vertexBuffer, 0); device.Indices = indexBuffer; device.DrawIndexedPrimitives(PrimitiveType.TriangleStrip, 0, 0, 8, 0, 2); device.DrawIndexedPrimitives(PrimitiveType.TriangleStrip, 0, 0, 8, 4, 2); device.DrawIndexedPrimitives(PrimitiveType.TriangleStrip, 0, 0, 8, 8, 2); device.DrawIndexedPrimitives(PrimitiveType.TriangleStrip, 0, 0, 8, 12, 2); device.DrawIndexedPrimitives(PrimitiveType.TriangleStrip, 0, 0, 8, 16, 2); device.DrawIndexedPrimitives(PrimitiveType.TriangleStrip, 0, 0, 8, 20, 2); Thanks for the help. John
Advertisement
it's probably back-face culling.

By default, primitives are one-sided. If you look at them from the wrong side they will be invisible.

You can fix this by either reversing the "winding order" of the verts (the order that you specify the vertecies)
  1      ->    13   2        2   3


or by turning off back-face culling

This topic is closed to new replies.

Advertisement