-
Notifications
You must be signed in to change notification settings - Fork 21
Getting Started
This guide will show you how to quickly set up a simple Application using Foster
- Clone the Foster repo
- Install dotnet core 3.1
- Create a new dotnet core console application in an adjacent folder to the Foster repo
- Add Foster Framework (
Foster/Framework/Foster.Framework.csproj
) as a dependency, along with the Platform Modules you intend to use.
By default, a good System and Graphics Module are GLFW and OpenGL (as of writing, these are the only 2 full implementations)
Foster/Platforms/GLFW/Foster.GLFW.csrpoj
Foster/Platforms/OpenGL/Foster.OpenGL.csproj
Once you've created a new dotnet core project, you can create a simple Application. Foster requires you to first register the Platform Modules you intend to use before launching. A simple Main method looks like this:
static void Main(string[] args)
{
// our System Module (this is Mandatory)
App.Modules.Register<GLFW_System>();
// our Graphics Module (not Mandatory but required for drawing anything)
App.Modules.Register<GL_Graphics>();
// start the Application with a single 1280x720 Window
App.Start("My Application", 1280, 720);
}
At this point if you run your project you should see a blank Window.
To run your own code, you need to register a custom Module. A Module gets callbacks for all the main system events, like Startup, Update, Render, and Shutdown.
A simple Module that draws a Rectangle to the screen with the Batch2D class looks like this:
public class CustomModule : Module
{
public readonly Batch2D Batcher = new Batch2D();
public float Offset = 0f;
// This is called when the Application has Started
protected override void Startup()
{
// Add a Callback to the primary window's Render loop
App.Window.OnRender += Render;
}
// This is called when the Application is shutting down, or when the Module is removed
protected override void Shutdown()
{
// Remove our Callback
App.Window.OnRender -= Render;
}
// This is called every frame of the Application
protected override void Update()
{
Offset += 32 * Time.DeltaTime;
}
private void Render(Window window)
{
// clear the batcher from the previous frame
Batcher.Clear();
// draw a rectangle
Batcher.Rect(Offset, 0, 32, 32, Color.Red);
// clear the Window
App.Graphics.Clear(window, Color.Black);
// draw the batcher to the Window
Batcher.Render(window);
}
}
You then need to add your Module before the Application is started. We can do this by modifying our Main method from earlier:
static void Main(string[] args)
{
// our System Module (this is Mandatory)
App.Modules.Register<GLFW_System>();
// our Graphics Module (not Mandatory but required for drawing anything)
App.Modules.Register<GL_Graphics>();
// our custom module
App.Modules.Register<CustomModule>();
// start the Application with a single 1280x720 Window
App.Start("My Application", 1280, 720);
}
At this point if you run the Application you should now see a red Rectangle that slowly moves across the screen!
Guides
API
Examples