Abstraction over modern OpenGL.
It tries to hide the ugliness of the global state machine that is OpenGL.
It is a little cumbersome, but bare with me.
Create two projects
YourProjectas a console projectYourProject.Assetsas a class library project (your IDE might have created aClass1.csfile, you can delete that safely)
- Add
YourProject.Assetsas a project reference toYourProject. - Copy
Fontsdirectory from here intoYourProject.Assets(i am working on a neater solution) - Add
EngineKittoYourProjectvia nuget as a usual package. - We also need a few other packages:
Microsoft.Extensions.Configuration- handle configuration in generalMicrosoft.Extensions.Configuration.Json- to load appsettings.jsonMicrosoft.Extensions.Options.ConfigurationExtensions- to turn sections of the configuration into usable objectsMicrosoft.Extensions.DependencyInjection- that's the dependency injection container we use hereSerilog.Sinks.Console- to print log statement to the consoleSerilog.Settings.Configuration- an adapter for serilog to get its configuration from our configuration object
- Create an
appsettings.jsoninYourProjectwhich should like like this one. - Make sure to have it copied when its newer by right clicking it -> Properties -> "Copy to output directory" -> "Copy if newer"
- Create a class
YourProjectApplicationinYourProjectand let it derive fromGraphicsApplication(let your IDE implement the constructor, if you cannot figure it out look at this constructor for inspiration) Program.csofYourProjectshould look like
using EngineKit;
using EngineKit.Extensions;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Serilog;
namespace YourProject;
internal static class Program
{
public static void Main(string[] args)
{
using var serviceProvider = CreateServiceProvider();
var application = serviceProvider.GetRequiredService<IApplication>();
application.Run();
}
private static ServiceProvider CreateServiceProvider()
{
var configuration = new ConfigurationBuilder()
.AddJsonFile("appsettings.json", false)
.Build();
Log.Logger = new LoggerConfiguration()
.ReadFrom.Configuration(configuration)
.CreateLogger();
var services = new ServiceCollection();
services.AddSingleton(configuration);
services.AddSingleton(Log.Logger);
services.Configure<WindowSettings>(configuration.GetSection(nameof(WindowSettings)));
services.Configure<ContextSettings>(configuration.GetSection(nameof(ContextSettings)));
services.AddEngine();
services.AddSingleton<IApplication, XXX>(); // replace XXX with YourProjectApplication
return services.BuildServiceProvider();
}
}- Run it.
- You should get a black window which you cannot close :)
- For that you can implement
YourProjectApplication'sUpdatemethod via
protected override void Update(float deltaTime)
{
base.Update(deltaTime);
if (IsKeyPressed(Glfw.Key.KeyEscape))
{
Close();
}
}TODO Complex Example