Boilerplate Code - jopo86/onyx GitHub Wiki
Onyx - Boilerplate Code
If you're starting a new project using Onyx, it can be easy to forget some necessary parts of the boilerplate code, so I've provided it all right here. Obviously you can change many parts about this code, and the parts commented out are simply optional parts.
#include <Onyx/Core.h>
#include <Onyx/Window.h>
#include <Onyx/InputHandler.h>
#include <Onyx/Math.h>
using Onyx::Math::Vec3;
int main()
{
Onyx::ErrorHandler errorHandler(true, true);
Onyx::Init(errorHandler);
Onyx::Window window(
Onyx::WindowProperties{
.title = "Onyx Window",
.width = 1280,
.height = 720
}
);
window.init();
Onyx::InputHandler input;
window.linkInputHandler(input);
Onyx::Camera cam(Onyx::Projection::Perspective(60.0f, 1280, 720) /* or Onyx::Projection::Orthographic(1280, 720) */);
window.linkCamera(cam);
// Onyx::Lighting lighting(Vec3::White(), 0.3f, Vec3(0.2f, -1.0f, -0.3f));
// Onyx::Fog fog(window.getBackgroundColor(), 10.0f, 20.0f);
Onyx::Renderer renderer(cam/*, lighting, fog*/);
window.linkRenderer(renderer);
// Create & Add Renderables
while (window.isOpen())
{
input.update();
// Handle Input
// Handle Camera Transformations (probably included in input handling)
cam.update();
// Handle any Logic/Transformations
window.startRender();
renderer.render();
window.endRender();
}
window.dispose();
renderer.dispose();
// Dispose any other disposables created (not including renderables that were added to the renderer, these are disposed automatically)
Onyx::Terminate();
return 0;
}