17.01.2021

+ WPF-Support
+ Game Controller System
+ GameKeybind System

+ SM_WPF_TEST
This commit is contained in:
Michel Fedde 2021-01-17 21:13:37 +01:00
parent af90d617d3
commit 6f23a80f7f
60 changed files with 1536 additions and 143 deletions

View file

@ -12,7 +12,7 @@ namespace SM.Base.Controls
/// </summary>
/// <typeparam name="TWindow">The type of window this controller is connected to.</typeparam>
public class Mouse<TWindow>
where TWindow : GenericWindow
where TWindow : IGenericWindow
{
/// <summary>
/// The window it is connected to.

View file

@ -34,8 +34,19 @@
<LangVersion>latest</LangVersion>
</PropertyGroup>
<ItemGroup>
<Reference Include="OpenTK, Version=3.2.1.0, Culture=neutral, PublicKeyToken=bad199fe84eb3df4, processorArchitecture=MSIL">
<HintPath>..\..\packages\OpenTK.3.2.1\lib\net20\OpenTK.dll</HintPath>
<Reference Include="GLWpfControl, Version=3.2.3.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\packages\OpenTK.GLWpfControl.3.2.3\lib\net452\GLWpfControl.dll</HintPath>
</Reference>
<Reference Include="OpenTK, Version=3.3.1.0, Culture=neutral, PublicKeyToken=bad199fe84eb3df4, processorArchitecture=MSIL">
<HintPath>..\..\packages\OpenTK.3.3.1\lib\net20\OpenTK.dll</HintPath>
</Reference>
<Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" />
<Reference Include="SharpDX, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b4dcf0f35e5521f1, processorArchitecture=MSIL">
<HintPath>..\..\packages\SharpDX.4.2.0\lib\net45\SharpDX.dll</HintPath>
</Reference>
<Reference Include="SharpDX.XInput, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b4dcf0f35e5521f1, processorArchitecture=MSIL">
<HintPath>..\..\packages\SharpDX.XInput.4.2.0\lib\net45\SharpDX.XInput.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
@ -43,6 +54,8 @@
<Reference Include="System.IO.Compression" />
<Reference Include="System.IO.Compression.FileSystem" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xaml" />
<Reference Include="WindowsBase" />
</ItemGroup>
<ItemGroup>
<Compile Include="Controls\Mouse.cs" />
@ -92,6 +105,9 @@
<Compile Include="Scene\GenericCamera.cs" />
<Compile Include="Scene\GenericScene.cs" />
<Compile Include="Objects\Static\Plate.cs" />
<Compile Include="Window\GenericWindowCode.cs" />
<Compile Include="Window\GenericWPFWindow.cs" />
<Compile Include="Window\IGenericWindow.cs" />
<Compile Include="Window\RenderPipeline.cs" />
</ItemGroup>
<ItemGroup>
@ -112,10 +128,12 @@
<EmbeddedResource Include="PostProcess\DefaultFiles\vertexWithExt.vert" />
</ItemGroup>
<ItemGroup>
<None Include="OpenTK.dll.config" />
<None Include="packages.config" />
<EmbeddedResource Include="PostEffects\Shaders\bloom_blur.glsl" />
<EmbeddedResource Include="PostEffects\Shaders\bloom_merge.glsl" />
</ItemGroup>
<ItemGroup>
<None Include="OpenTK.dll.config" />
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

View file

@ -55,6 +55,6 @@ namespace SM.Base
/// <summary>
/// Represents the current active window.
/// </summary>
public static GenericWindow CurrentWindow { get; internal set; }
public static IGenericWindow CurrentWindow { get; internal set; }
}
}

View file

@ -89,7 +89,7 @@ namespace SM.Base.Scene
return (T)ext;
}
/// <summary>
/// Called, when the user activates the scene.
/// </summary>
@ -178,7 +178,6 @@ namespace SM.Base.Scene
}
}
/// <inheritdoc />
public override void Update(UpdateContext context)
{

View file

@ -52,6 +52,8 @@ namespace SM.Base.Time
/// </summary>
public TimeSpan ElapsedSpan { get; protected set; }
public event Action<Stopwatch, UpdateContext> Tick;
/// <summary>
/// Starts the stopwatch.
/// </summary>
@ -69,10 +71,12 @@ namespace SM.Base.Time
/// Performs a tick.
/// </summary>
/// <param name="context"></param>
private protected virtual void Tick(UpdateContext context)
private protected virtual void Ticking(UpdateContext context)
{
Elapsed += context.Deltatime;
ElapsedSpan = TimeSpan.FromSeconds(Elapsed);
Tick?.Invoke(this, context);
}
/// <summary>
@ -115,7 +119,7 @@ namespace SM.Base.Time
for (var i = 0; i < _activeStopwatches.Count; i++)
{
if (_activeStopwatches[i].Paused) continue;
_activeStopwatches[i].Tick(context);
_activeStopwatches[i].Ticking(context);
}
}
}

View file

@ -1,6 +1,7 @@
#region usings
using System;
using System.Diagnostics.Eventing.Reader;
using SM.Base.Contexts;
#endregion
@ -43,7 +44,7 @@ namespace SM.Base.Time
/// <summary>
/// The event, that is triggered when the timer stops.
/// </summary>
public event Action<Timer, UpdateContext> EndAction;
public event Action<Timer, UpdateContext> End;
/// <inheritdoc />
public override void Start()
@ -52,9 +53,9 @@ namespace SM.Base.Time
Reset();
}
private protected override void Tick(UpdateContext context)
private protected override void Ticking(UpdateContext context)
{
base.Tick(context);
base.Ticking(context);
ElapsedNormalized = Elapsed / Target;
if (ElapsedNormalized >= 1) Stopping(context);
@ -70,12 +71,12 @@ namespace SM.Base.Time
}
/// <summary>
/// This will trigger <see cref="EndAction" />
/// This will trigger <see cref="End" />
/// </summary>
/// <param name="context"></param>
protected void TriggerEndAction(UpdateContext context)
{
EndAction?.Invoke(this, context);
End?.Invoke(this, context);
}
}
}

View file

@ -18,7 +18,7 @@ namespace SM.Utility
/// <returns></returns>
public static float TurnTowards(Vector2 origin, Vector2 target)
{
return MathHelper.RadiansToDegrees((float) Math.Atan2(target.Y - origin.Y, target.X - origin.X));
return MathHelper.RadiansToDegrees((float) Math.Atan2(origin.X - target.X, target.Y - origin.Y));
}
}
}

View file

@ -27,11 +27,11 @@ namespace SM.Base.Contexts
public RenderPipeline ActivePipeline;
public GenericScene ActiveScene;
public GenericWindow Window;
public IGenericWindow Window;
public GenericCamera UsedCamera =>
ForceViewport || ActiveScene._camera == null ? Window._viewportCamera : ActiveScene._camera;
ForceViewport || ActiveScene._camera == null ? Window.ViewportCamera : ActiveScene._camera;

View file

@ -1,6 +1,7 @@
#region usings
using OpenTK.Input;
using SM.Base.Scene;
#endregion
@ -25,5 +26,7 @@ namespace SM.Base.Contexts
/// The current mouse state.
/// </summary>
public MouseState MouseState;
public GenericScene CurrentScene;
}
}

View file

@ -0,0 +1,109 @@
using System;
using System.Drawing;
using System.Windows;
using System.Windows.Media;
using OpenTK;
using OpenTK.Wpf;
using SM.Base.Scene;
using SM.OGL;
namespace SM.Base
{
public class GenericWPFWindow : OpenTK.Wpf.GLWpfControl, IGenericWindow
{
private bool _renderContinuesly;
protected GenericCamera _viewportCamera;
public bool Loading => !base.IsInitialized;
public float Aspect { get; set; }
public GenericCamera ViewportCamera => _viewportCamera;
public bool ForceViewportCamera { get; set; }
public int Width => (int) base.ActualWidth;
public int Height => (int) base.ActualHeight;
public Rectangle ClientRectangle => new Rectangle((int)base.RenderTransformOrigin.X, (int)RenderTransformOrigin.Y, Width, Height);
public Vector2 WorldScale { get; set; }
public GenericWPFWindow(bool renderContinuesly = false)
{
_renderContinuesly = renderContinuesly;
Ready += Init;
Render += Rendering;
}
protected virtual void Init()
{
GenericWindowCode.Load(this);
}
protected virtual void Rendering(TimeSpan delta)
{
}
protected override void OnRenderSizeChanged(SizeChangedInfo info)
{
base.OnRenderSizeChanged(info);
GenericWindowCode.Resize(this);
}
public void Start()
{
GLWpfControlSettings settings = new GLWpfControlSettings()
{
MajorVersion = GLSettings.ForcedVersion.MajorVersion,
MinorVersion = GLSettings.ForcedVersion.MinorVersion,
RenderContinuously = _renderContinuesly
};
base.Start(settings);
}
public virtual void SetWorldScale()
{ }
}
public class GenericWPFWindow<TScene, TCamera> : GenericWPFWindow, IGenericWindow<TScene, TCamera>
where TScene : GenericScene, new()
where TCamera : GenericCamera, new()
{
private TScene _scene;
private RenderPipeline<TScene> _renderPipeline;
public TScene CurrentScene => _scene;
public RenderPipeline<TScene> RenderPipeline => _renderPipeline;
public GenericWPFWindow(bool renderContinuesly = false) : base(renderContinuesly)
{
_viewportCamera = new TCamera();
}
protected override void Rendering(TimeSpan delta)
{
base.Rendering(delta);
GenericWindowCode.Render(this, (float)delta.TotalSeconds);
}
protected override void OnRenderSizeChanged(SizeChangedInfo info)
{
base.OnRenderSizeChanged(info);
GenericWindowCode.Resize(this);
}
public void SetScene(TScene scene)
{
_scene = scene;
scene.Activate();
RenderPipeline.SceneChanged(scene);
}
public void SetRenderPipeline(RenderPipeline<TScene> renderPipeline)
{
_renderPipeline = renderPipeline;
renderPipeline.Activate(this);
}
}
}

View file

@ -26,20 +26,24 @@ namespace SM.Base
/// <summary>
/// The base window.
/// </summary>
public abstract class GenericWindow : GameWindow
public abstract class GenericWindow : GameWindow, IGenericWindow
{
protected GenericCamera _viewportCamera;
internal bool _loading = true;
internal List<Action> _actionsAfterLoading = new List<Action>();
public bool Loading => _loading;
/// <summary>
/// This tells you the current world scale.
/// </summary>
protected Vector2 _worldScale = Vector2.Zero;
public Vector2 WorldScale { get; set; } = Vector2.Zero;
/// <summary>
/// This tells you the current aspect ratio of this window.
/// </summary>
public float Aspect { get; private set; }
public float Aspect { get; set; }
/// <summary>
/// If false, the window will not react on updates and will not render something.
@ -49,7 +53,8 @@ namespace SM.Base
/// </summary>
public bool ReactWhileUnfocused = false;
internal GenericCamera _viewportCamera;
public GenericCamera ViewportCamera => _viewportCamera;
public bool ForceViewportCamera { get; set; }
/// <inheritdoc />
protected GenericWindow() : this(1280, 720, "Generic OGL Title", GameWindowFlags.Default)
@ -70,33 +75,7 @@ namespace SM.Base
/// <inheritdoc />
protected override void OnLoad(EventArgs e)
{
SMRenderer.CurrentWindow = this;
GLSystem.INIT_SYSTEM();
GLSettings.ShaderPreProcessing = true;
var args = Environment.GetCommandLineArgs();
if (args.Contains("--advDebugging"))
{
SMRenderer.AdvancedDebugging = true;
GLSettings.InfoEveryUniform = true;
}
Log.Init();
Log.Write("#", ConsoleColor.Cyan, "----------------------",
"--- OpenGL Loading ---",
"----------------------------------",
$"--- {"DeviceVersion",14}: {GLSystem.DeviceVersion,-10} ---",
$"--- {"ForcedVersion",14}: {GLSettings.ForcedVersion,-10} ---",
$"--- {"ShadingVersion",14}: {GLSystem.ShadingVersion,-10} ---",
$"--- {"Debugging",14}: {GLSystem.Debugging,-10} ---",
$"--- {"AdvDebugging",14}: {SMRenderer.AdvancedDebugging,-10} ---",
"----------------------------------");
if (SMRenderer.AdvancedDebugging) Log.Write("Extension", ConsoleColor.DarkCyan, GLSystem.Extensions);
ExtensionManager.InitExtensions();
GenericWindowCode.Load(this);
base.OnLoad(e);
}
@ -106,17 +85,14 @@ namespace SM.Base
{
base.OnResize(e);
Aspect = (float) Width / Height;
_worldScale = new Vector2(Width, Height);
SetWorldScale();
GL.Viewport(ClientRectangle);
GenericWindowCode.Resize(this);
if (_loading)
{
_loading = false;
OnLoaded();
_actionsAfterLoading.ForEach(a => a());
_actionsAfterLoading = null;
}
@ -132,7 +108,7 @@ namespace SM.Base
/// <summary>
/// Sets the world scale.
/// </summary>
protected virtual void SetWorldScale()
public virtual void SetWorldScale()
{
}
@ -218,10 +194,13 @@ namespace SM.Base
/// </summary>
/// <typeparam name="TScene">The scene type</typeparam>
/// <typeparam name="TCamera">The camera type</typeparam>
public abstract class GenericWindow<TScene, TCamera> : GenericWindow
public abstract class GenericWindow<TScene, TCamera> : GenericWindow, IGenericWindow<TScene, TCamera>
where TScene : GenericScene, new()
where TCamera : GenericCamera, new()
{
private RenderPipeline<TScene> _renderPipeline;
private TScene _scene;
/// <inheritdoc />
protected GenericWindow()
{
@ -244,17 +223,18 @@ namespace SM.Base
/// <summary>
/// The current scene.
/// </summary>
public TScene CurrentScene { get; private set; }
public TScene CurrentScene => _scene;
/// <summary>
/// Controls how a scene is rendered.
/// </summary>
public RenderPipeline<TScene> RenderPipeline { get; private set; }
public RenderPipeline<TScene> RenderPipeline => _renderPipeline;
/// <inheritdoc />
protected override void Update(FrameEventArgs e, ref UpdateContext context)
{
base.Update(e, ref context);
context.CurrentScene = CurrentScene;
CurrentScene?.Update(context);
}
@ -263,37 +243,9 @@ namespace SM.Base
{
if (!ReactWhileUnfocused && !Focused) return;
if (CurrentScene == null) return;
SMRenderer.CurrentFrame++;
Deltatime.RenderDelta = (float) e.Time;
var drawContext = new DrawContext
{
ForceViewport = ForceViewportCamera,
ActiveScene = CurrentScene,
Window = this,
Instances = new[]
{
new Instance
{ModelMatrix = Matrix4.Identity, TexturePosition = Vector2.Zero, TextureScale = Vector2.One}
},
Mesh = Plate.Object,
WorldScale = _worldScale,
LastPassthough = this,
ShaderArguments = new Dictionary<string, object>(),
World = ViewportCamera.World,
View = ViewportCamera.CalculateViewMatrix(),
ModelMaster = Matrix4.Identity
};
base.OnRenderFrame(e);
RenderPipeline.Render(ref drawContext);
GenericWindowCode.Render(this, (float)e.Time);
SwapBuffers();
@ -305,13 +257,7 @@ namespace SM.Base
{
base.OnResize(e);
ViewportCamera.RecalculateWorld(_worldScale, Aspect);
RenderPipeline.Resize();
PostProcessEffect.Model = Matrix4.CreateScale(_worldScale.X, -_worldScale.Y, 1);
PostProcessEffect.Mvp = PostProcessEffect.Model *
Matrix4.LookAt(0, 0, 1, 0, 0, 0, 0, 1, 0) *
GenericCamera.OrthographicWorld;
GenericWindowCode.Resize(this);
}
/// <summary>
@ -326,7 +272,7 @@ namespace SM.Base
return;
}
CurrentScene = scene;
_scene = scene;
scene.Activate();
RenderPipeline.SceneChanged(scene);
}
@ -343,7 +289,7 @@ namespace SM.Base
return;
}
RenderPipeline = pipeline;
_renderPipeline = pipeline;
pipeline.Activate(this);
}
}

View file

@ -0,0 +1,107 @@
using System;
using System.Collections.Generic;
using System.Linq;
using OpenTK;
using OpenTK.Graphics.OpenGL4;
using SM.Base.Contexts;
using SM.Base.Drawing;
using SM.Base.Objects.Static;
using SM.Base.PostProcess;
using SM.Base.Scene;
using SM.Base.ShaderExtension;
using SM.OGL;
using SM.Utility;
namespace SM.Base
{
public class GenericWindowCode
{
internal static void Load(IGenericWindow window)
{
SMRenderer.CurrentWindow = window;
GLSystem.INIT_SYSTEM();
GLSettings.ShaderPreProcessing = true;
var args = Environment.GetCommandLineArgs();
if (args.Contains("--advDebugging"))
{
SMRenderer.AdvancedDebugging = true;
GLSettings.InfoEveryUniform = true;
}
Log.Init();
Log.Write("#", ConsoleColor.Cyan, "----------------------",
"--- OpenGL Loading ---",
"----------------------------------",
$"--- {"DeviceVersion",14}: {GLSystem.DeviceVersion,-10} ---",
$"--- {"ForcedVersion",14}: {GLSettings.ForcedVersion,-10} ---",
$"--- {"ShadingVersion",14}: {GLSystem.ShadingVersion,-10} ---",
$"--- {"Debugging",14}: {GLSystem.Debugging,-10} ---",
$"--- {"AdvDebugging",14}: {SMRenderer.AdvancedDebugging,-10} ---",
"----------------------------------");
if (SMRenderer.AdvancedDebugging) Log.Write("Extension", ConsoleColor.DarkCyan, GLSystem.Extensions);
ExtensionManager.InitExtensions();
}
internal static void Resize(IGenericWindow window)
{
window.Aspect = (float) window.Width / window.Height;
window.WorldScale = new Vector2(window.Width, window.Height);
window.SetWorldScale();
GL.Viewport(window.ClientRectangle);
}
internal static void Resize<TScene, TCamera>(IGenericWindow<TScene, TCamera> window)
where TScene : GenericScene, new()
where TCamera : GenericCamera, new()
{
window.ViewportCamera.RecalculateWorld(window.WorldScale, window.Aspect);
window.RenderPipeline.Resize();
PostProcessEffect.Model = Matrix4.CreateScale(window.WorldScale.X, -window.WorldScale.Y, 1);
PostProcessEffect.Mvp = PostProcessEffect.Model *
Matrix4.LookAt(0, 0, 1, 0, 0, 0, 0, 1, 0) *
GenericCamera.OrthographicWorld;
}
internal static void Render<TScene, TCamera>(IGenericWindow<TScene, TCamera> window, float deltatime)
where TScene : GenericScene, new()
where TCamera : GenericCamera, new()
{
if (window.CurrentScene == null) return;
SMRenderer.CurrentFrame++;
Deltatime.RenderDelta = deltatime;
var drawContext = new DrawContext
{
ForceViewport = window.ForceViewportCamera,
ActiveScene = window.CurrentScene,
Window = window,
Instances = new[]
{
new Instance
{ModelMatrix = Matrix4.Identity, TexturePosition = Vector2.Zero, TextureScale = Vector2.One}
},
Mesh = Plate.Object,
WorldScale = window.WorldScale,
LastPassthough = window,
ShaderArguments = new Dictionary<string, object>(),
World = window.ViewportCamera.World,
View = window.ViewportCamera.CalculateViewMatrix(),
ModelMaster = Matrix4.Identity
};
window.RenderPipeline?.Render(ref drawContext);
}
}
}

View file

@ -0,0 +1,37 @@
using System.Drawing;
using System.Windows;
using OpenTK;
using SM.Base.Scene;
using SM.OGL.Framebuffer;
namespace SM.Base
{
public interface IGenericWindow : IFramebufferWindow
{
bool Loading { get; }
float Aspect { get; set; }
GenericCamera ViewportCamera { get; }
bool ForceViewportCamera { get; set; }
int Width { get; }
int Height { get; }
Rectangle ClientRectangle { get; }
Vector2 WorldScale { get; set; }
void SetWorldScale();
}
public interface IGenericWindow<TScene, TCamera> : IGenericWindow
where TScene : GenericScene, new()
where TCamera : GenericCamera, new()
{
TScene CurrentScene { get; }
RenderPipeline<TScene> RenderPipeline { get; }
void SetScene(TScene scene);
void SetRenderPipeline(RenderPipeline<TScene> renderPipeline);
}
}

View file

@ -24,7 +24,7 @@ namespace SM.Base
/// <summary>
/// The window the pipeline is connected to.
/// </summary>
protected GenericWindow _window { get; private set; }
protected IGenericWindow _window { get; private set; }
/// <summary>
/// The framebuffers, that are used in this Pipeline.
@ -63,7 +63,7 @@ namespace SM.Base
}
}
internal void Activate(GenericWindow window)
internal void Activate(IGenericWindow window)
{
_window = window;
@ -85,7 +85,7 @@ namespace SM.Base
/// <summary>
/// Occurs, when the pipeline was connected to a window.
/// </summary>
protected internal virtual void Activation(GenericWindow window)
protected internal virtual void Activation(IGenericWindow window)
{
}
@ -94,7 +94,7 @@ namespace SM.Base
/// Occurs, when the pipeline was connected to a window the first time.
/// </summary>
/// <param name="window"></param>
protected internal virtual void Initialization(GenericWindow window)
protected internal virtual void Initialization(IGenericWindow window)
{
}
@ -131,6 +131,7 @@ namespace SM.Base
internal void Render(ref DrawContext context)
{
context.ActivePipeline = this;
if (context.ActiveScene == null) return;
RenderProcess(ref context, (TScene)context.ActiveScene);
}

View file

@ -1,4 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="OpenTK" version="3.2.1" targetFramework="net452" />
<package id="OpenTK" version="3.3.1" targetFramework="net452" />
<package id="OpenTK.GLWpfControl" version="3.2.3" targetFramework="net452" />
<package id="SharpDX" version="4.2.0" targetFramework="net452" />
<package id="SharpDX.XInput" version="4.2.0" targetFramework="net452" />
</packages>

View file

@ -25,7 +25,7 @@ namespace SM.OGL.Framebuffer
private bool _canBeCompiled = true;
private INativeWindow _window;
private IFramebufferWindow _window;
private float _windowScale;
/// <summary>
@ -40,7 +40,7 @@ namespace SM.OGL.Framebuffer
/// </summary>
/// <param name="window"></param>
/// <param name="scale"></param>
public Framebuffer(INativeWindow window, float scale = 1) : this(new Vector2(window.Width * scale,
public Framebuffer(IFramebufferWindow window, float scale = 1) : this(new Vector2(window.Width * scale,
window.Height * scale))
{
_window = window;

View file

@ -0,0 +1,8 @@
namespace SM.OGL.Framebuffer
{
public interface IFramebufferWindow
{
int Width { get; }
int Height { get; }
}
}

View file

@ -34,8 +34,8 @@
<LangVersion>latest</LangVersion>
</PropertyGroup>
<ItemGroup>
<Reference Include="OpenTK, Version=3.2.1.0, Culture=neutral, PublicKeyToken=bad199fe84eb3df4, processorArchitecture=MSIL">
<HintPath>..\..\packages\OpenTK.3.2.1\lib\net20\OpenTK.dll</HintPath>
<Reference Include="OpenTK, Version=3.3.1.0, Culture=neutral, PublicKeyToken=bad199fe84eb3df4, processorArchitecture=MSIL">
<HintPath>..\..\packages\OpenTK.3.3.1\lib\net20\OpenTK.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
@ -43,6 +43,7 @@
<ItemGroup>
<Compile Include="Framebuffer\ColorAttachment.cs" />
<Compile Include="Framebuffer\Framebuffer.cs" />
<Compile Include="Framebuffer\IFramebufferWindow.cs" />
<Compile Include="GLCustomActions.cs" />
<Compile Include="GLDebugging.cs" />
<Compile Include="GLObject.cs" />
@ -71,5 +72,8 @@
<None Include="OpenTK.dll.config" />
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<Folder Include="GL\" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

View file

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="OpenTK" version="3.2.1" targetFramework="net452" />
<package id="OpenTK" version="3.3.1" targetFramework="net452" />
</packages>

View file

@ -10,9 +10,9 @@ using SM2D.Types;
namespace SM2D.Controls
{
public class Mouse2D : Mouse<GLWindow2D>
public class Mouse2D : Mouse<IGLWindow2D>
{
protected internal Mouse2D(GLWindow2D window) : base(window)
protected internal Mouse2D(IGLWindow2D window) : base(window)
{
}

View file

@ -22,7 +22,7 @@ namespace SM2D.Pipelines
}
protected override void Initialization(GenericWindow window)
protected override void Initialization(IGenericWindow window)
{
MainFramebuffer = CreateWindowFramebuffer();
}
@ -31,13 +31,10 @@ namespace SM2D.Pipelines
{
if (scene != null)
{
MainFramebuffer.Activate(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
scene.DrawBackground(context);
scene.DrawMainObjects(context);
Framebuffer.Screen.Activate();
scene.DrawHUD(context);
scene.DrawDebug(context);
}

View file

@ -31,12 +31,13 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="OpenTK, Version=3.2.1.0, Culture=neutral, PublicKeyToken=bad199fe84eb3df4, processorArchitecture=MSIL">
<HintPath>..\..\packages\OpenTK.3.2.1\lib\net20\OpenTK.dll</HintPath>
</Reference>
<Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" />
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Drawing" />
<Reference Include="System.Xaml" />
<Reference Include="WindowsBase" />
</ItemGroup>
<ItemGroup>
<Compile Include="Controls\Mouse2D.cs" />
@ -44,7 +45,8 @@
<Compile Include="Drawing\DrawObject2D.cs" />
<Compile Include="Drawing\DrawParticles.cs" />
<Compile Include="Drawing\DrawText.cs" />
<Compile Include="GLWindow2D.cs" />
<Compile Include="Window\GLWindow2D.cs" />
<Compile Include="Window\GLWPFWindow2D.cs" />
<Compile Include="Object\Polygon.cs" />
<Compile Include="Object\PolygonVertex.cs" />
<Compile Include="Pipelines\Adv2DPipeline.cs" />
@ -58,6 +60,7 @@
<Compile Include="Shader\Basic2DShader.cs" />
<Compile Include="Shader\Default2DShader.cs" />
<Compile Include="Types\Transformation.cs" />
<Compile Include="Window\IGLWindow2D.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\SM.Base\SM.Base.csproj">
@ -74,11 +77,15 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="OpenTK">
<Version>3.2.1</Version>
<Version>3.3.1</Version>
</PackageReference>
<PackageReference Include="OpenTK.GLWpfControl">
<Version>3.2.3</Version>
</PackageReference>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Shader\ShaderFiles\basic.glsl" />
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

View file

@ -1,2 +1,3 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=light_005Clightobjects/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=light_005Clightobjects/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=window/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>

View file

@ -18,7 +18,6 @@ namespace SM2D.Shader
private Default2DShader() : base(AssemblyUtility.ReadAssemblyFile("SM2D.Shader.ShaderFiles.default.glsl"))
{
Load();
}
protected override void DrawProcess(DrawContext context)

View file

@ -36,7 +36,7 @@ namespace SM2D.Types
{
if (_modelMatrix.Determinant < 0.0001) return new Vector2(0);
var vec = Vector3.TransformNormal(Vector3.UnitX, _modelMatrix);
var vec = Vector3.TransformNormal(Vector3.UnitY, _modelMatrix);
vec.Normalize();
return vec.Xy;
}

View file

@ -0,0 +1,48 @@
using System;
using System.Windows.Media;
using OpenTK;
using OpenTK.Graphics.ES11;
using SM.Base;
using SM2D.Controls;
using SM2D.Pipelines;
using SM2D.Scene;
using SM2D.Shader;
namespace SM2D
{
public class GLWPFWindow2D : GenericWPFWindow<Scene.Scene, Camera>, IGLWindow2D
{
public GLWPFWindow2D()
{
Mouse = new Mouse2D(this);
}
public Vector2? Scaling { get; set; }
public Mouse2D Mouse { get; }
protected override void Init()
{
base.Init();
SMRenderer.DefaultMaterialShader = Default2DShader.MaterialShader;
SetRenderPipeline(Default2DPipeline.Pipeline);
}
protected override void Rendering(TimeSpan delta)
{
GL.Disable(EnableCap.DepthTest);
base.Rendering(delta);
}
public override void SetWorldScale()
{
if (Scaling.HasValue)
{
if (Scaling.Value.X > 0 && Scaling.Value.Y > 0) WorldScale = Scaling.Value;
else if (Scaling.Value.X > 0) WorldScale = new Vector2(Scaling.Value.X, Scaling.Value.X / Aspect);
else if (Scaling.Value.Y > 0) WorldScale = new Vector2(Aspect * Scaling.Value.Y, Scaling.Value.Y);
}
}
}
}

View file

@ -14,7 +14,7 @@ using SM2D.Shader;
namespace SM2D
{
public class GLWindow2D : GenericWindow<Scene.Scene, Camera>
public class GLWindow2D : GenericWindow<Scene.Scene, Camera>, IGLWindow2D
{
public GLWindow2D()
{
@ -22,7 +22,6 @@ namespace SM2D
}
public Vector2? Scaling { get; set; }
public Vector2 WorldScale => _worldScale;
public Mouse2D Mouse { get; }
@ -47,13 +46,13 @@ namespace SM2D
base.OnRenderFrame(e);
}
protected override void SetWorldScale()
public override void SetWorldScale()
{
if (Scaling.HasValue)
{
if (Scaling.Value.X > 0 && Scaling.Value.Y > 0) _worldScale = Scaling.Value;
else if (Scaling.Value.X > 0) _worldScale = new Vector2(Scaling.Value.X, Scaling.Value.X / Aspect);
else if (Scaling.Value.Y > 0) _worldScale = new Vector2(Aspect * Scaling.Value.Y, Scaling.Value.Y);
if (Scaling.Value.X > 0 && Scaling.Value.Y > 0) WorldScale = Scaling.Value;
else if (Scaling.Value.X > 0) WorldScale = new Vector2(Scaling.Value.X, Scaling.Value.X / Aspect);
else if (Scaling.Value.Y > 0) WorldScale = new Vector2(Aspect * Scaling.Value.Y, Scaling.Value.Y);
}
}

View file

@ -0,0 +1,14 @@
using OpenTK;
using SM.Base;
using SM2D.Controls;
using SM2D.Scene;
namespace SM2D
{
public interface IGLWindow2D : IGenericWindow<Scene.Scene, Camera>
{
Vector2? Scaling { get; set; }
Mouse2D Mouse { get; }
}
}