flopoloco's picture

VBO: How to draw a simple point

using System;
using System.Drawing;
using OpenTK;
using OpenTK.Graphics;
using OpenTK.Graphics.OpenGL;
 
namespace OpenTKGL3Dot
{
	class Program : GameWindow
	{
		int vbo;
 
		void CreateVertexBuffer()
		{
			Vector3[] vertices = new Vector3[1];
			vertices[0] = new Vector3(0f, 0f, 0f);
			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(Color.Brown);
			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);
			}
		}
	}
}
Inline Images