19.09.2020

+ Vector-classes
+ Added Background
~ Changed OpenTK.Vector2 to SM.Base.Types.Vector2
This commit is contained in:
Michel Fedde 2020-09-19 19:04:19 +02:00
parent a603ecc417
commit acccf5f0e7
22 changed files with 295 additions and 27 deletions

View file

@ -0,0 +1,49 @@
using System.Drawing;
using OpenTK;
using OpenTK.Graphics;
using SM.Base.Contexts;
using SM.Base.Scene;
using SM.Base.Textures;
using SM.OGL.Texture;
using SM2D.Types;
namespace SM2D.Drawing
{
public class DrawBackground : DrawingBasis
{
public Color4 Color
{
get => _material.Tint;
set => _material.Tint = value;
}
public TextureBase Texture
{
get => _material.Texture;
set => _material.Texture = value;
}
public DrawBackground(Color4 color)
{
Color = color;
}
public DrawBackground(Bitmap texture)
{
Texture = (Texture)texture;
}
public DrawBackground(Bitmap texture, Color4 tint)
{
Color = tint;
Texture = (Texture) texture;
}
public override void Draw(DrawContext context)
{
ApplyContext(ref context);
context.ModelMatrix = Matrix4.CreateScale(context.WorldScale.X, context.WorldScale.Y, 1);
_material.Shader.Draw(context);
}
}
}

View file

@ -1,14 +1,19 @@
using System.Drawing;
using OpenTK;
using OpenTK.Graphics;
using SM.Base.Contexts;
using SM.Base.Scene;
using SM.Base.Textures;
using SM.Base.Types;
using SM2D.Types;
using Vector2 = SM.Base.Types.Vector2;
namespace SM2D.Drawing
{
public class DrawTexture : DrawingBasis<Transformation>
{
public static float MasterScale = .25f;
public Texture Texture
{
get => (Texture) _material.Texture;
@ -21,6 +26,9 @@ namespace SM2D.Drawing
set => _material.Tint = value;
}
public float Scale = 1;
public DrawTexture(Bitmap map) : this(map, Color4.White)
{ }
@ -35,6 +43,7 @@ namespace SM2D.Drawing
base.Draw(context);
ApplyContext(ref context);
Transform.Size = new Vector2(Texture.Map.Width * MasterScale * Scale, Texture.Map.Height * MasterScale * Scale);
context.ModelMatrix = Transform.GetMatrix();
_material.Shader.Draw(context);

View file

@ -1,10 +1,26 @@
using SM.Base;
using System;
using OpenTK;
using OpenTK.Graphics.OpenGL4;
using SM.Base;
using SM2D.Scene;
namespace SM2D
{
public class GLWindow2D : GenericWindow<Scene.Scene, Camera>
{
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
GL.Enable(EnableCap.Blend);
GL.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha);
}
protected override void OnRenderFrame(FrameEventArgs e)
{
GL.Disable(EnableCap.DepthTest);
base.OnRenderFrame(e);
}
}
}

View file

@ -45,6 +45,7 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Drawing\DrawBackground.cs" />
<Compile Include="Drawing\DrawEmpty.cs" />
<Compile Include="Drawing\DrawTexture.cs" />
<Compile Include="GLWindow2D.cs" />

View file

@ -1,5 +1,6 @@
using OpenTK;
using SM.Base.Scene;
using Vector2 = SM.Base.Types.Vector2;
namespace SM2D.Scene
{
@ -7,16 +8,16 @@ namespace SM2D.Scene
{
public override bool Orthographic { get; } = true;
public Vector2 Position;
public Vector2 Position = new Vector2(0);
public override Matrix4 ViewCalculation()
protected override Matrix4 ViewCalculation()
{
return Matrix4.LookAt(Position.X, Position.Y, -1, Position.X, Position.Y, 0, 0, 1, 0);
}
public override void RecalculateWorld(float width, float height)
public override void RecalculateWorld(OpenTK.Vector2 world, float aspect)
{
OrthographicWorld = Matrix4.CreateOrthographicOffCenter(-width / 2, width / 2, height / 2, -height / 2, 0.1f, 100);
OrthographicWorld = Matrix4.CreateOrthographicOffCenter(world.X / 2, -world.X / 2, world.Y / 2, -world.Y / 2, 0.1f, 100);
}
}
}

View file

@ -1,11 +1,12 @@
using OpenTK;
using SM.Base.Scene;
using Vector2 = SM.Base.Types.Vector2;
namespace SM2D.Types
{
public class Transformation : GenericTransformation
{
public Vector2 Position;
public Vector2 Position = new Vector2(0);
public Vector2 Size = new Vector2(50);
public float Rotation;