I wrote an N-body code in C# which outputs an array with x,y,z positions of N objects. I want to render it on a screen frame by frame using OpenTK.
Basically, I need to figure out how to create an array of vertices using VBO-s, show it on a screen, and update it periodically. Since I have zero experience in graphics, I tried to modify an example I found on the web, it works for one vertex but not an array.
Here's the code:
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
using System.Threading;
using OpenTK;
using OpenTK.Graphics.OpenGL;
using OpenTK.Platform;
using System.Drawing;
namespace OpenTK
{
class Program : GameWindow
{
int vbo;
void CreateVertexBuffer()
{
Vector3[] vertices = new Vector3[2];
vertices[0] = new Vector3(0f, 0f, 0f);
vertices[1] = new Vector3(1f, 7f, 6f);
GL.GenBuffers(1, out vbo);
GL.BindBuffer(BufferTarget.ArrayBuffer, vbo);
GL.BufferData<Vector3>(BufferTarget.ArrayBuffer,
new IntPtr(vertices.Length * Vector3.SizeInBytes),
vertices, BufferUsageHint.StaticDraw);
}
protected override void OnLoad(EventArgs e)
{
GL.ClearColor(0,0,0,0);
GL.PointSize(5f);
CreateVertexBuffer();
}
protected override void OnRenderFrame(FrameEventArgs e)
{
GL.Clear(ClearBufferMask.ColorBufferBit);
GL.EnableVertexAttribArray(0);
GL.BindBuffer(BufferTarget.ArrayBuffer, vbo);
GL.VertexAttribPointer(0, 3, VertexAttribPointerType.Float, false, 0, 0);
GL.DrawArrays(BeginMode.Points, 0, 1);
GL.DisableVertexAttribArray(0);
SwapBuffers();
}
public static void Main(string[] args)
{
using (Program p = new Program())
{
p.Run(60);
}
}
}
}