Skip to content

GLFW 3 Minimal application example

Antonie Blom edited this page Nov 15, 2013 · 3 revisions
using System;
using Pencil.Gaming;
using Pencil.Gaming.Graphics;

class MainClass
{
	public static void Main(string[] args)
	{
		// Initialize GLFW system
		Glfw.Init();

		// Create GLFW window
		GlfwWindowPtr window = Glfw.CreateWindow(800, 600, "", GlfwMonitorPtr.Null, GlfwWindowPtr.Null);

		// Enable the OpenGL context for the current window
		Glfw.MakeContextCurrent(window);

		while (!Glfw.WindowShouldClose(window))
		{
			// Poll GLFW window events
			Glfw.PollEvents();

			// If you press escape the window will close
			if (Glfw.GetKey(window, Key.Escape))
			{
				Glfw.SetWindowShouldClose(window, true);
			}

			// Set OpenGL clear colour to red
			GL.ClearColor(Color4.Red);

			// Clear the screen
			GL.Clear(ClearBufferMask.ColorBufferBit);

			// Swap the front and back buffer, displaying the scene
			Glfw.SwapBuffers(window);
		}

		// Finally, clean up Glfw, and close the window
		Glfw.Terminate();
	}
}
Clone this wiki locally