public void UpdateIndexBuffer(List <uint> indices) { CountIndices = indices.Count; GL.BindBuffer(BufferTarget.ElementArrayBuffer, IndexBuffer); GL.BufferData(BufferTarget.ElementArrayBuffer, (IntPtr)(CountIndices * sizeof(uint)), indices.ToArray(), BufferUsageHint.DynamicDraw); OpenGlHelper.CheckErrors(); }
public void GenerateSphere(float radius, int rings, int sectors) { Destroy(); float R = 1.0f / (rings - 1); float S = 1.0f / (sectors - 1); Vertices = new Vertex3d[rings * sectors]; int index = 0; for (int r = 0; r < rings; r++) { for (int s = 0; s < sectors; s++) { float x = (float)(Math.Cos(2.0 * Math.PI * s * S) * Math.Sin(Math.PI * r * R)); float y = (float)(Math.Sin(2.0 * Math.PI * s * S) * Math.Sin(Math.PI * r * R)); float z = (float)Math.Cos(Math.PI * r * R); var vertex = new Vertex3d(); vertex.TexCoord.X = s * S; vertex.TexCoord.Y = r * R; vertex.Position.X = x * radius; vertex.Position.Y = y * radius; vertex.Position.Z = z * radius; vertex.Normal.X = x; vertex.Normal.X = y; vertex.Normal.X = z; vertex.Color = new Vector4(1.0f, 0.0f, 0.0f, 1.0f); Vertices[index++] = vertex; } } index = 0; for (int r = 0; r < rings; r++) { for (int s = 0; s < sectors; s++) { Indices.Add((uint)(r * sectors + s)); Indices.Add((uint)(r * sectors + (s + 1))); Indices.Add((uint)((r + 1) * sectors + (s + 1))); Indices.Add((uint)((r + 1) * sectors + s)); } } GL.GenBuffers(1, out VertexBuffer); GL.GenBuffers(1, out IndexBuffer); GL.BindBuffer(BufferTarget.ArrayBuffer, VertexBuffer); GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(Vertices.Length * Vertex3d.Stride), Vertices, BufferUsageHint.StreamDraw); OpenGlHelper.CheckErrors(); GL.BindBuffer(BufferTarget.ElementArrayBuffer, IndexBuffer); GL.BufferData(BufferTarget.ElementArrayBuffer, (IntPtr)(Indices.Count * sizeof(uint)), Indices.ToArray(), BufferUsageHint.DynamicDraw); OpenGlHelper.CheckErrors(); }
private void UpdateVertexBuffer() { GL.BindBuffer(BufferTarget.ArrayBuffer, VertexBuffer); GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(Vertices.Length * Vertex3d.Stride), Vertices, BufferUsageHint.StreamDraw); OpenGlHelper.CheckErrors(); }