110 lines
3.0 KiB
C#
110 lines
3.0 KiB
C#
using Firebird2D.Datatypes;
|
|
using Firebird2D.DataypesAndInterfaces.Datatypes;
|
|
using Firebird2D.DataypesAndInterfaces.EventArguments;
|
|
using Firebird2D.DataypesAndInterfaces.Interfaces;
|
|
using Firebird2D.Interfaces;
|
|
using Firebird2D.Interfaces.Actors;
|
|
using Firebird2D.Rendering;
|
|
using Firebird2D.SceneSystem;
|
|
using Silk.NET.Input;
|
|
using Silk.NET.Maths;
|
|
using Silk.NET.OpenGL;
|
|
using Silk.NET.Windowing;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Numerics;
|
|
using System.Security.Cryptography.X509Certificates;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Firebird2D.Core
|
|
{
|
|
public class MainWindow
|
|
{
|
|
private IWindow renderWindow;
|
|
|
|
private IInputContext _inputContext;
|
|
|
|
private IKeyboard _keyboard;
|
|
|
|
private GL _gl;
|
|
|
|
private FirebirdShader _shader;
|
|
|
|
private Matrix4x4 _projection;
|
|
|
|
internal I_Scene? ActiveScene { set; get; }
|
|
|
|
private IEventBus eventBus;
|
|
|
|
private IKeyMapper keyMapper;
|
|
|
|
private IPipeline<FirebirdTickArgs> tickPipeline;
|
|
|
|
public MainWindow(Game game)
|
|
{
|
|
eventBus = game.EventBus;
|
|
keyMapper = game.KeyMapper;
|
|
}
|
|
|
|
public void Run()
|
|
{
|
|
WindowOptions opts = WindowOptions.Default;
|
|
opts.Size = new Silk.NET.Maths.Vector2D<int>(800, 600);
|
|
opts.Title = "Testtitle"; // TODO Title einstellbar
|
|
tickPipeline = eventBus.GetOrBuildPipeline<FirebirdTickArgs>(FirebirdSystemEventIds.Tick, this);
|
|
|
|
renderWindow = Window.Create(opts);
|
|
|
|
renderWindow.Load += OnLoad;
|
|
renderWindow.Render += OnRender;
|
|
renderWindow.Update += OnUpdate;
|
|
renderWindow.FramebufferResize += OnResize;
|
|
renderWindow.Run();
|
|
}
|
|
|
|
private void OnResize(Vector2D<int> newSize)
|
|
{
|
|
_projection = Matrix4x4.CreateOrthographicOffCenter(0, newSize.X, newSize.Y, 0, -1, 1);
|
|
}
|
|
|
|
private void OnUpdate(double dt)
|
|
{
|
|
tickPipeline.SendEvent(this,new FirebirdTickArgs(dt,_shader,_projection));
|
|
if (ActiveScene != null)
|
|
{
|
|
ActiveScene.TickScene(dt);
|
|
}
|
|
}
|
|
|
|
private void OnRender(double dt)
|
|
{
|
|
_gl.Clear(ClearBufferMask.ColorBufferBit);
|
|
|
|
_shader.Use();
|
|
_shader.SetMatrix4("projection", _projection);
|
|
|
|
if (ActiveScene != null)
|
|
{
|
|
ActiveScene.RenderScene(_projection, _shader, dt);
|
|
}
|
|
}
|
|
|
|
private void OnLoad()
|
|
{
|
|
_gl = GL.GetApi(renderWindow);
|
|
|
|
_gl.ClearColor(0.1f,0.1f,0.1f,1.0f);
|
|
_gl.Enable(GLEnum.Blend);
|
|
_gl.BlendFunc(GLEnum.SrcAlpha, GLEnum.OneMinusSrcAlpha);
|
|
|
|
_shader = new FirebirdShader(_gl, "shaders/vertex.glsl", "shaders/fragment.glsl");
|
|
|
|
_projection = Matrix4x4.CreateOrthographicOffCenter(0, renderWindow.Size.X, renderWindow.Size.Y, 0, -1, 1);
|
|
|
|
|
|
}
|
|
}
|
|
}
|