17.09.2020

+ Generic Scene
+ Generic Camera
+ Generic Window
+ Contexts for drawing and updateing

+ very basic 2D-implermention
This commit is contained in:
Michel Fedde 2020-09-17 21:28:16 +02:00
parent 9889366317
commit 589d131246
25 changed files with 383 additions and 78 deletions

View file

@ -0,0 +1,18 @@
using OpenTK;
using SM.Base.Scene;
using SM.OGL.Mesh;
namespace SM.Base.Contexts
{
public struct DrawContext
{
public bool ForceViewport;
public Matrix4 World;
public Matrix4 View;
public Matrix4 ModelMatrix;
public Mesh Mesh;
}
}

View file

@ -0,0 +1,7 @@
namespace SM.Base.Contexts
{
public struct UpdateContext
{
public double Deltatime;
}
}

View file

@ -0,0 +1,65 @@
using System;
using System.IO;
using OpenTK;
using OpenTK.Graphics;
using OpenTK.Graphics.OpenGL4;
using SM.Base.Contexts;
using SM.Base.Scene;
using SM.Base.StaticObjects;
using SM.OGL.Shaders;
namespace SM.Base
{
public class GenericWindow<TScene, TCamera> : GameWindow
where TScene : GenericScene<TCamera>, new()
where TCamera : GenericCamera, new()
{
private TCamera _viewportCamera;
public TScene CurrentScene { get; private set; }
public bool ForceViewportCamera { get; set; } = false;
public GenericWindow() : base(1280, 720, GraphicsMode.Default, "Testing", GameWindowFlags.Default, DisplayDevice.Default, 0, 0, GraphicsContextFlags.Default, null, true)
{
_viewportCamera = new TCamera();
}
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
}
protected override void OnRenderFrame(FrameEventArgs e)
{
DrawContext drawContext = new DrawContext()
{
World = _viewportCamera.World,
View = _viewportCamera.CalculateViewMatrix(),
ModelMatrix = Matrix4.Identity,
Mesh = Plate.Object,
ForceViewport = ForceViewportCamera
};
base.OnRenderFrame(e);
GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
CurrentScene.Draw(drawContext);
SwapBuffers();
}
protected override void OnResize(EventArgs e)
{
base.OnResize(e);
GL.Viewport(ClientRectangle);
_viewportCamera.RecalculateWorld(Width, Height);
}
public virtual void SetScene(TScene scene)
{
CurrentScene = scene;
}
}
}