Final source code of Chapter 1, Tutorial 2.
using Silk.NET.Input;
using Silk.NET.Maths;
using Silk.NET.Windowing;
namespace MySilkProgram;
public class Program
{
private static IWindow _window;
public static void Main(string[] args)
{
WindowOptions options = WindowOptions.Default;
options.Size = new Vector2D<int>(800, 600);
options.Title = "My first Silk.NET program!";
_window = Window.Create(options);
_window.Load += OnLoad;
_window.Update += OnUpdate;
_window.Render += OnRender;
_window.Run();
}
private static void OnLoad()
{
Console.WriteLine("Load!");
IInputContext input = _window.CreateInput();
for (int i = 0; i < input.Keyboards.Count; i++)
input.Keyboards[i].KeyDown += KeyDown;
}
// These two methods are unused for this tutorial, aside from the logging we added earlier.
private static void OnUpdate(double deltaTime)
{
Console.WriteLine("Update!");
}
private static void OnRender(double deltaTime)
{
Console.WriteLine("Render!");
}
private static void KeyDown(IKeyboard keyboard, Key key, int keyCode)
{
if (key == Key.Escape)
_window.Close();
}
}
Khronos®, Vulkan® are registered trademarks, and OpenXR™ is a trademark of The Khronos Group Inc. and is registered as a trademark in China, the European Union, Japan and the United Kingdom. OpenCL™, OpenGL®, and the OpenGL ES™ logos are registered trademarks or trademarks used under license by Khronos. Microsoft® and DirectX® are registered trademarks of Microsoft Corporation, used solely for identification. All other product names, trademarks, and/or company names are also used solely for identification and belong to their respective owners. Use of external images, trademarks, and/or resources are not endorsements, and no information in or regarding any of these external resources has been endorsed or approved by Silk.NET or the .NET Foundation.
Powered by Statiq Framework