Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Thanks to Zac Howland's answer I was able to get everything working. For anyone else trying to convert Frank Luna's book from DirectX to SharpDX I hope this helps. Here is what I ended up doing:</p> <pre><code>private void _buildGeometryBuffers() { System.IO.FileStream fs = new System.IO.FileStream(@"Chapter6/Content/skull.txt", System.IO.FileMode.Open); int vcount = 0; int tcount = 0; //string ignore = string.Empty; // this is not needed for my C# version using (System.IO.StreamReader reader = new System.IO.StreamReader(fs)) { // Get the vertice count string currentLine = reader.ReadLine(); string extractedLine = currentLine.Substring(currentLine.IndexOf(" ") + 1); vcount = int.Parse(extractedLine); // Get the indice count currentLine = reader.ReadLine(); extractedLine = currentLine.Substring(currentLine.IndexOf(" ") + 1); tcount = int.Parse(extractedLine); // Create vertex buffer // Skip over the first 2 lines (these are not the lines we are looking for) currentLine = reader.ReadLine(); currentLine = reader.ReadLine(); string[] positions = new string[6]; List&lt;VertexPosCol&gt; vertices = new List&lt;VertexPosCol&gt;(vcount); for (int i = 0; i &lt; vcount; ++i) { currentLine = reader.ReadLine(); extractedLine = currentLine.Substring(currentLine.IndexOf("\t") + 1); positions = extractedLine.Split(' '); // We only use the first 3, the last 3 are normals which are not used. vertices.Add(new VertexPosCol( new Vector3(float.Parse(positions[0]), float.Parse(positions[1]), float.Parse(positions[2])), Color.Black) ); } BufferDescription vbd = new BufferDescription(); vbd.Usage = ResourceUsage.Immutable; vbd.SizeInBytes = Utilities.SizeOf&lt;VertexPosCol&gt;() * vcount; vbd.BindFlags = BindFlags.VertexBuffer; vbd.StructureByteStride = 0; _vBuffer = Buffer.Create(d3dDevice, vertices.ToArray(), vbd); // Create the index buffer // Skip over the next 3 lines (these are not the lines we are looking for) currentLine = reader.ReadLine(); currentLine = reader.ReadLine(); currentLine = reader.ReadLine(); string[] indexes = new string[6]; _meshIndexCount = 3 * tcount; List&lt;int&gt; indices = new List&lt;int&gt;(_meshIndexCount); for (int i = 0; i &lt; tcount; ++i) { currentLine = reader.ReadLine(); extractedLine = currentLine.Substring(currentLine.IndexOf("\t") + 1); indexes = extractedLine.Split(' '); indices.Add(int.Parse(indexes[0])); indices.Add(int.Parse(indexes[1])); indices.Add(int.Parse(indexes[2])); } BufferDescription ibd = new BufferDescription(); ibd.Usage = ResourceUsage.Immutable; ibd.SizeInBytes = Utilities.SizeOf&lt;int&gt;() * _meshIndexCount; ibd.BindFlags = BindFlags.IndexBuffer; _iBuffer = Buffer.Create(d3dDevice, indices.ToArray(), ibd); } fs.Close(); } </code></pre> <p>As always is someone sees a problem with the code or a better way of doing something I am always open to ideas.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload