Holidays 12.10. -> 25.10.2020

~ Moved code around in files.

SM.Base:
+ PostProcessing-system
+ OnInitialization() for Scenes.
+ Shader-Extensions
+ Added option to not react while unfocused to the window.
+ Added Screenshots to the window.
+ Connected the log system to the SM.OGL-action system.

~ Replaced IShader with abstract MaterialShader.
~ When a log compression folder doesn't exist, it will create one.

SM.OGL:
+ Added support for UniformArrays
+ Added ShaderPreProcessing
+ Added Shader Extensions.
+ Added Debug actions.
+ SM.OGL settings

~ Framebuffer Size is automaticly changed, when the window and scale is set.

SM2D:
+ Added easy shader drawing.
This commit is contained in:
Michel Fedde 2020-10-24 15:10:36 +02:00
parent 2c00dbd31a
commit 03b3942732
102 changed files with 2683 additions and 1398 deletions

View file

@ -1,28 +1,34 @@
using System;
#region usings
using System;
#endregion
namespace SM.Base.Text
{
/// <summary>
/// Contains information for a font character.
/// Contains information for a font character.
/// </summary>
[Serializable]
public struct CharParameter
{
/// <summary>
/// The position on the X-axis.
/// The position on the X-axis.
/// </summary>
public int X;
/// <summary>
/// The width of the character.
/// The width of the character.
/// </summary>
public float Width;
/// <summary>
/// The normalized position inside the texture.
/// The normalized position inside the texture.
/// </summary>
public float NormalizedX;
/// <summary>
/// The normalized width inside the texture.
/// The normalized width inside the texture.
/// </summary>
public float NormalizedWidth;
}

View file

@ -1,71 +1,74 @@
using System.Collections.Generic;
#region usings
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Text;
using System.Security.Policy;
using OpenTK;
using OpenTK.Graphics.OpenGL4;
using OpenTK.Input;
using SM.Base.Textures;
using SM.Data.Fonts;
using SM.OGL.Texture;
#endregion
namespace SM.Base.Text
{
/// <summary>
/// Represents a font.
/// Represents a font.
/// </summary>
public class Font : Texture
{
/// <inheritdoc />
public override TextureWrapMode WrapMode { get; set; } = TextureWrapMode.ClampToEdge;
/// <summary>
/// The font family, that is used to find the right font.
/// </summary>
public FontFamily FontFamily;
/// <summary>
/// The font style.
/// <para>Default: <see cref="System.Drawing.FontStyle.Regular"/></para>
/// </summary>
public FontStyle FontStyle = FontStyle.Regular;
/// <summary>
/// The font size.
/// <para>Default: 12</para>
/// </summary>
public float FontSize = 12;
/// <summary>
/// The char set for the font.
/// <para>Default: <see cref="FontCharStorage.SimpleUTF8"/></para>
/// The char set for the font.
/// <para>Default: <see cref="FontCharStorage.SimpleUTF8" /></para>
/// </summary>
public ICollection<char> CharSet = FontCharStorage.SimpleUTF8;
/// <summary>
/// This contains all information for the different font character.
/// The font family, that is used to find the right font.
/// </summary>
public FontFamily FontFamily;
/// <summary>
/// The font size.
/// <para>Default: 12</para>
/// </summary>
public float FontSize = 12;
/// <summary>
/// The font style.
/// <para>Default: <see cref="System.Drawing.FontStyle.Regular" /></para>
/// </summary>
public FontStyle FontStyle = FontStyle.Regular;
/// <summary>
/// This contains all information for the different font character.
/// </summary>
public Dictionary<char, CharParameter> Positions = new Dictionary<char, CharParameter>();
/// <summary>
/// Generates a font from a font family from the specified path.
/// Generates a font from a font family from the specified path.
/// </summary>
/// <param name="path">The specified path</param>
public Font(string path)
{
PrivateFontCollection pfc = new PrivateFontCollection();
var pfc = new PrivateFontCollection();
pfc.AddFontFile(path);
FontFamily = pfc.Families[0];
}
/// <summary>
/// Generates a font from a specified font family.
/// Generates a font from a specified font family.
/// </summary>
/// <param name="font">Font-Family</param>
public Font(FontFamily font)
{
FontFamily = font;
}
/// <inheritdoc />
public override TextureWrapMode WrapMode { get; set; } = TextureWrapMode.ClampToEdge;
/// <summary>
/// Regenerates the texture.
/// Regenerates the texture.
/// </summary>
public void RegenerateTexture()
{
@ -74,47 +77,47 @@ namespace SM.Base.Text
Positions = new Dictionary<char, CharParameter>();
Bitmap map = new Bitmap(1000, 20);
Dictionary<char, float[]> charParams = new Dictionary<char, float[]>();
using (System.Drawing.Font f = new System.Drawing.Font(FontFamily, FontSize, FontStyle))
var map = new Bitmap(1000, 20);
var charParams = new Dictionary<char, float[]>();
using (var f = new System.Drawing.Font(FontFamily, FontSize, FontStyle))
{
using (Graphics g = Graphics.FromImage(map))
using (var g = Graphics.FromImage(map))
{
g.Clear(Color.Transparent);
foreach (char c in CharSet)
foreach (var c in CharSet)
{
string s = c.ToString();
SizeF size = g.MeasureString(s, f);
var s = c.ToString();
var size = g.MeasureString(s, f);
try
{
charParams.Add(c, new[] {size.Width, Width });
charParams.Add(c, new[] {size.Width, Width});
}
catch
{
// ignored
}
if (Height < size.Height) Height = (int)size.Height;
Width += (int)size.Width;
if (Height < size.Height) Height = (int) size.Height;
Width += (int) size.Width;
}
}
map = new Bitmap(Width, Height);
using (Graphics g = Graphics.FromImage(map))
using (var g = Graphics.FromImage(map))
{
foreach (KeyValuePair<char, float[]> keyValuePair in charParams)
foreach (var keyValuePair in charParams)
{
float normalizedX = (keyValuePair.Value[1] + 0.00001f) / Width;
float normalizedWidth = (keyValuePair.Value[0]) / Width;
var normalizedX = (keyValuePair.Value[1] + 0.00001f) / Width;
var normalizedWidth = keyValuePair.Value[0] / Width;
CharParameter parameter;
Positions.Add(keyValuePair.Key, parameter = new CharParameter()
Positions.Add(keyValuePair.Key, parameter = new CharParameter
{
NormalizedWidth = normalizedWidth,
NormalizedX = normalizedX,
Width = keyValuePair.Value[0],
X = (int)keyValuePair.Value[1]
X = (int) keyValuePair.Value[1]
});
g.DrawString(keyValuePair.Key.ToString(), f, Brushes.White, parameter.X, 0);

View file

@ -1,28 +1,29 @@
namespace SM.Data.Fonts
{
/// <summary>
/// Contains default char sets.
/// Contains default char sets.
/// </summary>
public class FontCharStorage
{
/// <summary>
/// Contains the english alphabet and the common special character.
/// Contains the english alphabet and the common special character.
/// </summary>
public static readonly char[] SimpleUTF8 = new char[]
public static readonly char[] SimpleUTF8 =
{
'!', '"', '#', '$', '%', '&', '\'', '(', ')', '*', '+', ',', '-', '.', '/', '0', '1', '2', '3', '4', '5', '6',
'!', '"', '#', '$', '%', '&', '\'', '(', ')', '*', '+', ',', '-', '.', '/', '0', '1', '2', '3', '4', '5',
'6',
'7', '8', '9', ':', ';', '<', '=', '>', '?', '@', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K',
'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '[', '\\', ']', '^', '_', '`',
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u',
'v', 'w', 'x', 'y', 'z', '{', '|', '}', '~'
};
/// <summary>
/// Contains only numbers.
/// Contains only numbers.
/// </summary>
public static readonly char[] Numbers = new[]
public static readonly char[] Numbers =
{
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'
};
}
}

View file

@ -1,30 +1,49 @@
using System;
#region usings
using System;
using OpenTK;
using OpenTK.Graphics;
using SM.Base.Contexts;
using SM.Base.Scene;
using SM.Data.Fonts;
#endregion
namespace SM.Base.Text
{
/// <summary>
/// Defines a basis for text drawing.
/// Defines a basis for text drawing.
/// </summary>
/// <typeparam name="TTransform">Transformation type</typeparam>
public abstract class TextDrawingBasis<TTransform> : DrawingBasis<TTransform>
where TTransform : GenericTransformation, new()
{
/// <summary>
/// The different instances for drawing.
/// The different instances for drawing.
/// </summary>
protected Instance[] _instances;
/// <summary>
/// The text, that is drawn.
/// The text, that is drawn.
/// </summary>
protected string _text;
/// <summary>
/// The font.
/// The spacing between numbers.
/// <para>Default: 1</para>
/// </summary>
public float Spacing = 1;
/// <summary>
/// Creates a text object with a font.
/// </summary>
/// <param name="font">The font.</param>
protected TextDrawingBasis(Font font)
{
_material.Texture = font;
}
/// <summary>
/// The font.
/// </summary>
public Font Font
{
@ -37,7 +56,7 @@ namespace SM.Base.Text
}
/// <summary>
/// The text, that is drawn.
/// The text, that is drawn.
/// </summary>
public string Text
{
@ -50,7 +69,7 @@ namespace SM.Base.Text
}
/// <summary>
/// The font color.
/// The font color.
/// </summary>
public Color4 Color
{
@ -58,21 +77,6 @@ namespace SM.Base.Text
set => _material.Tint = value;
}
/// <summary>
/// The spacing between numbers.
/// <para>Default: 1</para>
/// </summary>
public float Spacing = 1;
/// <summary>
/// Creates a text object with a font.
/// </summary>
/// <param name="font">The font.</param>
protected TextDrawingBasis(Font font)
{
_material.Texture = font;
}
/// <inheritdoc />
protected override void DrawContext(ref DrawContext context)
@ -81,7 +85,7 @@ namespace SM.Base.Text
}
/// <summary>
/// This generates the instances.
/// This generates the instances.
/// </summary>
/// <exception cref="Exception">The font doesn't contain a character that is needed for the text.</exception>
public void GenerateMatrixes()
@ -91,7 +95,7 @@ namespace SM.Base.Text
_instances = new Instance[_text.Length];
float x = 0;
CharParameter _last = new CharParameter();
var _last = new CharParameter();
for (var i = 0; i < _text.Length; i++)
{
if (_text[i] == 32)
@ -99,7 +103,7 @@ namespace SM.Base.Text
x += _last.Width * Spacing;
continue;
}
CharParameter parameter;
try
{
@ -110,15 +114,15 @@ namespace SM.Base.Text
throw new Exception("Font doesn't contain '" + _text[i] + "'");
}
Matrix4 matrix = Matrix4.CreateScale(parameter.Width, Font.Height, 1) *
Matrix4.CreateTranslation(x, 0, 0);
var matrix = Matrix4.CreateScale(parameter.Width, Font.Height, 1) *
Matrix4.CreateTranslation(x, 0, 0);
_instances[i] = new Instance
{
ModelMatrix = matrix,
TexturePosition = new Vector2(parameter.NormalizedX, 0),
TextureScale = new Vector2(parameter.NormalizedWidth, 1)
};
x += parameter.Width * Spacing;
_last = parameter;
}