Fixed Merge
This commit is contained in:
commit
bb030f588b
65 changed files with 917 additions and 1427 deletions
6
.gitignore
vendored
6
.gitignore
vendored
|
|
@ -10,6 +10,11 @@
|
|||
*.userosscache
|
||||
*.sln.docstates
|
||||
|
||||
# Dev-Added files
|
||||
*.nuspec
|
||||
*/*/nuget.exe
|
||||
**/apireference/**
|
||||
|
||||
# User-specific files (MonoDevelop/Xamarin Studio)
|
||||
*.userprefs
|
||||
|
||||
|
|
@ -26,6 +31,7 @@ bld/
|
|||
[Bb]in/
|
||||
[Oo]bj/
|
||||
[Ll]og/
|
||||
build/*
|
||||
|
||||
# Visual Studio 2015/2017 cache/options directory
|
||||
.vs/
|
||||
|
|
|
|||
|
|
@ -1,103 +0,0 @@
|
|||
#region usings
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Dynamic;
|
||||
using OpenTK;
|
||||
using SM.Base.Drawing;
|
||||
using SM.Base.Scene;
|
||||
using SM.OGL.Mesh;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace SM.Base.Contexts
|
||||
{
|
||||
/// <summary>
|
||||
/// Contains important information for drawing.
|
||||
/// </summary>
|
||||
public struct DrawContext
|
||||
{
|
||||
/// <summary>
|
||||
/// This says if it was forced to use the viewport camera.
|
||||
/// </summary>
|
||||
public bool ForceViewport;
|
||||
|
||||
/// <summary>
|
||||
/// Contains the currently used render pipeline.
|
||||
/// </summary>
|
||||
public RenderPipeline ActivePipeline;
|
||||
|
||||
public GenericScene ActiveScene;
|
||||
public IGenericWindow Window;
|
||||
|
||||
|
||||
public GenericCamera UsedCamera =>
|
||||
ForceViewport || ActiveScene._camera == null ? Window.ViewportCamera : ActiveScene._camera;
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// The mesh.
|
||||
/// </summary>
|
||||
public GenericMesh Mesh;
|
||||
|
||||
/// <summary>
|
||||
/// The material.
|
||||
/// </summary>
|
||||
public Material Material;
|
||||
|
||||
/// <summary>
|
||||
/// The drawing instances.
|
||||
/// <para>If there is only one, it's index 0</para>
|
||||
/// </summary>
|
||||
public IList<Instance> Instances;
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// The current world scale.
|
||||
/// </summary>
|
||||
public Vector2 WorldScale;
|
||||
|
||||
/// <summary>
|
||||
/// The last collection the context was passed though.
|
||||
/// </summary>
|
||||
public object LastPassthough;
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Returns the appropriate shader.
|
||||
/// <para>
|
||||
/// Returns the material shader, if available, otherwise it will take the default shader from the render
|
||||
/// pipeline.
|
||||
/// </para>
|
||||
/// </summary>
|
||||
public MaterialShader Shader => Material.CustomShader ?? ActivePipeline._defaultShader;
|
||||
/// <summary>
|
||||
/// Arguments for shaders
|
||||
/// </summary>
|
||||
public IDictionary<string, object> ShaderArguments;
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// The current world matrix.
|
||||
/// </summary>
|
||||
public Matrix4 World;
|
||||
|
||||
/// <summary>
|
||||
/// The current view matrix.
|
||||
/// </summary>
|
||||
public Matrix4 View;
|
||||
|
||||
/// <summary>
|
||||
/// The current WorldView matrix.
|
||||
/// </summary>
|
||||
public Matrix4 WorldView;
|
||||
|
||||
/// <summary>
|
||||
/// The master model matrix.
|
||||
/// </summary>
|
||||
public Matrix4 ModelMaster;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,32 +0,0 @@
|
|||
#region usings
|
||||
|
||||
using OpenTK.Input;
|
||||
using SM.Base.Scene;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace SM.Base.Contexts
|
||||
{
|
||||
/// <summary>
|
||||
/// The update context.
|
||||
/// </summary>
|
||||
public struct UpdateContext
|
||||
{
|
||||
/// <summary>
|
||||
/// The delta time.
|
||||
/// </summary>
|
||||
public float Deltatime => SMRenderer.DefaultDeltatime.DeltaTime;
|
||||
|
||||
/// <summary>
|
||||
/// The current keyboard state.
|
||||
/// </summary>
|
||||
public KeyboardState KeyboardState;
|
||||
|
||||
/// <summary>
|
||||
/// The current mouse state.
|
||||
/// </summary>
|
||||
public MouseState MouseState;
|
||||
|
||||
public GenericScene CurrentScene;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,48 +0,0 @@
|
|||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,65 +0,0 @@
|
|||
#region usings
|
||||
|
||||
using System;
|
||||
using OpenTK;
|
||||
using OpenTK.Graphics.OpenGL4;
|
||||
using OpenTK.Input;
|
||||
using SM.Base;
|
||||
using SM2D.Controls;
|
||||
using SM2D.Pipelines;
|
||||
using SM2D.Scene;
|
||||
using SM2D.Shader;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace SM2D
|
||||
{
|
||||
public class GLWindow2D : GenericWindow<Scene.Scene, Camera>, IGLWindow2D
|
||||
{
|
||||
public GLWindow2D()
|
||||
{
|
||||
Mouse = new Mouse2D(this);
|
||||
}
|
||||
|
||||
public Vector2? Scaling { get; set; }
|
||||
|
||||
public Mouse2D Mouse { get; }
|
||||
|
||||
protected override void OnLoad(EventArgs e)
|
||||
{
|
||||
base.OnLoad(e);
|
||||
GL.Enable(EnableCap.Blend);
|
||||
GL.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha);
|
||||
}
|
||||
|
||||
protected override void OnLoaded()
|
||||
{
|
||||
base.OnLoaded();
|
||||
SMRenderer.DefaultMaterialShader = Default2DShader.MaterialShader;
|
||||
|
||||
SetRenderPipeline(Default2DPipeline.Pipeline);
|
||||
}
|
||||
|
||||
protected override void OnRenderFrame(FrameEventArgs e)
|
||||
{
|
||||
GL.Disable(EnableCap.DepthTest);
|
||||
base.OnRenderFrame(e);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnMouseMove(MouseMoveEventArgs e)
|
||||
{
|
||||
base.OnMouseMove(e);
|
||||
Mouse.MouseMoveEvent(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,106 +0,0 @@
|
|||
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
|
||||
{
|
||||
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()
|
||||
{
|
||||
|
||||
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(bool renderContinuesly = false)
|
||||
{
|
||||
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() : base()
|
||||
{
|
||||
_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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,296 +0,0 @@
|
|||
#region usings
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using OpenTK;
|
||||
using OpenTK.Graphics;
|
||||
using OpenTK.Graphics.OpenGL4;
|
||||
using OpenTK.Input;
|
||||
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.Base.Time;
|
||||
using SM.OGL;
|
||||
using SM.OGL.Framebuffer;
|
||||
using SM.Utility;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace SM.Base
|
||||
{
|
||||
/// <summary>
|
||||
/// The base window.
|
||||
/// </summary>
|
||||
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>
|
||||
public Vector2 WorldScale { get; set; } = Vector2.Zero;
|
||||
|
||||
/// <summary>
|
||||
/// This tells you the current aspect ratio of this window.
|
||||
/// </summary>
|
||||
public float Aspect { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// If false, the window will not react on updates and will not render something.
|
||||
/// <para>
|
||||
/// Default: false
|
||||
/// </para>
|
||||
/// </summary>
|
||||
public bool ReactWhileUnfocused = false;
|
||||
|
||||
public GenericCamera ViewportCamera => _viewportCamera;
|
||||
public bool ForceViewportCamera { get; set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
protected GenericWindow() : this(1280, 720, "Generic OGL Title", GameWindowFlags.Default)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a window...
|
||||
/// </summary>
|
||||
protected GenericWindow(int width, int height, string title, GameWindowFlags flags, bool vSync = true) : base(width, height,
|
||||
GraphicsMode.Default, title, flags, DisplayDevice.Default, GLSettings.ForcedVersion.MajorVersion,
|
||||
GLSettings.ForcedVersion.MinorVersion, GraphicsContextFlags.Default)
|
||||
{
|
||||
VSync = vSync ? VSyncMode.On : VSyncMode.Off;
|
||||
}
|
||||
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void OnLoad(EventArgs e)
|
||||
{
|
||||
GenericWindowCode.Load(this);
|
||||
|
||||
base.OnLoad(e);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void OnResize(EventArgs e)
|
||||
{
|
||||
base.OnResize(e);
|
||||
|
||||
GenericWindowCode.Resize(this);
|
||||
|
||||
if (_loading)
|
||||
{
|
||||
_loading = false;
|
||||
|
||||
OnLoaded();
|
||||
|
||||
_actionsAfterLoading.ForEach(a => a());
|
||||
_actionsAfterLoading = null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This is triggered after all the window-loading has been done.
|
||||
/// </summary>
|
||||
protected virtual void OnLoaded()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the world scale.
|
||||
/// </summary>
|
||||
public virtual void SetWorldScale()
|
||||
{
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void OnUpdateFrame(FrameEventArgs e)
|
||||
{
|
||||
if (!ReactWhileUnfocused && !Focused) return;
|
||||
|
||||
base.OnUpdateFrame(e);
|
||||
|
||||
Deltatime.UpdateDelta = (float) e.Time;
|
||||
var context = new UpdateContext
|
||||
{
|
||||
KeyboardState = Keyboard.GetState(),
|
||||
MouseState = Mouse.GetState()
|
||||
};
|
||||
|
||||
if (context.KeyboardState[Key.AltLeft] && context.KeyboardState[Key.F4]) Close();
|
||||
|
||||
Update(e, ref context);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates the system.
|
||||
/// </summary>
|
||||
/// <param name="e"></param>
|
||||
/// <param name="context"></param>
|
||||
protected virtual void Update(FrameEventArgs e, ref UpdateContext context)
|
||||
{
|
||||
Stopwatch.PerformTicks(context);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Grabs the cursor and make sure it doesn't leave the window.
|
||||
/// </summary>
|
||||
/// <param name="makeItInvisible">If true, it makes the cursor invisible.</param>
|
||||
public void GrabCursor(bool makeItInvisible = true)
|
||||
{
|
||||
CursorGrabbed = true;
|
||||
CursorVisible = !makeItInvisible;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ungrabs the cursor.
|
||||
/// </summary>
|
||||
public void UngrabCursor()
|
||||
{
|
||||
CursorGrabbed = false;
|
||||
if (!CursorVisible) CursorVisible = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create a bitmap from the framebuffer.
|
||||
/// </summary>
|
||||
public Bitmap TakeScreenshot(Framebuffer framebuffer, ReadBufferMode readBuffer, int x, int y, int width, int height)
|
||||
{
|
||||
GL.GetInteger(GetPName.FramebufferBinding, out int prevFBId);
|
||||
GL.GetInteger(GetPName.DrawFramebufferBinding, out int prevFBDrawId);
|
||||
GL.GetInteger(GetPName.ReadFramebufferBinding, out int prevFBReadId);
|
||||
|
||||
Bitmap b = new Bitmap(width, height);
|
||||
System.Drawing.Imaging.BitmapData bits = b.LockBits(new Rectangle(0, 0, width, height),
|
||||
System.Drawing.Imaging.ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
|
||||
|
||||
GL.BindFramebuffer(FramebufferTarget.ReadFramebuffer, framebuffer);
|
||||
GL.ReadBuffer(readBuffer);
|
||||
GL.ReadPixels(x, y, width, height, OpenTK.Graphics.OpenGL4.PixelFormat.Bgra, PixelType.UnsignedByte,
|
||||
bits.Scan0);
|
||||
|
||||
b.UnlockBits(bits);
|
||||
b.RotateFlip(RotateFlipType.RotateNoneFlipY);
|
||||
|
||||
GL.BindFramebuffer(FramebufferTarget.Framebuffer, prevFBId);
|
||||
GL.BindFramebuffer(FramebufferTarget.DrawFramebuffer, prevFBDrawId);
|
||||
GL.BindFramebuffer(FramebufferTarget.ReadFramebuffer, prevFBReadId);
|
||||
|
||||
return b;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The base window.
|
||||
/// </summary>
|
||||
/// <typeparam name="TScene">The scene type</typeparam>
|
||||
/// <typeparam name="TCamera">The camera type</typeparam>
|
||||
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()
|
||||
{
|
||||
_viewportCamera = new TCamera();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The viewport camera.
|
||||
/// </summary>
|
||||
public TCamera ViewportCamera {
|
||||
get => (TCamera)_viewportCamera;
|
||||
set => _viewportCamera = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This forces the render to use the viewport camera.
|
||||
/// </summary>
|
||||
public bool ForceViewportCamera { get; set; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// The current scene.
|
||||
/// </summary>
|
||||
public TScene CurrentScene => _scene;
|
||||
|
||||
/// <summary>
|
||||
/// Controls how a scene is rendered.
|
||||
/// </summary>
|
||||
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);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void OnRenderFrame(FrameEventArgs e)
|
||||
{
|
||||
if (!ReactWhileUnfocused && !Focused) return;
|
||||
|
||||
base.OnRenderFrame(e);
|
||||
|
||||
GenericWindowCode.Render(this, (float)e.Time);
|
||||
|
||||
SwapBuffers();
|
||||
|
||||
GLDebugging.CheckGLErrors();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void OnResize(EventArgs e)
|
||||
{
|
||||
base.OnResize(e);
|
||||
|
||||
GenericWindowCode.Resize(this);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the scene.
|
||||
/// </summary>
|
||||
/// <param name="scene"></param>
|
||||
public virtual void SetScene(TScene scene)
|
||||
{
|
||||
if (_loading)
|
||||
{
|
||||
_actionsAfterLoading.Add(() => SetScene(scene));
|
||||
return;
|
||||
}
|
||||
|
||||
_scene = scene;
|
||||
scene.Activate();
|
||||
RenderPipeline.SceneChanged(scene);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Defines the render pipeline.
|
||||
/// </summary>
|
||||
/// <param name="pipeline"></param>
|
||||
public void SetRenderPipeline(RenderPipeline<TScene> pipeline)
|
||||
{
|
||||
if (_loading)
|
||||
{
|
||||
_actionsAfterLoading.Add(() => SetRenderPipeline(pipeline));
|
||||
return;
|
||||
}
|
||||
|
||||
_renderPipeline = pipeline;
|
||||
pipeline.Activate(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,107 +0,0 @@
|
|||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,14 +0,0 @@
|
|||
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; }
|
||||
}
|
||||
}
|
||||
|
|
@ -1,37 +0,0 @@
|
|||
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);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,150 +0,0 @@
|
|||
#region usings
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using SM.Base.Contexts;
|
||||
using SM.Base.Drawing;
|
||||
using SM.Base.Scene;
|
||||
using SM.OGL.Framebuffer;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace SM.Base
|
||||
{
|
||||
/// <summary>
|
||||
/// Definition of specific render options.
|
||||
/// </summary>
|
||||
public abstract class RenderPipeline
|
||||
{
|
||||
/// <summary>
|
||||
/// If true, this pipeline was already once activated.
|
||||
/// </summary>
|
||||
public bool IsInitialized { get; private set; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// The window the pipeline is connected to.
|
||||
/// </summary>
|
||||
protected IGenericWindow _window { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// The framebuffers, that are used in this Pipeline.
|
||||
/// </summary>
|
||||
public virtual List<Framebuffer> Framebuffers { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// The default shader for the pipeline.
|
||||
/// </summary>
|
||||
protected internal virtual MaterialShader _defaultShader { get; set; }
|
||||
|
||||
public virtual Framebuffer MainFramebuffer { get; protected set; }= Framebuffer.Screen;
|
||||
|
||||
/// <summary>
|
||||
/// Occurs, when the window is loading.
|
||||
/// </summary>
|
||||
protected internal virtual void Load()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Occurs, when the window is resizing.
|
||||
/// </summary>
|
||||
protected internal virtual void Resize()
|
||||
{
|
||||
if (Framebuffers == null) return;
|
||||
|
||||
foreach (var framebuffer in Framebuffers)
|
||||
framebuffer.Dispose();
|
||||
|
||||
Thread.Sleep(50);
|
||||
|
||||
foreach (Framebuffer framebuffer in Framebuffers)
|
||||
{
|
||||
framebuffer.Compile();
|
||||
}
|
||||
}
|
||||
|
||||
internal void Activate(IGenericWindow window)
|
||||
{
|
||||
_window = window;
|
||||
|
||||
if (!IsInitialized)
|
||||
{
|
||||
if (_defaultShader == null) _defaultShader = SMRenderer.DefaultMaterialShader;
|
||||
Framebuffers = new List<Framebuffer>();
|
||||
|
||||
Initialization(window);
|
||||
|
||||
Framebuffers.Add(MainFramebuffer);
|
||||
|
||||
IsInitialized = true;
|
||||
}
|
||||
|
||||
Activation(window);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Occurs, when the pipeline was connected to a window.
|
||||
/// </summary>
|
||||
protected internal virtual void Activation(IGenericWindow window)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Occurs, when the pipeline was connected to a window the first time.
|
||||
/// </summary>
|
||||
/// <param name="window"></param>
|
||||
protected internal virtual void Initialization(IGenericWindow window)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Occurs, when the window is unloading.
|
||||
/// </summary>
|
||||
protected internal virtual void Unload()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a framebuffer, that has specific (often) required settings already applied.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static Framebuffer CreateWindowFramebuffer()
|
||||
{
|
||||
Framebuffer framebuffer = new Framebuffer(window: SMRenderer.CurrentWindow);
|
||||
framebuffer.Append("color", 0);
|
||||
return framebuffer;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Represents a render pipeline.
|
||||
/// </summary>
|
||||
/// <typeparam name="TScene">The scene type</typeparam>
|
||||
public abstract class RenderPipeline<TScene> : RenderPipeline
|
||||
where TScene : GenericScene
|
||||
{
|
||||
/// <summary>
|
||||
/// The system to render stuff.
|
||||
/// </summary>
|
||||
internal void Render(ref DrawContext context)
|
||||
{
|
||||
context.ActivePipeline = this;
|
||||
if (context.ActiveScene == null) return;
|
||||
|
||||
RenderProcess(ref context, (TScene)context.ActiveScene);
|
||||
}
|
||||
|
||||
protected abstract void RenderProcess(ref DrawContext context, TScene scene);
|
||||
|
||||
/// <summary>
|
||||
/// Event, that triggers, when the scene in the current window changes.
|
||||
/// </summary>
|
||||
/// <param name="scene"></param>
|
||||
protected internal virtual void SceneChanged(TScene scene)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,162 +0,0 @@
|
|||
<!DOCTYPE html>
|
||||
<!-- saved from url=(0014)about:internet -->
|
||||
|
||||
<html xmlns:msxsl="urn:schemas-microsoft-com:xslt"><head><meta content="en-us" http-equiv="Content-Language" /><meta content="text/html; charset=utf-16" http-equiv="Content-Type" /><title _locID="NuGetUpgradeReportTitle">
|
||||
NuGetMigrationLog
|
||||
</title><style>
|
||||
|
||||
/* Body style, for the entire document */
|
||||
body
|
||||
{
|
||||
background: #F3F3F4;
|
||||
color: #1E1E1F;
|
||||
font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
|
||||
font-size: 12pt;
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
/* Header1 style, used for the main title */
|
||||
h1
|
||||
{
|
||||
padding: 10px 0px 10px 10px;
|
||||
font-size: 21pt;
|
||||
background-color: #E2E2E2;
|
||||
border-bottom: 1px #C1C1C2 solid;
|
||||
color: #201F20;
|
||||
margin: 0;
|
||||
font-weight: normal;
|
||||
}
|
||||
|
||||
/* Header2 style, used for "Overview" and other sections */
|
||||
h2
|
||||
{
|
||||
font-size: 18pt;
|
||||
font-weight: normal;
|
||||
padding: 15px 0 5px 0;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
/* Header3 style, used for sub-sections, such as project name */
|
||||
h3
|
||||
{
|
||||
font-weight: normal;
|
||||
font-size: 15pt;
|
||||
margin: 0;
|
||||
padding: 15px 0 5px 0;
|
||||
background-color: transparent;
|
||||
}
|
||||
|
||||
.info-text
|
||||
{
|
||||
margin: 0px 0 0.75em 0;
|
||||
}
|
||||
|
||||
/* Color all hyperlinks one color */
|
||||
a
|
||||
{
|
||||
color: #1382CE;
|
||||
}
|
||||
|
||||
/* Table styles */
|
||||
table
|
||||
{
|
||||
border-spacing: 0 0;
|
||||
border-collapse: collapse;
|
||||
font-size: 11pt;
|
||||
}
|
||||
|
||||
table th
|
||||
{
|
||||
background: #E7E7E8;
|
||||
text-align: left;
|
||||
text-decoration: none;
|
||||
font-weight: normal;
|
||||
padding: 3px 6px 3px 6px;
|
||||
}
|
||||
|
||||
table td
|
||||
{
|
||||
vertical-align: top;
|
||||
padding: 3px 6px 5px 5px;
|
||||
margin: 0px;
|
||||
border: 1px solid #E7E7E8;
|
||||
background: #F7F7F8;
|
||||
}
|
||||
|
||||
/* Local link is a style for hyperlinks that link to file:/// content, there are lots so color them as 'normal' text until the user mouse overs */
|
||||
.localLink
|
||||
{
|
||||
color: #1E1E1F;
|
||||
background: #EEEEED;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.localLink:hover
|
||||
{
|
||||
color: #1382CE;
|
||||
background: #FFFF99;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.issueCell
|
||||
{
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.packageIssue
|
||||
{
|
||||
margin-left: 25px;
|
||||
}
|
||||
|
||||
/* Padding around the content after the h1 */
|
||||
#content
|
||||
{
|
||||
padding: 0px 20px 20px 20px;
|
||||
}
|
||||
|
||||
.issues table
|
||||
{
|
||||
width: 97%;
|
||||
}
|
||||
|
||||
/* All Icons */
|
||||
.IconSuccessEncoded, .IconInfoEncoded, .IconWarningEncoded, .IconErrorEncoded
|
||||
{
|
||||
min-width:18px;
|
||||
min-height:18px;
|
||||
background-repeat:no-repeat;
|
||||
background-position:center;
|
||||
}
|
||||
|
||||
.IconSuccessEncoded
|
||||
{
|
||||
background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAACXBIWXMAAA7EAAAOxAGVKw4bAAABcElEQVR4Xq2TsUsCURzHv15g8ZJcBWlyiYYgCIWcb9DFRRwMW5TA2c0/QEFwFkxxUQdxVlBwCYWOi6IhWgQhBLHJUCkhLr/BW8S7gvrAg+N+v8/v+x68Z8MGy+XSCyABQAXgBgHGALoASkIIDWSLeLBetdHryMjd5IxQPWT4rn1c/P7+xxp72Cs9m5SZ0Bq2vPnbPFafK2zDvmNHypdC0BPkLlQhxJsCAhQoZwdZU5mwxh720qGo8MzTxTTKZDPCx2HoVzp6lz0Q9tKhyx0kGs8Ny+TkWRKk8lCROwEduhyg9l/6lunOPSfmH3NUH6uQ0KHLAe7JYvJjevm+DAMGJHToKtigE+vwvIidxLamb8IBY9e+C5LiXREkfho3TSd06HJA13/oh6T51MTsfQbHrsMynQ5dDihFjiK8JJAU9AKIWTp76dCVN7HWHrajmUEGvyF9nkbAE6gLIS7kTUyuf2gscLoJrElZo/Mvj+nPz/kLTmfnEwP3tB0AAAAASUVORK5CYII=);
|
||||
}
|
||||
|
||||
.IconInfoEncoded
|
||||
{
|
||||
background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAABHElEQVR4Xs2TsUoDQRRF7wwoziokjZUKadInhdhukR9YP8DMX1hYW+QvdsXa/QHBbcXC7W0CamWTQnclFutceIQJwwaWNLlwm5k5d94M76mmaeCrrmsLYOocY12FcxZFUeozCqKqqgYA8uevv1H6VuPxcwlfk5N92KHBxfFeCSAxxswlYAW/Xr989x/mv9gkhtyMDhcAxgzRsp7flj8B/HF1RsMXq+NZMkopaHe7lbKxQUEIGbKsYNoGn969060hZBkQex/W8oRQwsQaW2o3Ago2SVcJUzAgY3N0lTCZZm+zPS8HB51gMmS1DEYyOz9acKO1D8JWTlafKIMxdhvlfdyT94Vv5h7P8Ky7nQzACmhvKq3zk3PjW9asz9D/1oigecsioooAAAAASUVORK5CYII=);
|
||||
}
|
||||
|
||||
.IconWarningEncoded
|
||||
{
|
||||
background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAAx0lEQVR4XpWSMQ7CMAxFf4xAyBMLCxMrO8dhaBcuwdCJS3RJBw7SA/QGTCxdWJgiQYWKXJWKIXHIlyw5lqr34tQgEOdcBsCOx5yZK3hCCKdYXneQkh4pEfqzLfu+wVDSyyzFoJjfz9NB+pAF+eizx2Vruts0k15mPgvS6GYvpVtQhB61IB/dk6AF6fS4Ben0uIX5odtFe8Q/eW1KvFeH4e8khT6+gm5B+t3juyDt7n0jpe+CANTd+oTUjN/U3yVaABnSUjFz/gFq44JaVSCXeQAAAABJRU5ErkJggg==);
|
||||
}
|
||||
|
||||
.IconErrorEncoded
|
||||
{
|
||||
background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAABQElEQVR4XqWTvUoEQRCE6wYPZUA80AfwAQz23uCMjA7MDRQEIzPBVEyNTQUFIw00vcQTTMzuAh/AxEQQT8HF/3G/oGGnEUGuoNnd6qoZuqltyKEsyzVJq5I6rnUp6SjGeGhESikzzlc1eL7opfuVbrqbU1Zw9NCgtQMaZpY0eNnaaL2fHusvTK5vKu7sjSS1Y4y3QUA6K3e3Mau5UFDyMP7tYF9o8cAHZv68vipoIJg971PZIZ5HiwdvYGGvFVFHmGmZ2MxwmQYPXubPl9Up0tfoMQGetXd6mRbvhBw+boZ6WF7Mbv1+GsHRk0fQmPAH1GfmZirbCfDJ61tw3Px8/8pZsPAG4jlVhcPgZ7adwNWBB68lkRQWFiTgFlbnLY3DGGM7izIJIyT/jjIvEJw6fdJTc6krDzh6aMwMP9bvDH4ADSsa9uSWVJkAAAAASUVORK5CYII=);
|
||||
}
|
||||
|
||||
</style></head><body><h1>
|
||||
NuGet Migration Report - SMRenderer\SM2D</h1><div id="content"><h2 _locID="OverviewTitle">Overview</h2><div class="info-text">Migration to PackageReference was completed successfully. Please build and run your solution to verify that all packages are available.</div><div class="info-text">
|
||||
If you run into any problems, have feedback, questions, or concerns, please
|
||||
<a href="https://github.com/NuGet/Home/issues/">file an issue on the NuGet GitHub repository.</a></div><div class="info-text">
|
||||
Changed files and this report have been backed up here:
|
||||
<a href="C:\Users\user\source\repos\IedSoftworks\SMRendererV3\MigrationBackup\d4ed0f1f\SMRenderer\SM2D">C:\Users\user\source\repos\IedSoftworks\SMRendererV3\MigrationBackup\d4ed0f1f\SMRenderer\SM2D</a></div><div class="info-text"><a href="https://aka.ms/nuget-pc2pr-migrator-rollback">Help me rollback to packages.config</a></div><h2 _locID="PackagesTitle">Packages processed</h2><h3 _locID="IncludePackagesTitle">Top-level dependencies:</h3><div class="issues"><table><tr><th class="issueCell">Package Id</th><th>Version</th></tr><tr><td class="issueCell"><span>OpenTK</span></td><td><span>
|
||||
v3.2.1</span></td></tr></table></div><p /><h3 _locID="IncludePackagesTitle">Transitive dependencies:</h3><div class="issues"><table><tr><th class="issueCell">Package Id</th><th>Version</th></tr><tr><td class="issueCell">
|
||||
No transitive dependencies found.
|
||||
</td><td /></tr></table></div><h2 _locID="IssuesTitle">Package compatibility issues</h2><div class="issues"><table><tr><th /><th class="issueCell" _locID="DescriptionTableHeader">Description</th></tr><tr><td class="IconInfoEncoded" /><td class="issueCell">
|
||||
No issues were found.
|
||||
</td></tr></table></div></div></body></html>
|
||||
|
|
@ -1,82 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{A4565538-625A-42C6-A330-DD4F1ABB3986}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>SM2D</RootNamespace>
|
||||
<AssemblyName>SM2D</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<Deterministic>true</Deterministic>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<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="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Drawing" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Controls\Mouse2D.cs" />
|
||||
<Compile Include="Drawing\DrawBackground.cs" />
|
||||
<Compile Include="Drawing\DrawBackgroundShader.cs" />
|
||||
<Compile Include="Drawing\DrawColor.cs" />
|
||||
<Compile Include="Drawing\DrawComplex.cs" />
|
||||
<Compile Include="Drawing\DrawObject2D.cs" />
|
||||
<Compile Include="Drawing\DrawParticles.cs" />
|
||||
<Compile Include="Drawing\DrawPolygon.cs" />
|
||||
<Compile Include="Drawing\DrawShader.cs" />
|
||||
<Compile Include="Drawing\DrawText.cs" />
|
||||
<Compile Include="Drawing\DrawTexture.cs" />
|
||||
<Compile Include="GLWindow2D.cs" />
|
||||
<Compile Include="Object\Polygon.cs" />
|
||||
<Compile Include="Object\PolygonVertex.cs" />
|
||||
<Compile Include="Pipelines\Adv2DPipeline.cs" />
|
||||
<Compile Include="Pipelines\Basic2DPipeline.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Scene\Camera.cs" />
|
||||
<Compile Include="Scene\I2DShowItem.cs" />
|
||||
<Compile Include="Scene\ItemCollection.cs" />
|
||||
<Compile Include="Scene\Scene.cs" />
|
||||
<Compile Include="Shader\Default2DShader.cs" />
|
||||
<Compile Include="Types\Transformation.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\SM.Base\SM.Base.csproj">
|
||||
<Project>{8e733844-4204-43e7-b3dc-3913cddabb0d}</Project>
|
||||
<Name>SM.Base</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\SM.OGL\SM.OGL.csproj">
|
||||
<Project>{f604d684-bc1d-4819-88b5-8b5d03a17be0}</Project>
|
||||
<Name>SM.OGL</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="OpenTK.dll.config" />
|
||||
<None Include="packages.config" />
|
||||
<EmbeddedResource Include="Shader\ShaderFiles\default.glsl" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
||||
|
|
@ -1,4 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="OpenTK" version="3.2.1" targetFramework="net452" />
|
||||
</packages>
|
||||
|
|
@ -28,6 +28,18 @@ namespace SM.Base.Controls
|
|||
/// </summary>
|
||||
public static Vector2 InScreenNormalized { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// This returns true, if the left mouse button was pressed.
|
||||
/// <para>Its pretty much: IsDown(MouseButton.Left, true)</para>
|
||||
/// </summary>
|
||||
public static bool LeftClick => IsDown(MouseButton.Left, true);
|
||||
|
||||
/// <summary>
|
||||
/// This returns true, if the right mouse button was pressed.
|
||||
/// <para>Its pretty much: IsDown(MouseButton.Right, true)</para>
|
||||
/// </summary>
|
||||
public static bool RightClick => IsDown(MouseButton.Right, true);
|
||||
|
||||
/// <summary>
|
||||
/// The event to update the values.
|
||||
/// </summary>
|
||||
|
|
@ -53,11 +65,21 @@ namespace SM.Base.Controls
|
|||
_mouseState = OpenTK.Input.Mouse.GetState();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if the mouse is pressed.
|
||||
/// </summary>
|
||||
/// <param name="button"></param>
|
||||
/// <param name="once">If true, it will not get called, when it was pressed in the last update.</param>
|
||||
public static bool IsDown(MouseButton button, bool once = false)
|
||||
{
|
||||
return _mouseState?[button] == true && !(once && _lastButtonsPressed.Contains(button));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if the mouse is not pressed.
|
||||
/// </summary>
|
||||
/// <param name="button"></param>
|
||||
/// <param name="once">If true, it will not get called, when it was not pressed in the last update.</param>
|
||||
public static bool IsUp(MouseButton button, bool once = false)
|
||||
{
|
||||
return _mouseState?[button] == false && !(once && !_lastButtonsPressed.Contains(button));
|
||||
|
|
|
|||
|
|
@ -55,6 +55,7 @@ namespace SM.Base.Drawing
|
|||
/// </summary>
|
||||
public bool Active { get; set; } = true;
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool RenderActive { get; set; } = true;
|
||||
|
||||
/// <inheritdoc />
|
||||
|
|
|
|||
|
|
@ -34,19 +34,10 @@
|
|||
<LangVersion>latest</LangVersion>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<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="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" />
|
||||
<Reference Include="System.Drawing" />
|
||||
|
|
|
|||
|
|
@ -43,6 +43,11 @@ namespace SM.Base
|
|||
/// </summary>
|
||||
public static MaterialShader DefaultMaterialShader;
|
||||
|
||||
/// <summary>
|
||||
/// The default render pipeline.
|
||||
/// </summary>
|
||||
public static RenderPipeline DefaultRenderPipeline;
|
||||
|
||||
/// <summary>
|
||||
/// Shows more information onto the log system.
|
||||
/// </summary>
|
||||
|
|
|
|||
|
|
@ -15,8 +15,8 @@ namespace SM.Base.Scene
|
|||
/// </summary>
|
||||
public abstract class GenericItemCollection : List<IShowItem>, IShowItem, IShowCollection, IScriptable, IFixedScriptable
|
||||
{
|
||||
private List<IScriptable> _scriptableObjects = new List<IScriptable>();
|
||||
private List<IFixedScriptable> _fixedScriptables = new List<IFixedScriptable>();
|
||||
private readonly List<IScriptable> _scriptableObjects = new List<IScriptable>();
|
||||
private readonly List<IFixedScriptable> _fixedScriptables = new List<IFixedScriptable>();
|
||||
|
||||
/// <summary>
|
||||
/// Currently active script objects.
|
||||
|
|
@ -45,6 +45,7 @@ namespace SM.Base.Scene
|
|||
/// <inheritdoc />
|
||||
public bool RenderActive { get; set; } = true;
|
||||
|
||||
/// <inheritdoc />
|
||||
public virtual void FixedUpdate(FixedUpdateContext context)
|
||||
{
|
||||
if (!Active || !UpdateActive) return;
|
||||
|
|
@ -126,6 +127,11 @@ namespace SM.Base.Scene
|
|||
if (item is IFixedScriptable fs) _fixedScriptables.Add(fs);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes an object from the drawing list.
|
||||
/// <para>If the object is a scriptable object, it will remove the object from that list as well.</para>
|
||||
/// </summary>
|
||||
/// <param name="items"></param>
|
||||
public void Remove(params IShowItem[] items)
|
||||
{
|
||||
foreach (var item in items)
|
||||
|
|
@ -161,6 +167,12 @@ namespace SM.Base.Scene
|
|||
if (item is IFixedScriptable fs) _fixedScriptables.Remove(fs);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns all objects in the drawing list.
|
||||
/// <para>Not reclusive.</para>
|
||||
/// </summary>
|
||||
/// <param name="includeCollections">If true, it will add collections as well.</param>
|
||||
/// <returns></returns>
|
||||
public ICollection<IShowItem> GetAllItems(bool includeCollections = false)
|
||||
{
|
||||
List<IShowItem> items = new List<IShowItem>();
|
||||
|
|
@ -224,7 +236,6 @@ namespace SM.Base.Scene
|
|||
/// <summary>
|
||||
/// Contains a list of show items with transformation.
|
||||
/// </summary>
|
||||
/// <typeparam name="TItem">The type of show items.</typeparam>
|
||||
/// <typeparam name="TTransformation">The type of transformation.</typeparam>
|
||||
public abstract class GenericItemCollection<TTransformation> : GenericItemCollection,
|
||||
IShowTransformItem<TTransformation>
|
||||
|
|
|
|||
|
|
@ -213,18 +213,24 @@ namespace SM.Base.Scene
|
|||
/// A generic scene that imports different functions.
|
||||
/// </summary>
|
||||
/// <typeparam name="TCamera">The type of cameras.</typeparam>
|
||||
/// <typeparam name="TItem">The type of show items.</typeparam>
|
||||
/// <typeparam name="TCollection">The type for collections</typeparam>
|
||||
public abstract class GenericScene<TCamera, TCollection> : GenericScene
|
||||
where TCamera : GenericCamera, new()
|
||||
where TCollection : GenericItemCollection, new()
|
||||
{
|
||||
/// <summary>
|
||||
/// Objects inside the scene, but as the collection type.
|
||||
/// </summary>
|
||||
public new TCollection Objects
|
||||
{
|
||||
get => (TCollection) base.Objects;
|
||||
set => base.Objects = value;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// HUD-Objects inside the scene, but as the collection type.
|
||||
/// </summary>
|
||||
public new TCollection HUD
|
||||
{
|
||||
get
|
||||
|
|
@ -235,18 +241,28 @@ namespace SM.Base.Scene
|
|||
set => base.HUD = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The active camera, that is used if the context doesn't force the viewport camera.
|
||||
/// <para>If none set, it automaticly uses the viewport camera.</para>
|
||||
/// </summary>
|
||||
public new TCamera Camera
|
||||
{
|
||||
get => (TCamera) base.Camera;
|
||||
set => base.Camera = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A camera to control the HUD.
|
||||
/// </summary>
|
||||
public new TCamera HUDCamera
|
||||
{
|
||||
get => (TCamera) base.HUDCamera;
|
||||
set => base.HUDCamera = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A camera to control the background.
|
||||
/// </summary>
|
||||
public new TCamera BackgroundCamera
|
||||
{
|
||||
get => (TCamera) base.BackgroundCamera;
|
||||
|
|
|
|||
|
|
@ -55,19 +55,36 @@ namespace SM.Base.Scene
|
|||
void OnRemoved(object sender);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Interface to implement transformation.
|
||||
/// </summary>
|
||||
/// <typeparam name="TTransform"></typeparam>
|
||||
public interface ITransformItem<TTransform>
|
||||
where TTransform : GenericTransformation
|
||||
{
|
||||
/// <summary>
|
||||
/// Controls the transformation of the object.
|
||||
/// </summary>
|
||||
TTransform Transform { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Merges <see cref="IShowItem"/> and <see cref="ITransformItem{TTransform}"/>.
|
||||
/// </summary>
|
||||
/// <typeparam name="TTransform"></typeparam>
|
||||
public interface IShowTransformItem<TTransform> : IShowItem, ITransformItem<TTransform>
|
||||
where TTransform : GenericTransformation
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Interface to implement models in the object.
|
||||
/// </summary>
|
||||
public interface IModelItem
|
||||
{
|
||||
/// <summary>
|
||||
/// The mesh the rendering should use.
|
||||
/// </summary>
|
||||
GenericMesh Mesh { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
@ -96,7 +96,6 @@ namespace SM.Base.Types
|
|||
/// <summary>
|
||||
/// Conversion from <see cref="float" /> to One-dimensional Vector.
|
||||
/// </summary>
|
||||
/// <param name="f"></param>
|
||||
/// <returns></returns>
|
||||
//public static implicit operator CVector1(float f) => new CVector1(f);
|
||||
protected virtual float GetLengthProcess()
|
||||
|
|
@ -104,14 +103,27 @@ namespace SM.Base.Types
|
|||
return X * X;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Normalizes the vector.
|
||||
/// </summary>
|
||||
/// <param name="length"></param>
|
||||
protected virtual void NormalizationProcess(float length)
|
||||
{
|
||||
X *= length;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This triggers the <see cref="Changed"/> event.
|
||||
/// </summary>
|
||||
protected void TriggerChanged()
|
||||
{
|
||||
Changed?.Invoke();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string ToString()
|
||||
{
|
||||
return X.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -46,6 +46,12 @@ namespace SM.Base.Types
|
|||
Y *= length;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string ToString()
|
||||
{
|
||||
return "{"+X+"; "+Y+"}";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets each component to the same value
|
||||
/// </summary>
|
||||
|
|
@ -58,7 +64,6 @@ namespace SM.Base.Types
|
|||
/// <summary>
|
||||
/// Sets each component to the <see cref="Vector2" /> counter-part.
|
||||
/// </summary>
|
||||
/// <param name="vector"></param>
|
||||
public void Set(Vector2 vector, bool triggerChanged = true)
|
||||
{
|
||||
Set(vector.X, vector.Y, triggerChanged);
|
||||
|
|
@ -67,8 +72,6 @@ namespace SM.Base.Types
|
|||
/// <summary>
|
||||
/// Sets the a own value to each component.
|
||||
/// </summary>
|
||||
/// <param name="x"></param>
|
||||
/// <param name="y"></param>
|
||||
public void Set(float x, float y, bool triggerChanged = true)
|
||||
{
|
||||
Y = y;
|
||||
|
|
|
|||
|
|
@ -46,6 +46,12 @@ namespace SM.Base.Types
|
|||
Z *= length;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string ToString()
|
||||
{
|
||||
return "{" + X + "; " + Y + "}";
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void Set(float uniform, bool triggerChanged = true)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -6,12 +6,24 @@ using SM.Base.Scene;
|
|||
|
||||
namespace SM.Base.Window
|
||||
{
|
||||
/// <summary>
|
||||
/// A context that gets send when a window want to update the scene.
|
||||
/// </summary>
|
||||
public struct UpdateContext
|
||||
{
|
||||
/// <summary>
|
||||
/// The window what triggered the updated.
|
||||
/// </summary>
|
||||
public IGenericWindow Window;
|
||||
|
||||
/// <summary>
|
||||
/// A current update delta time. Equivalent to <see cref="SMRenderer.DefaultDeltatime"/>.
|
||||
/// </summary>
|
||||
public float Deltatime => SMRenderer.DefaultDeltatime.DeltaTime;
|
||||
|
||||
/// <summary>
|
||||
/// The scene that gets updated.
|
||||
/// </summary>
|
||||
public GenericScene Scene;
|
||||
}
|
||||
}
|
||||
|
|
@ -3,6 +3,7 @@
|
|||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics;
|
||||
using System.Drawing.Text;
|
||||
using System.Threading;
|
||||
using System.Windows.Forms;
|
||||
using OpenTK;
|
||||
|
|
@ -18,58 +19,105 @@ using Mouse = SM.Base.Controls.Mouse;
|
|||
|
||||
namespace SM.Base.Window
|
||||
{
|
||||
/// <summary>
|
||||
/// This provides the main entry, by executing the window.
|
||||
/// </summary>
|
||||
public class GLWindow : GameWindow, IGenericWindow
|
||||
{
|
||||
private Vector2 _flagWindowPos;
|
||||
private Vector2 _flagWindowSize;
|
||||
|
||||
private Thread _fixedUpdateThread;
|
||||
private WindowFlags _windowFlags;
|
||||
|
||||
public WindowFlags WindowFlags;
|
||||
private DisplayResolution _normalResolution;
|
||||
private DisplayResolution _fullscreenResolution;
|
||||
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool Loading { get; private set; } = true;
|
||||
|
||||
/// <inheritdoc />
|
||||
public float AspectRatio { get; set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public GenericCamera ViewportCamera { get; set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool ForceViewportCamera { get; set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool DrawWhileUnfocused { get; set; } = true;
|
||||
/// <inheritdoc />
|
||||
public bool UpdateWhileUnfocused { get; set; } = false;
|
||||
|
||||
/// <inheritdoc />
|
||||
public Vector2 WindowSize { get; set; }
|
||||
/// <inheritdoc />
|
||||
public ISetup AppliedSetup { get; private set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public new event Action<IGenericWindow> Resize;
|
||||
/// <inheritdoc />
|
||||
public new event Action<IGenericWindow> Load;
|
||||
|
||||
/// <inheritdoc />
|
||||
public GenericScene CurrentScene { get; private set; }
|
||||
/// <inheritdoc />
|
||||
public RenderPipeline CurrentRenderPipeline { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets/Sets the current window flag.
|
||||
/// </summary>
|
||||
public WindowFlags WindowFlags
|
||||
{
|
||||
get => _windowFlags;
|
||||
set
|
||||
{
|
||||
if (_windowFlags != value)
|
||||
{
|
||||
WindowFlags oldV = _windowFlags;
|
||||
_windowFlags = value;
|
||||
ChangeWindowFlag(value, oldV);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Loads the window with default values.
|
||||
/// <para>Width: 1280px; Height: 720px; Title: Generic OpenGL Title; WindowFlag: Window</para>
|
||||
/// </summary>
|
||||
public GLWindow() : this(1280, 720, "Generic OpenGL Title", WindowFlags.Window)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Loads the window with custom values.
|
||||
/// </summary>
|
||||
/// <param name="width"></param>
|
||||
/// <param name="height"></param>
|
||||
/// <param name="title"></param>
|
||||
/// <param name="flags"></param>
|
||||
/// <param name="vSync"></param>
|
||||
public GLWindow(int width, int height, string title, WindowFlags flags, VSyncMode vSync = VSyncMode.On) :
|
||||
base(width, height, default, title, (GameWindowFlags) flags, DisplayDevice.Default,
|
||||
base(width, height, default, title, GameWindowFlags.Default, DisplayDevice.Default,
|
||||
GLSettings.ForcedVersion.MajorVersion, GLSettings.ForcedVersion.MinorVersion,
|
||||
GraphicsContextFlags.Default)
|
||||
{
|
||||
VSync = vSync;
|
||||
_flagWindowSize = new Vector2(width, height);
|
||||
WindowFlags = flags;
|
||||
|
||||
ChangeWindowFlag(flags);
|
||||
FocusedChanged += GLWindow_FocusedChanged;
|
||||
_normalResolution = _fullscreenResolution = DisplayDevice.Default.SelectResolution(DisplayDevice.Default.Width, DisplayDevice.Default.Height, DisplayDevice.Default.BitsPerPixel, DisplayDevice.Default.RefreshRate);
|
||||
}
|
||||
|
||||
public bool Loading { get; private set; } = true;
|
||||
public float AspectRatio { get; set; }
|
||||
|
||||
public GenericCamera ViewportCamera { get; set; }
|
||||
public bool ForceViewportCamera { get; set; }
|
||||
|
||||
public bool DrawWhileUnfocused { get; set; } = true;
|
||||
public bool UpdateWhileUnfocused { get; set; } = false;
|
||||
|
||||
public Vector2 WindowSize { get; set; }
|
||||
|
||||
public ISetup AppliedSetup { get; private set; }
|
||||
public new event Action<IGenericWindow> Resize;
|
||||
public new event Action<IGenericWindow> Load;
|
||||
|
||||
public GenericScene CurrentScene { get; private set; }
|
||||
public RenderPipeline CurrentRenderPipeline { get; private set; }
|
||||
|
||||
public void TriggerLoad()
|
||||
{
|
||||
Load?.Invoke(this);
|
||||
}
|
||||
|
||||
public void TriggerResize()
|
||||
{
|
||||
Resize?.Invoke(this);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A event that gets executed when the window is done loading.
|
||||
/// </summary>
|
||||
public event Action<IGenericWindow> Loaded;
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void OnLoad(EventArgs e)
|
||||
{
|
||||
WindowCode.Load(this);
|
||||
|
|
@ -78,14 +126,13 @@ namespace SM.Base.Window
|
|||
base.OnLoad(e);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void OnResize(EventArgs e)
|
||||
{
|
||||
base.OnResize(e);
|
||||
|
||||
WindowCode.Resize(this);
|
||||
|
||||
if (WindowFlags == WindowFlags.Window) _flagWindowSize = WindowSize;
|
||||
|
||||
if (Loading)
|
||||
{
|
||||
Loading = false;
|
||||
|
|
@ -94,6 +141,7 @@ namespace SM.Base.Window
|
|||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void OnUpdateFrame(FrameEventArgs e)
|
||||
{
|
||||
if (!Focused && !UpdateWhileUnfocused) return;
|
||||
|
|
@ -104,6 +152,7 @@ namespace SM.Base.Window
|
|||
}
|
||||
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void OnRenderFrame(FrameEventArgs e)
|
||||
{
|
||||
base.OnRenderFrame(e);
|
||||
|
|
@ -115,23 +164,40 @@ namespace SM.Base.Window
|
|||
GLDebugging.CheckGLErrors();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void OnMouseMove(MouseMoveEventArgs e)
|
||||
{
|
||||
base.OnMouseMove(e);
|
||||
Mouse.MouseMoveEvent(e, this);
|
||||
}
|
||||
|
||||
|
||||
/// <inheritdoc />
|
||||
public void TriggerLoad()
|
||||
{
|
||||
Load?.Invoke(this);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void TriggerResize()
|
||||
{
|
||||
Resize?.Invoke(this);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Update(UpdateContext context)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void ApplySetup(ISetup setup)
|
||||
{
|
||||
AppliedSetup = setup;
|
||||
setup.Applied(this);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void SetScene(GenericScene scene)
|
||||
{
|
||||
if (Loading)
|
||||
|
|
@ -144,6 +210,7 @@ namespace SM.Base.Window
|
|||
CurrentScene = scene;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void SetRenderPipeline(RenderPipeline renderPipeline)
|
||||
{
|
||||
if (Loading)
|
||||
|
|
@ -156,34 +223,23 @@ namespace SM.Base.Window
|
|||
CurrentRenderPipeline = renderPipeline;
|
||||
}
|
||||
|
||||
public void ChangeWindowFlag(WindowFlags newFlag)
|
||||
/// <summary>
|
||||
/// Changes the resolution in fullscreen mode.
|
||||
/// <para>Can be executed before changing to fullscreen, but with no effect until changed.</para>
|
||||
/// </summary>
|
||||
/// <param name="resolution">The resolution you get from <see cref="DisplayDevice.AvailableResolutions"/> or <see cref="DisplayDevice.SelectResolution"/></param>
|
||||
public void ChangeFullscreenResolution(DisplayResolution resolution)
|
||||
{
|
||||
WindowFlags = newFlag;
|
||||
_fullscreenResolution = resolution;
|
||||
|
||||
switch (newFlag)
|
||||
{
|
||||
case WindowFlags.Window:
|
||||
Width = (int) _flagWindowSize.X;
|
||||
Height = (int) _flagWindowSize.Y;
|
||||
|
||||
WindowBorder = WindowBorder.Resizable;
|
||||
break;
|
||||
case WindowFlags.BorderlessWindow:
|
||||
WindowBorder = WindowBorder.Hidden;
|
||||
|
||||
X = Screen.PrimaryScreen.Bounds.Left;
|
||||
Y = Screen.PrimaryScreen.Bounds.Top;
|
||||
Width = Screen.PrimaryScreen.Bounds.Width;
|
||||
Height = Screen.PrimaryScreen.Bounds.Height;
|
||||
|
||||
break;
|
||||
case WindowFlags.ExclusiveFullscreen:
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException(nameof(newFlag), newFlag, null);
|
||||
}
|
||||
if (_windowFlags == WindowFlags.ExclusiveFullscreen) ApplyFullscreenResolution();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Starts the fixed update loop.
|
||||
/// <para>Need to get executed before <see cref="IFixedScriptable"/> can be used.</para>
|
||||
/// </summary>
|
||||
/// <param name="updatesPerSecond"></param>
|
||||
public void RunFixedUpdate(float updatesPerSecond)
|
||||
{
|
||||
Deltatime.FixedUpdateDelta = 1 / (float)updatesPerSecond;
|
||||
|
|
@ -208,5 +264,76 @@ namespace SM.Base.Window
|
|||
Thread.Sleep(waitTime);
|
||||
}
|
||||
}
|
||||
|
||||
private void GLWindow_FocusedChanged(object sender, EventArgs e)
|
||||
{
|
||||
if (_windowFlags == WindowFlags.ExclusiveFullscreen)
|
||||
{
|
||||
if (!Focused)
|
||||
{
|
||||
DisplayDevice.Default.ChangeResolution(_normalResolution);
|
||||
WindowState = WindowState.Minimized;
|
||||
}
|
||||
else
|
||||
{
|
||||
ApplyFullscreenResolution();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
private void ChangeWindowFlag(WindowFlags newFlag, WindowFlags oldFlag)
|
||||
{
|
||||
if (oldFlag == WindowFlags.Window)
|
||||
{
|
||||
_flagWindowSize = WindowSize;
|
||||
_flagWindowPos = new Vector2(X, Y);
|
||||
}
|
||||
|
||||
switch (newFlag)
|
||||
{
|
||||
case WindowFlags.Window:
|
||||
DisplayDevice.Default.ChangeResolution(_normalResolution);
|
||||
WindowState = WindowState.Normal;
|
||||
Width = (int)_flagWindowSize.X;
|
||||
Height = (int)_flagWindowSize.Y;
|
||||
|
||||
X = (int) _flagWindowPos.X;
|
||||
Y = (int) _flagWindowPos.Y;
|
||||
|
||||
WindowBorder = WindowBorder.Resizable;
|
||||
|
||||
|
||||
break;
|
||||
case WindowFlags.BorderlessWindow:
|
||||
DisplayDevice.Default.ChangeResolution(_normalResolution);
|
||||
WindowState = WindowState.Maximized;
|
||||
WindowBorder = WindowBorder.Hidden;
|
||||
|
||||
X = Screen.PrimaryScreen.Bounds.Left;
|
||||
Y = Screen.PrimaryScreen.Bounds.Top;
|
||||
Width = Screen.PrimaryScreen.Bounds.Width;
|
||||
Height = Screen.PrimaryScreen.Bounds.Height;
|
||||
|
||||
break;
|
||||
case WindowFlags.ExclusiveFullscreen:
|
||||
|
||||
|
||||
WindowState = WindowState.Fullscreen;
|
||||
ApplyFullscreenResolution();
|
||||
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException(nameof(newFlag), newFlag, null);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void ApplyFullscreenResolution()
|
||||
{
|
||||
DisplayDevice.Default.ChangeResolution(_fullscreenResolution);
|
||||
Width = _fullscreenResolution.Width;
|
||||
Height = _fullscreenResolution.Height;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -10,39 +10,106 @@ using SM.OGL.Framebuffer;
|
|||
|
||||
namespace SM.Base.Window
|
||||
{
|
||||
/// <summary>
|
||||
/// This interface sets ground functions for windows.
|
||||
/// </summary>
|
||||
public interface IGenericWindow : IFramebufferWindow
|
||||
{
|
||||
/// <summary>
|
||||
/// If true, the window is currently loading.
|
||||
/// </summary>
|
||||
bool Loading { get; }
|
||||
/// <summary>
|
||||
/// Holds the aspect ratio of the window.
|
||||
/// </summary>
|
||||
float AspectRatio { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The viewport camera is used, when no camera is found in the scene.
|
||||
/// </summary>
|
||||
GenericCamera ViewportCamera { get; set; }
|
||||
/// <summary>
|
||||
/// Turning this to true, will force the window to render in the viewport camera.
|
||||
/// </summary>
|
||||
bool ForceViewportCamera { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Turning this to false will not allow drawing while the window is not in focus.
|
||||
/// </summary>
|
||||
bool DrawWhileUnfocused { get; set; }
|
||||
/// <summary>
|
||||
/// Turning this to false will not allow updating while the window is not in focus.
|
||||
/// </summary>
|
||||
bool UpdateWhileUnfocused { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Contains the window size.
|
||||
/// </summary>
|
||||
Vector2 WindowSize { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The rectangle the window is using.
|
||||
/// </summary>
|
||||
Rectangle ClientRectangle { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The setup that was applied to the window.
|
||||
/// </summary>
|
||||
ISetup AppliedSetup { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The scene that is currently used.
|
||||
/// </summary>
|
||||
GenericScene CurrentScene { get; }
|
||||
/// <summary>
|
||||
/// The render pipeline that is currently used.
|
||||
/// </summary>
|
||||
RenderPipeline CurrentRenderPipeline { get; }
|
||||
|
||||
/// <summary>
|
||||
/// An event, when the window resizes.
|
||||
/// </summary>
|
||||
event Action<IGenericWindow> Resize;
|
||||
/// <summary>
|
||||
/// An event, when the window is loading.
|
||||
/// </summary>
|
||||
event Action<IGenericWindow> Load;
|
||||
|
||||
/// <summary>
|
||||
/// This gets executed, when the window should update something.
|
||||
/// </summary>
|
||||
/// <param name="context">The context of the update.</param>
|
||||
void Update(UpdateContext context);
|
||||
|
||||
/// <summary>
|
||||
/// This applies a setup to the window.
|
||||
/// </summary>
|
||||
/// <param name="setup"></param>
|
||||
void ApplySetup(ISetup setup);
|
||||
|
||||
/// <summary>
|
||||
/// This sets a scene for the window to use.
|
||||
/// </summary>
|
||||
/// <param name="scene"></param>
|
||||
void SetScene(GenericScene scene);
|
||||
/// <summary>
|
||||
/// This sets a render pipeline, from where the scene gets rendered.
|
||||
/// </summary>
|
||||
/// <param name="renderPipeline"></param>
|
||||
void SetRenderPipeline(RenderPipeline renderPipeline);
|
||||
|
||||
/// <summary>
|
||||
/// This triggeres the <see cref="Load"/> event.
|
||||
/// </summary>
|
||||
void TriggerLoad();
|
||||
/// <summary>
|
||||
/// This triggeres the <see cref="Resize"/> event.
|
||||
/// </summary>
|
||||
void TriggerResize();
|
||||
|
||||
/// <summary>
|
||||
/// This closes the window.
|
||||
/// </summary>
|
||||
void Close();
|
||||
}
|
||||
}
|
||||
|
|
@ -53,9 +53,10 @@ namespace SM.Base.Window
|
|||
/// <inheritdoc/>
|
||||
public virtual void Initialization()
|
||||
{
|
||||
MainFramebuffer.Name = GetType().Name + ".MainFramebuffer";
|
||||
|
||||
if (MainFramebuffer != null) Framebuffers.Add(MainFramebuffer);
|
||||
if (MainFramebuffer != null) {
|
||||
Framebuffers.Add(MainFramebuffer);
|
||||
MainFramebuffer.Name = GetType().Name + ".MainFramebuffer";
|
||||
}
|
||||
DefaultShader ??= SMRenderer.DefaultMaterialShader;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -93,6 +93,7 @@ namespace SM.Base.Window
|
|||
internal static void Render(IGenericWindow window, float deltatime)
|
||||
{
|
||||
if (window.CurrentScene == null) return;
|
||||
if (window.CurrentRenderPipeline == null) window.SetRenderPipeline(SMRenderer.DefaultRenderPipeline);
|
||||
|
||||
SMRenderer.CurrentFrame++;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,8 +1,4 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<packages>
|
||||
<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" />
|
||||
<package id="OpenTK" version="3.3.1" targetFramework="net452" />
|
||||
</packages>
|
||||
|
|
@ -14,7 +14,7 @@ namespace SM.OGL.Framebuffer
|
|||
/// </summary>
|
||||
public class ColorAttachment : TextureBase
|
||||
{
|
||||
private int _multisamples;
|
||||
private readonly int _multisamples;
|
||||
|
||||
/// <summary>
|
||||
/// The ID the attachment was given.
|
||||
|
|
@ -50,6 +50,12 @@ namespace SM.OGL.Framebuffer
|
|||
public ColorAttachment(int attachmentId) : this(attachmentId, PixelInformation.RGBA_LDR)
|
||||
{ }
|
||||
|
||||
/// <summary>
|
||||
/// Creates a color attachment with a specific id, specific pixel informations and multisamples.
|
||||
/// </summary>
|
||||
/// <param name="attachmentID"></param>
|
||||
/// <param name="pixelInformation"></param>
|
||||
/// <param name="multisamples"></param>
|
||||
public ColorAttachment(int attachmentID, PixelInformation pixelInformation, int multisamples = 0)
|
||||
{
|
||||
AttachmentID = attachmentID;
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ namespace SM.OGL.Framebuffer
|
|||
/// </summary>
|
||||
public class Framebuffer : GLObject
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override bool AutoCompile { get; set; } = true;
|
||||
|
||||
public static IFramebufferWindow ScreenWindow;
|
||||
|
|
@ -30,8 +31,8 @@ namespace SM.OGL.Framebuffer
|
|||
_windowScale = 1,
|
||||
};
|
||||
|
||||
private IFramebufferWindow _window;
|
||||
private float _windowScale;
|
||||
private readonly IFramebufferWindow _window;
|
||||
private readonly float _windowScale;
|
||||
|
||||
/// <inheritdoc />
|
||||
public override ObjectLabelIdentifier TypeIdentifier { get; } = ObjectLabelIdentifier.Framebuffer;
|
||||
|
|
@ -46,7 +47,9 @@ namespace SM.OGL.Framebuffer
|
|||
/// </summary>
|
||||
public Dictionary<string, ColorAttachment> ColorAttachments { get; private set; } =
|
||||
new Dictionary<string, ColorAttachment>();
|
||||
|
||||
/// <summary>
|
||||
/// Contains the current renderbuffer attachments of the framebuffer.
|
||||
/// </summary>
|
||||
public Dictionary<RenderbufferAttachment, int> RenderbufferAttachments { get; } = new Dictionary<RenderbufferAttachment, int>();
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -143,6 +146,10 @@ namespace SM.OGL.Framebuffer
|
|||
ColorAttachments.Add(key, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Appends a renderbuffer attachment to the framebuffer.
|
||||
/// </summary>
|
||||
/// <param name="attachment"></param>
|
||||
public void AppendRenderbuffer(RenderbufferAttachment attachment)
|
||||
{
|
||||
RenderbufferAttachments.Add(attachment, -1);
|
||||
|
|
@ -185,6 +192,11 @@ namespace SM.OGL.Framebuffer
|
|||
GL.Clear(clear);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a <see cref="Framebuffer"/> handle of the current framebuffer.
|
||||
/// </summary>
|
||||
/// <param name="target"></param>
|
||||
/// <returns></returns>
|
||||
public static Framebuffer GetCurrentlyActive(FramebufferTarget target = FramebufferTarget.Framebuffer)
|
||||
{
|
||||
Framebuffer buffer = new Framebuffer()
|
||||
|
|
|
|||
|
|
@ -5,7 +5,13 @@
|
|||
/// </summary>
|
||||
public interface IFramebufferWindow
|
||||
{
|
||||
/// <summary>
|
||||
/// The width of the window.
|
||||
/// </summary>
|
||||
int Width { get; }
|
||||
/// <summary>
|
||||
/// The height of the window.
|
||||
/// </summary>
|
||||
int Height { get; }
|
||||
}
|
||||
}
|
||||
|
|
@ -14,20 +14,30 @@ namespace SM.OGL
|
|||
/// </summary>
|
||||
public abstract class GLObject
|
||||
{
|
||||
private static List<GLObject> _disposableObjects = new List<GLObject>();
|
||||
private static readonly List<GLObject> _disposableObjects = new List<GLObject>();
|
||||
private string _name = "";
|
||||
|
||||
protected bool ReportAsNotCompiled;
|
||||
|
||||
/// <summary>
|
||||
/// Contains the OpenGL ID
|
||||
/// </summary>
|
||||
protected int _id = -1;
|
||||
|
||||
/// <summary>
|
||||
/// This can mark the object to never report as compiled, even when it was.
|
||||
/// <para>You can still figure out, if it was compiled by checking <see cref="_id"/>. If not -1, its compiled.</para>
|
||||
/// <para>Default: false</para>
|
||||
/// </summary>
|
||||
protected bool ReportAsNotCompiled;
|
||||
/// <summary>
|
||||
/// This can prevent the object to compile.
|
||||
/// <para>Default: true</para>
|
||||
/// </summary>
|
||||
protected bool CanCompile = true;
|
||||
|
||||
/// <summary>
|
||||
/// If true, the system will call "Compile()", when "ID" is tried to get, but the id is still -1.
|
||||
/// <para>Default: false</para>
|
||||
/// </summary>
|
||||
protected virtual bool AutoCompile { get; set; } = false;
|
||||
|
||||
|
|
@ -36,6 +46,10 @@ namespace SM.OGL
|
|||
/// </summary>
|
||||
public bool WasCompiled => _id > 0 && !ReportAsNotCompiled;
|
||||
|
||||
/// <summary>
|
||||
/// Names the object
|
||||
/// <para>If <see cref="GLSystem.Debugging"/> is true, then it will also name the object in the system.</para>
|
||||
/// </summary>
|
||||
public string Name
|
||||
{
|
||||
get => _name;
|
||||
|
|
@ -111,11 +125,15 @@ namespace SM.OGL
|
|||
Compile();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string ToString()
|
||||
{
|
||||
return $"{GetType().Name} {(string.IsNullOrEmpty(_name) ? "" : $"\"{_name}\" ")}[{_id}]";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This disposes the current objects, that where marked by the garbage collector.
|
||||
/// </summary>
|
||||
public static void DisposeMarkedObjects()
|
||||
{
|
||||
foreach (GLObject o in _disposableObjects)
|
||||
|
|
@ -134,6 +152,9 @@ namespace SM.OGL
|
|||
return glo.ID;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// If the garbage collector is trying to remove this object, it will add the object to a list, what get removed when <see cref="DisposeMarkedObjects"/> is called.
|
||||
/// </summary>
|
||||
~GLObject()
|
||||
{
|
||||
if (WasCompiled) _disposableObjects.Add(this);
|
||||
|
|
|
|||
|
|
@ -49,21 +49,59 @@ namespace SM.OGL.Mesh
|
|||
/// <returns></returns>
|
||||
public Vector3 this[bool x, bool y, bool z] => Get(x,y,z);
|
||||
|
||||
/// <summary>
|
||||
/// Equivalent to <see cref="this"/>.
|
||||
/// <para>Returns specific configurations of corners</para>
|
||||
/// </summary>
|
||||
/// <param name="x">If true, it takes the X-value of maximum, otherwise the minimum.</param>
|
||||
/// <param name="y">If true, it takes the Y-value of maximum, otherwise the minimum.</param>
|
||||
/// <param name="z">If true, it takes the Z-value of maximum, otherwise the minimum.</param>
|
||||
/// <returns></returns>
|
||||
public Vector3 Get(bool x, bool y, bool z)
|
||||
{
|
||||
return new Vector3(x ? Max.X : Min.X, y ? Max.Y : Min.Y, z ? Max.Z : Min.Z);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the configuration of the two furthest away corners.
|
||||
/// </summary>
|
||||
/// <param name="xyz">If true, it will take the maximum, otherwise the minimum.</param>
|
||||
/// <returns></returns>
|
||||
public Vector3 Get(bool xyz) => Get(xyz, xyz, xyz);
|
||||
|
||||
/// <summary>
|
||||
/// Returns the configuration of one corner and applies a transformation to it.
|
||||
/// <para>If the transformation causes the points to shift to no being in the right location is NOT checked!</para>
|
||||
/// <para>For that use <see cref="GetBounds"/></para>
|
||||
/// </summary>
|
||||
/// <param name="transformation">The transformation</param>
|
||||
/// <param name="x">If true, it takes the X-value of maximum, otherwise the minimum.</param>
|
||||
/// <param name="y">If true, it takes the Y-value of maximum, otherwise the minimum.</param>
|
||||
/// <param name="z">If true, it takes the Z-value of maximum, otherwise the minimum.</param>
|
||||
/// <returns></returns>
|
||||
public Vector3 Get(Matrix4 transformation, bool x, bool y, bool z)
|
||||
{
|
||||
Vector3 get = Get(x, y, z);
|
||||
return (new Vector4(get, 1) * transformation).Xyz;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the configuration of the two furthest away corners.
|
||||
/// <para>If the transformation causes the points to shift to no being in the right location is NOT checked!</para>
|
||||
/// <para>For that use <see cref="GetBounds"/></para>
|
||||
/// </summary>
|
||||
/// <param name="transformation">The transformation</param>
|
||||
/// <param name="xyz">If true, it will take the maximum, otherwise the minimum.</param>
|
||||
/// <returns></returns>
|
||||
public Vector3 Get(Matrix4 transformation, bool xyz) => Get(transformation, xyz, xyz, xyz);
|
||||
|
||||
/// <summary>
|
||||
/// Returns the bounds of the bounding box while applying a transformation.
|
||||
/// <para>This takes care of min and max locations.</para>
|
||||
/// </summary>
|
||||
/// <param name="transformation"></param>
|
||||
/// <param name="min"></param>
|
||||
/// <param name="max"></param>
|
||||
public void GetBounds(Matrix4 transformation, out Vector3 min, out Vector3 max)
|
||||
{
|
||||
min = Get(transformation, false);
|
||||
|
|
@ -79,6 +117,10 @@ namespace SM.OGL.Mesh
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates the bounding box to the mesh provided.
|
||||
/// </summary>
|
||||
/// <param name="mesh"></param>
|
||||
public void Update(GenericMesh mesh)
|
||||
{
|
||||
int pos = 0;
|
||||
|
|
|
|||
|
|
@ -14,8 +14,6 @@ namespace SM.OGL.Mesh
|
|||
{
|
||||
private bool _boundingBoxUpdated = false;
|
||||
|
||||
public static int LastID { get; internal set; } = -1;
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override bool AutoCompile { get; set; } = true;
|
||||
|
||||
|
|
@ -71,12 +69,18 @@ namespace SM.OGL.Mesh
|
|||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates the object bounding box.
|
||||
/// </summary>
|
||||
public void UpdateBoundingBox()
|
||||
{
|
||||
BoundingBox.Update(this);
|
||||
_boundingBoxUpdated = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Activates the object to be rendered.
|
||||
/// </summary>
|
||||
public void Activate()
|
||||
{
|
||||
GL.BindVertexArray(ID);
|
||||
|
|
@ -99,6 +103,7 @@ namespace SM.OGL.Mesh
|
|||
GL.BindVertexArray(0);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void Dispose()
|
||||
{
|
||||
GL.DeleteVertexArray(_id);
|
||||
|
|
|
|||
|
|
@ -18,6 +18,12 @@
|
|||
/// </summary>
|
||||
public VBO ConnectedVBO;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a attribute for a mesh.
|
||||
/// </summary>
|
||||
/// <param name="index"></param>
|
||||
/// <param name="name"></param>
|
||||
/// <param name="buffer"></param>
|
||||
public MeshAttribute(int index, string name, VBO buffer)
|
||||
{
|
||||
Index = index;
|
||||
|
|
|
|||
|
|
@ -49,6 +49,11 @@ namespace SM.OGL.Mesh
|
|||
Add(new MeshAttribute(id, name, vbo));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if the attribute list has the attribute name.
|
||||
/// </summary>
|
||||
/// <param name="name"></param>
|
||||
/// <returns></returns>
|
||||
public bool Has(string name)
|
||||
{
|
||||
VBO attribute = this[name];
|
||||
|
|
|
|||
|
|
@ -139,6 +139,10 @@ namespace SM.OGL.Mesh
|
|||
Add(vector.X, vector.Y, z, w);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds a array of vector2s.
|
||||
/// </summary>
|
||||
/// <param name="vectors"></param>
|
||||
public void Add(params Vector2[] vectors)
|
||||
{
|
||||
foreach (Vector2 vector in vectors)
|
||||
|
|
@ -163,6 +167,10 @@ namespace SM.OGL.Mesh
|
|||
Add(vector.X, vector.Y, vector.Z, w);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds a array of Vector3s.
|
||||
/// </summary>
|
||||
/// <param name="vectors"></param>
|
||||
public void Add(params Vector3[] vectors)
|
||||
{
|
||||
foreach (Vector3 vector in vectors)
|
||||
|
|
|
|||
|
|
@ -70,6 +70,11 @@ namespace SM.OGL.Shaders
|
|||
ShaderFileFiles = new ShaderFileCollection(vertex,fragment, geometry);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a shader out of a vertex and an fragment shader.
|
||||
/// </summary>
|
||||
/// <param name="vertex"></param>
|
||||
/// <param name="fragment"></param>
|
||||
protected GenericShader(string vertex, string fragment) : this(new ShaderFileCollection(vertex, fragment)){}
|
||||
|
||||
/// <inheritdoc />
|
||||
|
|
@ -81,6 +86,10 @@ namespace SM.OGL.Shaders
|
|||
/// <inheritdoc />
|
||||
public override ObjectLabelIdentifier TypeIdentifier { get; } = ObjectLabelIdentifier.Program;
|
||||
|
||||
/// <summary>
|
||||
/// Updates the shader files and recompiles the shader.
|
||||
/// </summary>
|
||||
/// <param name="newShaderFiles"></param>
|
||||
public void Update(ShaderFileCollection newShaderFiles)
|
||||
{
|
||||
ShaderFileFiles = newShaderFiles;
|
||||
|
|
@ -104,6 +113,9 @@ namespace SM.OGL.Shaders
|
|||
GLDebugging.CheckGLErrors($"A error occured at shader creation for '{GetType()}': %code%");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Activates the shader
|
||||
/// </summary>
|
||||
public void Activate()
|
||||
{
|
||||
GL.UseProgram(ID);
|
||||
|
|
@ -115,6 +127,7 @@ namespace SM.OGL.Shaders
|
|||
Load();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void Dispose()
|
||||
{
|
||||
GL.DeleteProgram(this);
|
||||
|
|
@ -136,14 +149,15 @@ namespace SM.OGL.Shaders
|
|||
/// <summary>
|
||||
/// Draws the mesh while forcing a primitive type instead of using the mesh type.
|
||||
/// </summary>
|
||||
/// <param name="modelType">The type, as what the object should be rendered.</param>
|
||||
/// <param name="mesh">The mesh.</param>
|
||||
/// <param name="amount">The amounts for instancing.</param>
|
||||
public static void DrawObject(PrimitiveType forcedType, GenericMesh mesh, int amount = 1)
|
||||
public static void DrawObject(PrimitiveType modelType, GenericMesh mesh, int amount = 1)
|
||||
{
|
||||
if (mesh.Indices != null)
|
||||
GL.DrawElementsInstanced(forcedType, 0, DrawElementsType.UnsignedInt, mesh.Indices, amount);
|
||||
GL.DrawElementsInstanced(modelType, 0, DrawElementsType.UnsignedInt, mesh.Indices, amount);
|
||||
else
|
||||
GL.DrawArraysInstanced(forcedType, 0, mesh.Vertex.Count / mesh.Vertex.PointerSize, amount);
|
||||
GL.DrawArraysInstanced(modelType, 0, mesh.Vertex.Count / mesh.Vertex.PointerSize, amount);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
|||
|
|
@ -2,28 +2,51 @@
|
|||
|
||||
namespace SM.OGL.Shaders
|
||||
{
|
||||
/// <summary>
|
||||
/// This class controls uniform array structures.
|
||||
/// </summary>
|
||||
public class UniformArray : IUniform
|
||||
{
|
||||
private Dictionary<int, Dictionary<string, Uniform>> storedUniforms = new Dictionary<int, Dictionary<string, Uniform>>();
|
||||
internal List<string> uniformNames = new List<string>();
|
||||
private readonly Dictionary<int, Dictionary<string, Uniform>> storedUniforms = new Dictionary<int, Dictionary<string, Uniform>>();
|
||||
internal List<string> UniformNames = new List<string>();
|
||||
|
||||
/// <inheritdoc />
|
||||
public int Location { get; internal set; }
|
||||
/// <summary>
|
||||
/// The name of the uniform.
|
||||
/// </summary>
|
||||
public string Name { get; internal set; }
|
||||
/// <summary>
|
||||
/// The uniform collection the uniform is from.
|
||||
/// </summary>
|
||||
public UniformCollection Parent { get; internal set; }
|
||||
/// <summary>
|
||||
/// The shader the uniform is from.
|
||||
/// </summary>
|
||||
public GenericShader ParentShader { get; internal set; }
|
||||
/// <summary>
|
||||
/// The length of the array.
|
||||
/// </summary>
|
||||
public int Length => storedUniforms.Count;
|
||||
|
||||
/// <summary>
|
||||
/// Returns a dictionary to control the current index inside the array.
|
||||
/// </summary>
|
||||
public Dictionary<string, Uniform> this[int index] => Get(index);
|
||||
|
||||
/// <summary>
|
||||
/// Equivalent to <see cref="this"/>
|
||||
/// <para>Returns a dictionary to control the current index inside the array.</para>
|
||||
/// </summary>
|
||||
public Dictionary<string, Uniform> Get(int index)
|
||||
{
|
||||
if (!storedUniforms.ContainsKey(index))
|
||||
{
|
||||
Dictionary<string, Uniform> dic = storedUniforms[index] = new Dictionary<string, Uniform>();
|
||||
|
||||
for (int i = 0; i < uniformNames.Count; i++)
|
||||
for (int i = 0; i < UniformNames.Count; i++)
|
||||
{
|
||||
dic.Add(uniformNames[i], new Uniform(Name + $"[{index}]." + uniformNames[i], ParentShader, Parent));
|
||||
dic.Add(UniformNames[i], new Uniform(Name + $"[{index}]." + UniformNames[i], ParentShader, Parent));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -8,14 +8,34 @@ using OpenTK.Graphics.OpenGL4;
|
|||
|
||||
namespace SM.OGL.Shaders
|
||||
{
|
||||
/// <summary>
|
||||
/// Collects and provied the uniforms of a shader.
|
||||
/// </summary>
|
||||
public class UniformCollection : Dictionary<string, IUniform>
|
||||
{
|
||||
public int NextTexture = 0;
|
||||
internal string KeyString = "";
|
||||
/// <summary>
|
||||
/// The next uniform-position for textures.
|
||||
/// </summary>
|
||||
public int NextTexture = 0;
|
||||
/// <summary>
|
||||
/// The shader this collections is connected to.
|
||||
/// </summary>
|
||||
public GenericShader ParentShader { get; internal set; }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="key"></param>
|
||||
public new Uniform this[string key] => Get(key);
|
||||
|
||||
/// <summary>
|
||||
/// Equivalent to <see cref="this"/>
|
||||
/// <para>Gets the uniform with the provied key.</para>
|
||||
/// <para>If it can't find it, it will create a warning and a uniform with the location of -1.</para>
|
||||
/// </summary>
|
||||
/// <param name="key"></param>
|
||||
/// <returns></returns>
|
||||
public Uniform Get(string key)
|
||||
{
|
||||
try
|
||||
|
|
@ -31,18 +51,22 @@ namespace SM.OGL.Shaders
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a array.
|
||||
/// </summary>
|
||||
/// <param name="key"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="KeyNotFoundException">If the key wasn't found, it will throw a exception</exception>
|
||||
public UniformArray GetArray(string key)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (ContainsKey(key))
|
||||
return (UniformArray) base[key];
|
||||
}
|
||||
catch (KeyNotFoundException)
|
||||
{
|
||||
throw new Exception("UniformArray '"+key+"' wasn't found");
|
||||
}
|
||||
else throw new KeyNotFoundException("UniformArray '"+key+"' wasn't found");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds a uniform to the collection.
|
||||
/// </summary>
|
||||
public void Add(string key, int location)
|
||||
{
|
||||
base.Add(key, new Uniform(location, this));
|
||||
|
|
@ -101,7 +125,7 @@ namespace SM.OGL.Shaders
|
|||
}
|
||||
|
||||
if (keySplits[1] == "0")
|
||||
array.uniformNames.Add(keySplits[2].Substring(1));
|
||||
array.UniformNames.Add(keySplits[2].Substring(1));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
|||
|
|
@ -8,8 +8,14 @@ using SM2D.Types;
|
|||
|
||||
namespace SM2D.Controls
|
||||
{
|
||||
/// <summary>
|
||||
/// Contains special methods for the mouse.
|
||||
/// </summary>
|
||||
public class Mouse2D
|
||||
{
|
||||
/// <summary>
|
||||
/// Returns the current position of the mouse inside the world.
|
||||
/// </summary>
|
||||
public static Vector2 InWorld(Vector2 worldScale)
|
||||
{
|
||||
var res = worldScale;
|
||||
|
|
@ -17,28 +23,63 @@ namespace SM2D.Controls
|
|||
return Mouse.InScreenNormalized * res - res / 2;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the current position of the mouse inside the world.
|
||||
/// </summary>
|
||||
public static Vector2 InWorld(Camera cam)
|
||||
{
|
||||
return InWorld(cam.WorldScale) + cam.Position;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the current position of the mouse inside the world.
|
||||
/// </summary>
|
||||
public static Vector2 InWorld(Vector2 worldScale, Vector2 position)
|
||||
{
|
||||
return InWorld(worldScale) + position;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if the mouse is over an object.
|
||||
/// </summary>
|
||||
/// <param name="mousePos">The position in the world. See <see cref="InWorld(Camera)"/></param>
|
||||
/// <param name="checkingObjects"></param>
|
||||
/// <typeparam name="TObject"></typeparam>
|
||||
public static bool MouseOver<TObject>(Vector2 mousePos, params TObject[] checkingObjects)
|
||||
where TObject : IModelItem, ITransformItem<Transformation>
|
||||
=> MouseOver(mousePos, out _, checkingObjects);
|
||||
|
||||
/// <summary>
|
||||
/// Checks if the mouse is over an object.
|
||||
/// </summary>
|
||||
/// <param name="mousePos">The position in the world. See <see cref="InWorld(Camera)"/></param>
|
||||
/// <param name="checkingObjects"></param>
|
||||
/// <typeparam name="TObject"></typeparam>
|
||||
/// <returns></returns>
|
||||
public static bool MouseOver<TObject>(Vector2 mousePos, ICollection<TObject> checkingObjects)
|
||||
where TObject : IModelItem, ITransformItem<Transformation>
|
||||
=> MouseOver<TObject>(mousePos, out _, checkingObjects);
|
||||
|
||||
/// <summary>
|
||||
/// Checks if the mouse is over an object and returns the object that was clicked on.
|
||||
/// </summary>
|
||||
/// <param name="mousePos">The position in the world. See <see cref="InWorld(Camera)"/></param>
|
||||
/// <param name="clicked"></param>
|
||||
/// <param name="checkingObjects"></param>
|
||||
/// <typeparam name="TObject"></typeparam>
|
||||
/// <returns></returns>
|
||||
public static bool MouseOver<TObject>(Vector2 mousePos, out TObject clicked, params TObject[] checkingObjects)
|
||||
where TObject : IModelItem, ITransformItem<Transformation>
|
||||
=> MouseOver<TObject>(mousePos, out clicked, (ICollection<TObject>)checkingObjects);
|
||||
|
||||
/// <summary>
|
||||
/// Checks if the mouse is over an object and returns the object that was clicked on.
|
||||
/// </summary>
|
||||
/// <param name="mousePos">The position in the world. See <see cref="InWorld(Camera)"/></param>
|
||||
/// <param name="clickedObj"></param>
|
||||
/// <param name="checkingObjects"></param>
|
||||
/// <typeparam name="TObject"></typeparam>
|
||||
/// <returns></returns>
|
||||
public static bool MouseOver<TObject>(Vector2 mousePos, out TObject clickedObj, ICollection<TObject> checkingObjects)
|
||||
where TObject : IModelItem, ITransformItem<Transformation>
|
||||
{
|
||||
|
|
@ -70,6 +111,13 @@ namespace SM2D.Controls
|
|||
return success;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if the mouse is over an object and returns the object that was clicked on.
|
||||
/// </summary>
|
||||
/// <param name="mousePos">The position in the world. See <see cref="InWorld(Camera)"/></param>
|
||||
/// <param name="boundingBox"></param>
|
||||
/// <param name="transform"></param>
|
||||
/// <returns></returns>
|
||||
public static bool MouseOver(Vector2 mousePos, BoundingBox boundingBox, Transformation transform)
|
||||
{
|
||||
Matrix4 worldPos = transform.InWorldSpace;
|
||||
|
|
|
|||
|
|
@ -14,14 +14,23 @@ using SM2D.Scene;
|
|||
|
||||
namespace SM2D.Drawing
|
||||
{
|
||||
/// <summary>
|
||||
/// Allows easy access to draw something on the background.
|
||||
/// </summary>
|
||||
public class DrawBackground : DrawingBasis, IBackgroundItem
|
||||
{
|
||||
/// <summary>
|
||||
/// Sets the color or tint (in case a texture is set).
|
||||
/// </summary>
|
||||
public Color4 Color
|
||||
{
|
||||
get => Material.Tint;
|
||||
set => Material.Tint = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the texture of the background.
|
||||
/// </summary>
|
||||
public TextureBase Texture
|
||||
{
|
||||
get => Material.Texture;
|
||||
|
|
@ -32,18 +41,34 @@ namespace SM2D.Drawing
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a black background.
|
||||
/// </summary>
|
||||
public DrawBackground() : this(Color4.Black) {}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a background with a color.
|
||||
/// </summary>
|
||||
/// <param name="color"></param>
|
||||
public DrawBackground(Color4 color)
|
||||
{
|
||||
Color = color;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a background with a texture.
|
||||
/// </summary>
|
||||
/// <param name="texture"></param>
|
||||
public DrawBackground(Bitmap texture)
|
||||
{
|
||||
Texture = (Texture) texture;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a background with a texture and a tint.
|
||||
/// </summary>
|
||||
/// <param name="texture"></param>
|
||||
/// <param name="tint"></param>
|
||||
public DrawBackground(Bitmap texture, Color4 tint)
|
||||
{
|
||||
Color = tint;
|
||||
|
|
@ -51,6 +76,7 @@ namespace SM2D.Drawing
|
|||
}
|
||||
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void DrawContext(ref DrawContext context)
|
||||
{
|
||||
base.DrawContext(ref context);
|
||||
|
|
|
|||
|
|
@ -10,46 +10,72 @@ using SM2D.Types;
|
|||
|
||||
namespace SM2D.Drawing
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public class DrawObject2D : DrawingBasis<Transformation>
|
||||
{
|
||||
/// <summary>
|
||||
/// The texture the object should use.
|
||||
/// </summary>
|
||||
public Texture Texture
|
||||
{
|
||||
get => (Texture) Material.Texture;
|
||||
set => Material.Texture = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The color or tint the object should use.
|
||||
/// </summary>
|
||||
public Color4 Color
|
||||
{
|
||||
get => Material.Tint;
|
||||
set => Material.Tint = value;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void DrawContext(ref DrawContext context)
|
||||
{
|
||||
base.DrawContext(ref context);
|
||||
context.Shader.Draw(context);
|
||||
}
|
||||
|
||||
public void SetShader(MaterialShader shader) => Material.CustomShader = shader;
|
||||
/// <summary>
|
||||
/// Applies a polygon to the object.
|
||||
/// </summary>
|
||||
/// <param name="vertices"></param>
|
||||
/// <returns></returns>
|
||||
public Polygon ApplyPolygon(ICollection<Vector2> vertices)
|
||||
{
|
||||
Polygon polygon = new Polygon(vertices);
|
||||
Mesh = polygon;
|
||||
return polygon;
|
||||
}
|
||||
|
||||
public Polygon ApplyPolygon(ICollection<Vector2> vertices, bool centerUVs = false)
|
||||
{
|
||||
Polygon polygon = new Polygon(vertices);
|
||||
Mesh = polygon;
|
||||
return polygon;
|
||||
}
|
||||
public Polygon ApplyPolygon(ICollection<PolygonVertex> vertices, bool centerUVs = false)
|
||||
/// <summary>
|
||||
/// Applies a polygon to the object.
|
||||
/// </summary>
|
||||
/// <param name="vertices"></param>
|
||||
/// <returns></returns>
|
||||
public Polygon ApplyPolygon(ICollection<PolygonVertex> vertices)
|
||||
{
|
||||
Polygon polygon = new Polygon(vertices);
|
||||
Mesh = polygon;
|
||||
return polygon;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Applies a polygon to the object.
|
||||
/// </summary>
|
||||
public void ApplyPolygon(Polygon polygon)
|
||||
{
|
||||
Mesh = polygon;
|
||||
}
|
||||
|
||||
public Polygon ApplyCircle(int segments = 32, bool centerUVs = false)
|
||||
/// <summary>
|
||||
/// This applies a circle.
|
||||
/// </summary>
|
||||
/// <param name="segments"></param>
|
||||
/// <returns></returns>
|
||||
public Polygon ApplyCircle(int segments = 32)
|
||||
{
|
||||
Polygon pol = Polygon.GenerateCircle(segments);
|
||||
Mesh = pol;
|
||||
|
|
|
|||
|
|
@ -6,14 +6,20 @@ using SM2D.Types;
|
|||
|
||||
namespace SM2D.Drawing
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates particles.
|
||||
/// </summary>
|
||||
public class DrawParticles : ParticleDrawingBasis<Transformation, Vector2>
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public override Func<Vector2, ParticleContext, Vector2> MovementCalculation { get; set; } = ParticleMovement.Default2D;
|
||||
|
||||
/// <inheritdoc />
|
||||
public DrawParticles(TimeSpan duration) : base(duration)
|
||||
{
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override ParticleStruct<Vector2> CreateObject(int index)
|
||||
{
|
||||
return new ParticleStruct<Vector2>()
|
||||
|
|
@ -24,6 +30,7 @@ namespace SM2D.Drawing
|
|||
};
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override Matrix4 CreateMatrix(ParticleStruct<Vector2> Struct, Vector2 direction)
|
||||
{
|
||||
return Struct.Matrix * Matrix4.CreateTranslation(direction.X, direction.Y, 0);
|
||||
|
|
|
|||
|
|
@ -9,14 +9,21 @@ using SM2D.Types;
|
|||
|
||||
namespace SM2D.Drawing
|
||||
{
|
||||
/// <summary>
|
||||
/// Draws a text to the world.
|
||||
/// </summary>
|
||||
public class DrawText : TextDrawingBasis<Transformation>
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a text object.
|
||||
/// </summary>
|
||||
public DrawText(Font font, string text) : base(font)
|
||||
{
|
||||
_text = text;
|
||||
Transform.Size = new CVector2(1);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void DrawContext(ref DrawContext context)
|
||||
{
|
||||
base.DrawContext(ref context);
|
||||
|
|
|
|||
|
|
@ -5,15 +5,36 @@ using SM.OGL.Mesh;
|
|||
|
||||
namespace SM2D.Object
|
||||
{
|
||||
/// <summary>
|
||||
/// Allows different type of lines.
|
||||
/// </summary>
|
||||
public enum PolyLineType
|
||||
{
|
||||
/// <summary>
|
||||
/// Those lines are not connected to each other.
|
||||
/// <para>Every two points starts a new line.</para>
|
||||
/// </summary>
|
||||
NotConnected = 1,
|
||||
/// <summary>
|
||||
/// Those lines are connected with each other, but don't connect the start and the end.
|
||||
/// </summary>
|
||||
Connected = 3,
|
||||
/// <summary>
|
||||
/// Those lines are connected and they connect start and end.
|
||||
/// </summary>
|
||||
ConnectedLoop = 2
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates new poly line.
|
||||
/// </summary>
|
||||
public class PolyLine : Polygon, ILineMesh
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a new polyline by using <see cref="Vector2"/>.
|
||||
/// </summary>
|
||||
/// <param name="vertices"></param>
|
||||
/// <param name="lineType"></param>
|
||||
public PolyLine(ICollection<Vector2> vertices, PolyLineType lineType = PolyLineType.NotConnected) : base(vertices)
|
||||
{
|
||||
UVs.Active = false;
|
||||
|
|
@ -21,6 +42,11 @@ namespace SM2D.Object
|
|||
PrimitiveType = (PrimitiveType)lineType;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new polyline by using <see cref="PolygonVertex"/>.
|
||||
/// </summary>
|
||||
/// <param name="vertices"></param>
|
||||
/// <param name="lineType"></param>
|
||||
public PolyLine(ICollection<PolygonVertex> vertices, PolyLineType lineType = PolyLineType.NotConnected) : base(vertices)
|
||||
{
|
||||
UVs.Active = false;
|
||||
|
|
|
|||
|
|
@ -11,8 +11,27 @@ using SM.OGL.Mesh;
|
|||
|
||||
namespace SM2D.Object
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a polygon.
|
||||
/// </summary>
|
||||
public class Polygon : Mesh
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public override VBO Vertex { get; protected set; } = new VBO();
|
||||
|
||||
/// <inheritdoc />
|
||||
public override VBO UVs { get; protected set; } = new VBO(pointerSize: 2);
|
||||
|
||||
/// <inheritdoc />
|
||||
public override VBO Color { get; protected set; } = new VBO(pointerSize: 4);
|
||||
|
||||
/// <inheritdoc />
|
||||
public override PrimitiveType PrimitiveType { get; protected set; } = PrimitiveType.TriangleFan;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a polygon with <see cref="Vector2"/>s.
|
||||
/// </summary>
|
||||
/// <param name="vertices"></param>
|
||||
public Polygon(ICollection<Vector2> vertices) : base(PrimitiveType.TriangleFan)
|
||||
{
|
||||
Color.Active = false;
|
||||
|
|
@ -27,25 +46,23 @@ namespace SM2D.Object
|
|||
if (UVs.Active) foreach (var vertex in vertices) AddUV(vertex);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a polygon with <see cref="PolygonVertex"/>, what allows colors hard coded.
|
||||
/// </summary>
|
||||
/// <param name="vertices"></param>
|
||||
public Polygon(ICollection<PolygonVertex> vertices) : base(PrimitiveType.TriangleFan)
|
||||
{
|
||||
foreach (var polygonVertex in vertices)
|
||||
{
|
||||
Color.Add(polygonVertex.Color);
|
||||
Vertex.Add(polygonVertex.Vertex, 0);
|
||||
Vertex.Add(polygonVertex.Position, 0);
|
||||
}
|
||||
|
||||
UpdateBoundingBox();
|
||||
|
||||
if (UVs.Active) foreach (var vertex in vertices) AddUV(vertex.Vertex);
|
||||
if (UVs.Active) foreach (var vertex in vertices) AddUV(vertex.Position);
|
||||
}
|
||||
|
||||
public override VBO Vertex { get; protected set; } = new VBO();
|
||||
public override VBO UVs { get; protected set; } = new VBO(pointerSize: 2);
|
||||
public override VBO Color { get; protected set; } = new VBO(pointerSize: 4);
|
||||
|
||||
public override PrimitiveType PrimitiveType { get; protected set; } = PrimitiveType.TriangleFan;
|
||||
|
||||
private void AddUV(Vector2 vertex)
|
||||
{
|
||||
var uv = Vector2.Divide(vertex - BoundingBox.Min.Xy, BoundingBox.Max.Xy - BoundingBox.Min.Xy);
|
||||
|
|
@ -53,6 +70,11 @@ namespace SM2D.Object
|
|||
UVs.Add(uv);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a circle.
|
||||
/// </summary>
|
||||
/// <param name="secments"></param>
|
||||
/// <returns></returns>
|
||||
public static Polygon GenerateCircle(int secments = 32)
|
||||
{
|
||||
var vertices = new List<Vector2> {Vector2.Zero};
|
||||
|
|
|
|||
|
|
@ -7,17 +7,36 @@ using OpenTK.Graphics;
|
|||
|
||||
namespace SM2D.Object
|
||||
{
|
||||
/// <summary>
|
||||
/// Allows storing more information inside a vertex.
|
||||
/// </summary>
|
||||
public struct PolygonVertex
|
||||
{
|
||||
public Vector2 Vertex;
|
||||
/// <summary>
|
||||
/// The position in the polygon.
|
||||
/// </summary>
|
||||
public Vector2 Position;
|
||||
/// <summary>
|
||||
/// The color of the vertex.
|
||||
/// </summary>
|
||||
public Color4 Color;
|
||||
|
||||
public PolygonVertex(Vector2 vertex = default, Color4 color = default)
|
||||
/// <summary>
|
||||
/// Creates a polygon vertex.
|
||||
/// </summary>
|
||||
/// <param name="position"></param>
|
||||
/// <param name="color"></param>
|
||||
public PolygonVertex(Vector2 position = default, Color4 color = default)
|
||||
{
|
||||
Vertex = vertex;
|
||||
Position = position;
|
||||
Color = color;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Automaticly translates Vector2s to PolygonVertex
|
||||
/// </summary>
|
||||
/// <param name="vec"></param>
|
||||
/// <returns></returns>
|
||||
public static implicit operator PolygonVertex(Vector2 vec) => new PolygonVertex(vec, Color4.White);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,18 +1,32 @@
|
|||
using SM.Base.Shaders;
|
||||
using OpenTK.Graphics.OpenGL4;
|
||||
using SM.Base.Shaders;
|
||||
using SM.Base.Window;
|
||||
using SM.OGL.Framebuffer;
|
||||
using SM2D.Shader;
|
||||
|
||||
namespace SM2D.Pipelines
|
||||
{
|
||||
/// <summary>
|
||||
/// This implements the most basic render pipeline.
|
||||
/// </summary>
|
||||
public class Basic2DPipeline : RenderPipeline
|
||||
{
|
||||
public static Basic2DPipeline Pipeline = new Basic2DPipeline();
|
||||
/// <summary>
|
||||
/// The access to the pipeline.
|
||||
/// </summary>
|
||||
public static Basic2DPipeline Pipeline =
|
||||
new Basic2DPipeline();
|
||||
|
||||
/// <inheritdoc />
|
||||
public override MaterialShader DefaultShader { get; protected set; } = ShaderCollection.Instanced;
|
||||
|
||||
private Basic2DPipeline() {}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void RenderProcess(ref DrawContext context)
|
||||
{
|
||||
Framebuffer.Screen.Activate(FramebufferTarget.Framebuffer, ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
|
||||
|
||||
context.Scene?.Draw(context);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,5 +35,4 @@ using System.Runtime.InteropServices;
|
|||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||
[assembly: AssemblyVersion("1.0.1.1")]
|
||||
|
|
@ -1,6 +1,5 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
|
|
@ -8,7 +7,7 @@
|
|||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>SM2D</RootNamespace>
|
||||
<AssemblyName>SM2D</AssemblyName>
|
||||
<AssemblyName>SMRenderer2D</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<Deterministic>true</Deterministic>
|
||||
|
|
@ -21,6 +20,7 @@
|
|||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<DocumentationFile>bin\Debug\SMRenderer2D.xml</DocumentationFile>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
|
|
@ -47,13 +47,11 @@
|
|||
<Compile Include="Pipelines\Basic2DPipeline.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Scene\Camera.cs" />
|
||||
<Compile Include="Scene\I2DShowItem.cs" />
|
||||
<Compile Include="Scene\ItemCollection.cs" />
|
||||
<Compile Include="Scene\Scene.cs" />
|
||||
<Compile Include="Shader\ShaderCollection.cs" />
|
||||
<Compile Include="Types\Transformation.cs" />
|
||||
<Compile Include="Window\Window2DSetup.cs" />
|
||||
<Compile Include="Window\I2DSetup.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\SM.Base\SM.Base.csproj">
|
||||
|
|
@ -69,9 +67,6 @@
|
|||
<PackageReference Include="OpenTK">
|
||||
<Version>3.3.1</Version>
|
||||
</PackageReference>
|
||||
<PackageReference Include="OpenTK.GLWpfControl">
|
||||
<Version>3.2.3</Version>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="Shader\ShaderFiles\basic.glsl" />
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ using SM.Base.Window;
|
|||
|
||||
namespace SM2D.Scene
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public class Camera : GenericCamera
|
||||
{
|
||||
internal static int ResizeCounter = 0;
|
||||
|
|
@ -19,6 +20,14 @@ namespace SM2D.Scene
|
|||
private bool _updateWorldScale = false;
|
||||
private Vector2? _requestedWorldScale = null;
|
||||
|
||||
/// <summary>
|
||||
/// This vector allows to request a world scale.
|
||||
/// <para>Following cases are possible. ("not set" means 0)</para>
|
||||
/// <para>None is set: It takes the window size.</para>
|
||||
/// <para>X is set: Y get calculated by the aspect ratio of the window.</para>
|
||||
/// <para>Y is set: X get calculated by the aspect ratio of the window.</para>
|
||||
/// <para>Both are set: Now the system try to keep a (invisible) rectangle in view, by increasing the width or height of the view, if needed.</para>
|
||||
/// </summary>
|
||||
public Vector2? RequestedWorldScale
|
||||
{
|
||||
get => _requestedWorldScale;
|
||||
|
|
@ -29,18 +38,32 @@ namespace SM2D.Scene
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The world scale that got calculated.
|
||||
/// </summary>
|
||||
public Vector2 WorldScale { get; private set; } = Vector2.Zero;
|
||||
|
||||
/// <summary>
|
||||
/// A event that gets triggered, when the world scale changed.
|
||||
/// <para>Possible causes: Window resizes, <see cref="RequestedWorldScale"/> changed</para>
|
||||
/// </summary>
|
||||
public event Action<Camera> WorldScaleChanged;
|
||||
|
||||
/// <summary>
|
||||
/// The position of the camera.
|
||||
/// </summary>
|
||||
public CVector2 Position = new CVector2(0);
|
||||
|
||||
/// <inheritdoc />
|
||||
public override bool Orthographic { get; } = true;
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override Matrix4 ViewCalculation(IGenericWindow window)
|
||||
{
|
||||
return Matrix4.LookAt(Position.X, Position.Y, Distance, Position.X, Position.Y, 0f, 0, 1, 0);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override bool WorldCalculation(IGenericWindow window, out Matrix4 world)
|
||||
{
|
||||
world = Matrix4.Identity;
|
||||
|
|
@ -57,6 +80,11 @@ namespace SM2D.Scene
|
|||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This calculates the world scale.
|
||||
/// <para>Usually gets called, by the camera itself, but if you need the world scale for additional calculations, you can execute it by yourself.</para>
|
||||
/// </summary>
|
||||
/// <param name="window"></param>
|
||||
public void CalculateWorldScale(IGenericWindow window)
|
||||
{
|
||||
if (RequestedWorldScale.HasValue)
|
||||
|
|
|
|||
|
|
@ -1,13 +0,0 @@
|
|||
#region usings
|
||||
|
||||
using SM.Base.Scene;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace SM2D.Scene
|
||||
{
|
||||
public interface I2DShowItem : IShowItem
|
||||
{
|
||||
int ZIndex { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
@ -2,23 +2,19 @@
|
|||
|
||||
using SM.Base.Scene;
|
||||
using SM.Base.Types;
|
||||
using SM.Base.Window;
|
||||
using SM2D.Types;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace SM2D.Scene
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public class ItemCollection : GenericItemCollection<Transformation>
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public ItemCollection()
|
||||
{
|
||||
Transform.Size = new CVector2(1);
|
||||
}
|
||||
|
||||
public override void Draw(DrawContext context)
|
||||
{
|
||||
base.Draw(context);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -11,17 +11,25 @@ using SM2D.Drawing;
|
|||
|
||||
namespace SM2D.Scene
|
||||
{
|
||||
/// <summary>
|
||||
/// The scene allows connecting different objects to render together.
|
||||
/// </summary>
|
||||
public class Scene : GenericScene<Camera, ItemCollection>
|
||||
{
|
||||
private static DrawObject2D _axisHelper;
|
||||
private static readonly DrawObject2D _axisHelper;
|
||||
|
||||
/// <summary>
|
||||
/// This determent how large the axishelper should be.
|
||||
/// </summary>
|
||||
public float AxisHelperSize = 100;
|
||||
static Scene()
|
||||
{
|
||||
_axisHelper = new DrawObject2D();
|
||||
_axisHelper.Mesh = AxisHelper.Object;
|
||||
_axisHelper = new DrawObject2D {Mesh = AxisHelper.Object};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This creates a new scene.
|
||||
/// </summary>
|
||||
public Scene()
|
||||
{
|
||||
_Background = new DrawBackground(Color4.Black);
|
||||
|
|
@ -32,12 +40,16 @@ namespace SM2D.Scene
|
|||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Gets/Sets the background.
|
||||
/// </summary>
|
||||
public DrawBackground Background
|
||||
{
|
||||
get => (DrawBackground) _Background;
|
||||
set => _Background = value;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void DrawHUD(DrawContext context)
|
||||
{
|
||||
context.ModelMatrix *= Matrix4.CreateTranslation(0,0,1);
|
||||
|
|
@ -45,6 +57,7 @@ namespace SM2D.Scene
|
|||
base.DrawHUD(context);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void DrawDebug(DrawContext context)
|
||||
{
|
||||
if (ShowAxisHelper)
|
||||
|
|
|
|||
|
|
@ -5,9 +5,15 @@ using SM.OGL.Shaders;
|
|||
|
||||
namespace SM2D.Shader
|
||||
{
|
||||
public class ShaderCollection
|
||||
class ShaderCollection
|
||||
{
|
||||
/// <summary>
|
||||
/// The most basic shader, that renders only one thing and only allows colors and one texture.
|
||||
/// </summary>
|
||||
public static SimpleShader Basic = new SimpleShader("basic", AssemblyUtility.ReadAssemblyFile("SM2D.Shader.ShaderFiles.basic.glsl"), SetUniforms);
|
||||
/// <summary>
|
||||
/// The same fragment shader as <see cref="Basic"/>, but allows to be instanced and used in (f.E.) text.
|
||||
/// </summary>
|
||||
public static SimpleShader Instanced = new SimpleShader("instanced", AssemblyUtility.ReadAssemblyFile("SM2D.Shader.ShaderFiles.basic.glsl"), SetUniforms);
|
||||
|
||||
static void SetUniforms(UniformCollection uniforms, DrawContext context)
|
||||
|
|
|
|||
|
|
@ -11,5 +11,4 @@ layout(location = 0) out vec4 color;
|
|||
void main() {
|
||||
color = v_Color * Tint;
|
||||
if (UseTexture) color *= texture(Texture, v_TexCoords);
|
||||
color *= 1.2;
|
||||
}
|
||||
|
|
@ -10,22 +10,46 @@ using SM.Base.Utility;
|
|||
|
||||
namespace SM2D.Types
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public class Transformation : GenericTransformation
|
||||
{
|
||||
public static int ZIndexPercision = 300;
|
||||
/// <summary>
|
||||
/// The precision of the Z-Index.
|
||||
/// <para>High values can result into "z-fighting" and cliping.</para>
|
||||
/// </summary>
|
||||
public static int ZIndexPercision = 100;
|
||||
|
||||
/// <summary>
|
||||
/// The transformations translation.
|
||||
/// </summary>
|
||||
public CVector2 Position { get; set; } = new CVector2(0);
|
||||
|
||||
/// <summary>
|
||||
/// The scaling.
|
||||
/// </summary>
|
||||
public CVector2 Size { get; set; } = new CVector2(50);
|
||||
|
||||
/// <summary>
|
||||
/// The rotation.
|
||||
/// </summary>
|
||||
public CVector1 Rotation { get; set; } = new CVector1(0);
|
||||
|
||||
/// <summary>
|
||||
/// If true, the object get rotated on the X-Axis by 180°.
|
||||
/// </summary>
|
||||
public bool HorizontalFlip { get; set; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// If true, the object get rotated on the Y-Axis by 180°.
|
||||
/// </summary>
|
||||
public bool VerticalFlip { get; set; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// The ZIndex.
|
||||
/// </summary>
|
||||
public CVector1 ZIndex { get; set; } = new CVector1(0);
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override Matrix4 RequestMatrix()
|
||||
{
|
||||
float z = 1 / (float) ZIndexPercision * ZIndex;
|
||||
|
|
@ -37,11 +61,18 @@ namespace SM2D.Types
|
|||
Matrix4.CreateTranslation(Position.X, Position.Y, z);
|
||||
}
|
||||
|
||||
public void TurnTo(Vector2 v)
|
||||
/// <summary>
|
||||
/// Rotates the object, so it SHOULD turn toward the position.
|
||||
/// </summary>
|
||||
public void TurnTo(Vector2 turnposition)
|
||||
{
|
||||
Rotation.Set(RotationUtility.TurnTowards(Position, v));
|
||||
Rotation.Set(RotationUtility.TurnTowards(Position, turnposition));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the vector the object is looking.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public Vector2 LookAtVector()
|
||||
{
|
||||
if (_modelMatrix.Determinant < 0.0001) return new Vector2(0);
|
||||
|
|
@ -51,11 +82,20 @@ namespace SM2D.Types
|
|||
return vec.Xy;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The object scale gets set to the same as the resolution of the texture.
|
||||
/// </summary>
|
||||
/// <param name="texture"></param>
|
||||
public void ApplyTextureSize(Texture texture)
|
||||
{
|
||||
Size.Set(texture.Width, texture.Height);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The object scale gets set to the same aspect ratio as the texture and then it will set the width..
|
||||
/// </summary>
|
||||
/// <param name="texture"></param>
|
||||
/// <param name="width"></param>
|
||||
public void ApplyTextureSize(Texture texture, float width)
|
||||
{
|
||||
Size.Set(width, width / texture.Aspect);
|
||||
|
|
|
|||
|
|
@ -1,10 +0,0 @@
|
|||
using OpenTK;
|
||||
using SM.Base.Window;
|
||||
|
||||
namespace SM2D
|
||||
{
|
||||
public interface I2DSetup : ISetup
|
||||
{
|
||||
Vector2? WorldScale { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
@ -2,32 +2,38 @@
|
|||
using OpenTK.Graphics.OpenGL4;
|
||||
using SM.Base;
|
||||
using SM.Base.Window;
|
||||
using SM2D.Pipelines;
|
||||
using SM2D.Scene;
|
||||
using SM2D.Shader;
|
||||
|
||||
namespace SM2D
|
||||
{
|
||||
public struct Window2DSetup : I2DSetup
|
||||
/// <summary>
|
||||
/// Sets up a 2D window.
|
||||
/// </summary>
|
||||
public struct Window2DSetup : ISetup
|
||||
{
|
||||
public Vector2? WorldScale { get; set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Applied(IGenericWindow window)
|
||||
{
|
||||
window.ViewportCamera = new Camera();
|
||||
|
||||
SMRenderer.DefaultMaterialShader = ShaderCollection.Instanced;
|
||||
SMRenderer.DefaultRenderPipeline = Basic2DPipeline.Pipeline;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Load(IGenericWindow window)
|
||||
{
|
||||
(window.ViewportCamera as Camera).RequestedWorldScale = WorldScale;
|
||||
GL.Enable(EnableCap.DepthTest);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Loaded(IGenericWindow window)
|
||||
{
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Resize(IGenericWindow window)
|
||||
{
|
||||
Camera.ResizeCounter++;
|
||||
|
|
|
|||
|
|
@ -1,11 +1,13 @@
|
|||
using OpenTK;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using OpenTK;
|
||||
using OpenTK.Graphics;
|
||||
using OpenTK.Input;
|
||||
using SM.Base;
|
||||
using SM.Base.Window;
|
||||
using SM.Game.Controls;
|
||||
using SM2D;
|
||||
using SM2D.Drawing;
|
||||
using SM2D.Pipelines;
|
||||
using SM2D.Scene;
|
||||
using Font = SM.Base.Drawing.Text.Font;
|
||||
using Vector2 = OpenTK.Vector2;
|
||||
|
|
@ -19,48 +21,29 @@ namespace SM_TEST
|
|||
private static GLWindow window;
|
||||
static void Main(string[] args)
|
||||
{
|
||||
font = new Font(@"C:\Windows\Fonts\Arial.ttf")
|
||||
{
|
||||
FontSize = 32
|
||||
};
|
||||
|
||||
Log.SetLogFile(compressionFolder:"logs");
|
||||
|
||||
window = new GLWindow {VSync = VSyncMode.Off};
|
||||
window.ApplySetup(new Window2DSetup() {WorldScale = new Vector2(0,1000)});
|
||||
window.SetRenderPipeline(new TestRenderPipeline());
|
||||
window = new GLWindow();
|
||||
window.ApplySetup(new Window2DSetup());
|
||||
window.SetScene(scene = new Scene());
|
||||
window.RunFixedUpdate(60);
|
||||
window.Load += WindowOnLoad;
|
||||
window.RenderFrame += WindowOnUpdateFrame;
|
||||
scene.Objects.Add(new DrawObject2D());
|
||||
window.UpdateFrame += WindowOnUpdateFrame;
|
||||
window.Run();
|
||||
|
||||
Debug.WriteLine("Window Closed");
|
||||
}
|
||||
|
||||
private static DrawParticles particles;
|
||||
private static void WindowOnUpdateFrame(object sender, FrameEventArgs e)
|
||||
{
|
||||
if (Keyboard.GetState()[Key.R])
|
||||
particles.Trigger();
|
||||
//particles.Paused = Keyboard.GetState()[Key.P];
|
||||
if (SM.Base.Controls.Keyboard.IsDown(Key.F, true))
|
||||
{
|
||||
window.WindowFlags = WindowFlags.ExclusiveFullscreen;
|
||||
window.ChangeFullscreenResolution(DisplayDevice.Default.SelectResolution(1280,720, DisplayDevice.Default.BitsPerPixel, DisplayDevice.Default.RefreshRate));
|
||||
}
|
||||
if (SM.Base.Controls.Keyboard.IsDown(Key.W, true)) window.WindowFlags = WindowFlags.Window;
|
||||
if (SM.Base.Controls.Keyboard.IsDown(Key.B, true)) window.WindowFlags = WindowFlags.BorderlessWindow;
|
||||
|
||||
GameControllerState s1 = new GameController(0).GetState();
|
||||
GameControllerState s2 = new GameController(1).GetState();
|
||||
}
|
||||
|
||||
private static void WindowOnLoad(IGenericWindow window)
|
||||
{
|
||||
scene.ShowAxisHelper = true;
|
||||
//scene.Background.Color = Color4.White;
|
||||
|
||||
DrawObject2D box = new DrawObject2D();
|
||||
scene.Objects.Add(box);
|
||||
|
||||
DrawText text = new DrawText(font, "Test Text");
|
||||
text.Transform.Position.Set(50, 0);
|
||||
text.Transform.Size.Set(2);
|
||||
scene.HUD.Add(text);
|
||||
|
||||
//particles.Trigger();
|
||||
}
|
||||
{ }
|
||||
}
|
||||
}
|
||||
|
|
@ -36,12 +36,6 @@
|
|||
<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="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" />
|
||||
<Reference Include="System.Drawing" />
|
||||
|
|
@ -56,6 +50,9 @@
|
|||
<None Include="OpenTK.dll.config" />
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<WCFMetadata Include="Connected Services\" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\SMCode\SM.Base\SM.Base.csproj">
|
||||
<Project>{8e733844-4204-43e7-b3dc-3913cddabb0d}</Project>
|
||||
|
|
@ -69,10 +66,6 @@
|
|||
<Project>{a4565538-625a-42c6-a330-dd4f1abb3986}</Project>
|
||||
<Name>SM2D</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\SMOptionals\SM.Game\SM.Game.csproj">
|
||||
<Project>{079bab31-3dc4-40da-90c7-efaa8517c647}</Project>
|
||||
<Name>SM.Game</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
||||
|
|
@ -18,7 +18,7 @@ namespace SM_TEST
|
|||
|
||||
_postBuffer = CreateWindowFramebuffer(0, false, PixelInformation.RGBA_HDR);
|
||||
Framebuffers.Add(_postBuffer);
|
||||
_bloom = new BloomEffect(MainFramebuffer, hdr: true, .5f)
|
||||
_bloom = new BloomEffect(MainFramebuffer, hdr: true, .75f)
|
||||
{
|
||||
Threshold = .5f,
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue