Note that there are some explanatory texts on larger screens.

plurals
  1. PORendering Multiple objects in one scene DirectX C#
    text
    copied!<p>I'm not really not knowledgeable with directX but I will do my best to explain. To start I have multiple Model Objects (custom object with vertex data). At the moment my code (see below) can render a single model in a scene using a vertexBuffer and indexBuffer for that model. What I would like to do is given an array of models. Render them all in a single scene.This is my current code:</p> <pre><code> private void Render() { device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.White, 1.0f, 0); device.BeginScene(); float x = (float)Math.Cos(0); float z = (float)Math.Sin(0); device.Transform.Projection = Matrix.PerspectiveFovLH((float)Math.PI / 4, this.Width / this.Height, 1f, 50f); device.Transform.View = Matrix.LookAtLH(new Vector3(x, 6, z), new Vector3(0, 0, 0), new Vector3(0, 1, 0)); device.RenderState.Lighting = true; device.Lights[0].Type = LightType.Directional; device.Lights[0].Diffuse = Color.White; device.Lights[0].Direction = new Vector3(-x, -6, -z); device.Lights[0].Position = new Vector3(x, 6, z); device.Lights[0].Enabled = true; device.Transform.World = model.transform; device.VertexFormat = CustomVertex.PositionNormalColored.Format; device.SetStreamSource(0, vertexBuffer, 0); device.Indices = indexBuffer; device.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, model.getVertices().Length, 0, model.getIndices().Length / 3); device.EndScene(); device.Present(); } public void RenderModel(Model model) { this.model = model; vertexBuffer = new VertexBuffer(typeof(CustomVertex.PositionNormalColored), model.getVertices().Length, device, Usage.Dynamic | Usage.WriteOnly, CustomVertex.PositionNormalColored.Format, Pool.Default); vertexBuffer.SetData(model.getVertices(), 0, LockFlags.None); indexBuffer = new IndexBuffer(typeof(ushort), model.getIndices().Length, device, Usage.WriteOnly, Pool.Default); indexBuffer.SetData(model.getIndices(), 0, LockFlags.None); Render(); } </code></pre>
 

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