1.0.12 & 1.0.12.1
+ Utility Methods for texture transformations ~ Fixed an issue, where the horizontal & vertical flip was wrongly applied ~ Added missing summaries
This commit is contained in:
parent
a29a2cab53
commit
f11a954b5a
10 changed files with 116 additions and 21 deletions
|
|
@ -18,17 +18,17 @@ namespace SM.Base.Drawing
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The camera, that was used last time the object was rendered.
|
/// The camera, that was used last time the object was rendered.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public GenericCamera LastDrawingCamera;
|
public GenericCamera LastDrawingCamera { get; private set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The material it should use.
|
/// The material it should use.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Material Material = new Material();
|
public Material Material { get; set; } = new Material();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Transformation for the textures.
|
/// Transformation for the textures.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public TextureTransformation TextureTransform = new TextureTransformation();
|
public TextureTransformation TextureTransform { get; set; } = new TextureTransformation();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// This allows custom shaders to add own arguments.
|
/// This allows custom shaders to add own arguments.
|
||||||
|
|
@ -71,7 +71,6 @@ namespace SM.Base.Drawing
|
||||||
|
|
||||||
DrawContext(ref context);
|
DrawContext(ref context);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public virtual void OnAdded(object sender)
|
public virtual void OnAdded(object sender)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,9 @@ namespace SM.Base.Drawing.Text
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int Advance;
|
public int Advance;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The bearing for this char.
|
||||||
|
/// </summary>
|
||||||
public float BearingX;
|
public float BearingX;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -26,6 +29,9 @@ namespace SM.Base.Drawing.Text
|
||||||
public float Width;
|
public float Width;
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Matrix for the texture.
|
||||||
|
/// </summary>
|
||||||
public Matrix3 TextureMatrix;
|
public Matrix3 TextureMatrix;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -11,21 +11,45 @@ using SM.Base.Textures;
|
||||||
|
|
||||||
namespace SM.Base.Drawing.Text
|
namespace SM.Base.Drawing.Text
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Represents a font to be used in DrawText-classes.
|
||||||
|
/// </summary>
|
||||||
public class Font : Texture
|
public class Font : Texture
|
||||||
{
|
{
|
||||||
private static Library _lib;
|
private static Library _lib;
|
||||||
|
|
||||||
private Face _fontFace;
|
private Face _fontFace;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The amount the cursor should move forward when a space was found.
|
||||||
|
/// </summary>
|
||||||
public float SpaceWidth { get; private set; } = 0;
|
public float SpaceWidth { get; private set; } = 0;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The char set the font should contain.
|
||||||
|
/// <para>See <see cref="FontCharStorage"/> for some default values.</para>
|
||||||
|
/// <para>Default: <see cref="FontCharStorage.SimpleUTF8"/></para>
|
||||||
|
/// </summary>
|
||||||
public ICollection<char> CharSet { get; set; } = FontCharStorage.SimpleUTF8;
|
public ICollection<char> CharSet { get; set; } = FontCharStorage.SimpleUTF8;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The font-size defines how large the result texture should be.
|
||||||
|
/// <para>Lower equals less quality, but also less memory usage.</para>
|
||||||
|
/// <para>Higher equals high quality, but also high memory usage.</para>
|
||||||
|
/// <para>Default: 12</para>
|
||||||
|
/// </summary>
|
||||||
public float FontSize { get; set; } = 12;
|
public float FontSize { get; set; } = 12;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The character positions.
|
||||||
|
/// </summary>
|
||||||
public Dictionary<char, CharParameter> Positions = new Dictionary<char, CharParameter>();
|
public Dictionary<char, CharParameter> Positions = new Dictionary<char, CharParameter>();
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Creates a font, by using a path
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="path">Path to the font-file.</param>
|
||||||
public Font(string path)
|
public Font(string path)
|
||||||
{
|
{
|
||||||
_lib ??= new Library();
|
_lib ??= new Library();
|
||||||
|
|
@ -34,6 +58,9 @@ namespace SM.Base.Drawing.Text
|
||||||
UnpackAlignment = 1;
|
UnpackAlignment = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// (Re-)Generates the texture.
|
||||||
|
/// </summary>
|
||||||
public void RegenerateTexture()
|
public void RegenerateTexture()
|
||||||
{
|
{
|
||||||
Width = Height = 0;
|
Width = Height = 0;
|
||||||
|
|
@ -88,6 +115,7 @@ namespace SM.Base.Drawing.Text
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
public override void Compile()
|
public override void Compile()
|
||||||
{
|
{
|
||||||
RegenerateTexture();
|
RegenerateTexture();
|
||||||
|
|
|
||||||
|
|
@ -10,10 +10,22 @@ using SM.Base.Window;
|
||||||
|
|
||||||
namespace SM.Base.Drawing.Text
|
namespace SM.Base.Drawing.Text
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Represents the options for <see cref="TextDrawingBasis{TTransform}.Origin"/>
|
||||||
|
/// </summary>
|
||||||
public enum TextOrigin
|
public enum TextOrigin
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The position equals (0,0) in the left side of the text.
|
||||||
|
/// </summary>
|
||||||
Left,
|
Left,
|
||||||
|
/// <summary>
|
||||||
|
/// The position equals (0,0) in the center of the text.
|
||||||
|
/// </summary>
|
||||||
Center,
|
Center,
|
||||||
|
/// <summary>
|
||||||
|
/// The position equals (0,0) in the right side of the text.
|
||||||
|
/// </summary>
|
||||||
Right
|
Right
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,8 @@
|
||||||
#region usings
|
#region usings
|
||||||
|
|
||||||
using OpenTK;
|
using OpenTK;
|
||||||
|
using OpenTK.Graphics.ES10;
|
||||||
|
using SM.Base.Textures;
|
||||||
using SM.Base.Types;
|
using SM.Base.Types;
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
@ -34,6 +36,41 @@ namespace SM.Base.Drawing
|
||||||
return CalculateMatrix(Offset, Scale, Rotation);
|
return CalculateMatrix(Offset, Scale, Rotation);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Sets the offset relative to the pixels of the texture.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="texture">The texture it should use.</param>
|
||||||
|
/// <param name="pixelLocation">The offset in pixel.</param>
|
||||||
|
public void SetOffsetRelative(Texture texture, Vector2 pixelLocation)
|
||||||
|
{
|
||||||
|
Vector2 textureSize = new Vector2(texture.Width, texture.Height);
|
||||||
|
Offset.Set( Vector2.Divide(pixelLocation, textureSize) );
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Sets the scale relative to the pixels of the texture.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="texture">The texture.</param>
|
||||||
|
/// <param name="rectangleSize">The scale in pixel.</param>
|
||||||
|
public void SetScaleRelative(Texture texture, Vector2 rectangleSize)
|
||||||
|
{
|
||||||
|
Vector2 textureSize = new Vector2(texture.Width, texture.Height);
|
||||||
|
Scale.Set( Vector2.Divide(rectangleSize, textureSize) );
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Sets the offset and scale relative to the pixels of the texture.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="texture">The texture.</param>
|
||||||
|
/// <param name="location">Offset in pixel</param>
|
||||||
|
/// <param name="rectangleSize">Scale in pixel.</param>
|
||||||
|
public void SetRectangleRelative(Texture texture, Vector2 location, Vector2 rectangleSize)
|
||||||
|
{
|
||||||
|
Vector2 textureSize = new Vector2(texture.Width, texture.Height);
|
||||||
|
|
||||||
|
Offset.Set(Vector2.Divide(location, textureSize));
|
||||||
|
Scale.Set(Vector2.Divide(rectangleSize, textureSize));
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Calculates a texture matrix.
|
/// Calculates a texture matrix.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
||||||
|
|
@ -33,6 +33,9 @@ namespace SM.Base.Textures
|
||||||
private int? _height;
|
private int? _height;
|
||||||
private int? _width;
|
private int? _width;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The unpack alignment for this texture.
|
||||||
|
/// </summary>
|
||||||
public int UnpackAlignment = 4;
|
public int UnpackAlignment = 4;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -120,6 +123,7 @@ namespace SM.Base.Textures
|
||||||
/// <param name="filter">The filter</param>
|
/// <param name="filter">The filter</param>
|
||||||
/// <param name="wrapMode">The wrap mode</param>
|
/// <param name="wrapMode">The wrap mode</param>
|
||||||
/// <param name="dispose">Auto dispose of the bitmap? Default: false</param>
|
/// <param name="dispose">Auto dispose of the bitmap? Default: false</param>
|
||||||
|
/// <param name="unpackAlignment">The unpack alignment for this texture.</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static int GenerateTexture(Bitmap map, TextureMinFilter filter, TextureWrapMode wrapMode,
|
public static int GenerateTexture(Bitmap map, TextureMinFilter filter, TextureWrapMode wrapMode,
|
||||||
bool dispose = false, int unpackAlignment = 4)
|
bool dispose = false, int unpackAlignment = 4)
|
||||||
|
|
|
||||||
|
|
@ -143,6 +143,9 @@ namespace SM.Base.Window
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// This gets called, when the window completed with all initilization steps.
|
||||||
|
/// </summary>
|
||||||
protected virtual void OnLoaded()
|
protected virtual void OnLoaded()
|
||||||
{
|
{
|
||||||
Icon ??= new Icon(AssemblyUtility.GetAssemblyStream("SM.Base.Window.winIcon.ico"));
|
Icon ??= new Icon(AssemblyUtility.GetAssemblyStream("SM.Base.Window.winIcon.ico"));
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,10 @@ namespace SM2D.Drawing
|
||||||
Transform.Size = new CVector2(1);
|
Transform.Size = new CVector2(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Sets the height of the text.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="desiredHeight">The height it should be.</param>
|
||||||
public void SetHeight(float desiredHeight)
|
public void SetHeight(float desiredHeight)
|
||||||
{
|
{
|
||||||
if (!Font.WasCompiled) Font.Compile();
|
if (!Font.WasCompiled) Font.Compile();
|
||||||
|
|
|
||||||
|
|
@ -54,9 +54,7 @@ namespace SM2D.Types
|
||||||
{
|
{
|
||||||
float z = 1 / (float) ZIndexPercision * ZIndex;
|
float z = 1 / (float) ZIndexPercision * ZIndex;
|
||||||
|
|
||||||
return Matrix4.CreateScale(Size.X, Size.Y, 1) *
|
return Matrix4.CreateScale(Size.X * (VerticalFlip ? -1 : 1), Size.Y * (HorizontalFlip ? -1 : 1), 1) *
|
||||||
Matrix4.CreateRotationX(MathHelper.DegreesToRadians(HorizontalFlip ? 180 : 0)) *
|
|
||||||
Matrix4.CreateRotationY(MathHelper.DegreesToRadians(VerticalFlip ? 180 : 0)) *
|
|
||||||
Matrix4.CreateRotationZ(MathHelper.DegreesToRadians(Rotation)) *
|
Matrix4.CreateRotationZ(MathHelper.DegreesToRadians(Rotation)) *
|
||||||
Matrix4.CreateTranslation(Position.X, Position.Y, z);
|
Matrix4.CreateTranslation(Position.X, Position.Y, z);
|
||||||
}
|
}
|
||||||
|
|
@ -100,5 +98,15 @@ namespace SM2D.Types
|
||||||
{
|
{
|
||||||
Size.Set(width, width / texture.Aspect);
|
Size.Set(width, width / texture.Aspect);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Adjusts <see cref="Size"/> for the texture transform.
|
||||||
|
/// <para>In this way you can make sure, the texture is not stretched.</para>
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="transform"></param>
|
||||||
|
public void AdjustSizeToTextureTransform(TextureTransformation transform)
|
||||||
|
{
|
||||||
|
Size.Set(transform.Scale * Size);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
|
using System.Drawing;
|
||||||
using OpenTK;
|
using OpenTK;
|
||||||
using OpenTK.Graphics;
|
using OpenTK.Graphics;
|
||||||
using OpenTK.Graphics.OpenGL;
|
using OpenTK.Graphics.OpenGL;
|
||||||
|
|
@ -8,13 +9,13 @@ using SM.Base;
|
||||||
using SM.Base.Animation;
|
using SM.Base.Animation;
|
||||||
using SM.Base.Controls;
|
using SM.Base.Controls;
|
||||||
using SM.Base.Drawing;
|
using SM.Base.Drawing;
|
||||||
using SM.Base.Drawing.Text;
|
|
||||||
using SM.Base.Time;
|
using SM.Base.Time;
|
||||||
using SM.Base.Window;
|
using SM.Base.Window;
|
||||||
using SM2D;
|
using SM2D;
|
||||||
using SM2D.Drawing;
|
using SM2D.Drawing;
|
||||||
using SM2D.Object;
|
using SM2D.Object;
|
||||||
using SM2D.Scene;
|
using SM2D.Scene;
|
||||||
|
using Font = SM.Base.Drawing.Text.Font;
|
||||||
|
|
||||||
namespace SM_TEST
|
namespace SM_TEST
|
||||||
{
|
{
|
||||||
|
|
@ -34,8 +35,6 @@ namespace SM_TEST
|
||||||
};
|
};
|
||||||
font.RegenerateTexture();
|
font.RegenerateTexture();
|
||||||
|
|
||||||
SMRenderer.DefaultMesh = new Polygon(new[] { new Vector2(0, 0), new Vector2(0, 1), new Vector2(1, 1), new Vector2(1, 0) });
|
|
||||||
|
|
||||||
window = new GLWindow(1280, 720, "0ms", WindowFlags.Window, VSyncMode.Off);
|
window = new GLWindow(1280, 720, "0ms", WindowFlags.Window, VSyncMode.Off);
|
||||||
window.ApplySetup(new Window2DSetup());
|
window.ApplySetup(new Window2DSetup());
|
||||||
|
|
||||||
|
|
@ -49,19 +48,14 @@ namespace SM_TEST
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Material uvMaterial = new Material()
|
DrawObject2D test = new DrawObject2D()
|
||||||
{
|
{
|
||||||
Tint = new Color4(1f, 0, 0, .5f),
|
Texture = new Bitmap("test.png")
|
||||||
Blending = true,
|
|
||||||
Texture = font
|
|
||||||
};
|
};
|
||||||
|
test.Material.Blending = true;
|
||||||
DrawText test = new DrawText(font, "Level Completed")
|
test.Transform.Size.Set(100);
|
||||||
{
|
test.TextureTransform.SetRectangleRelative(test.Texture, new Vector2(234, 0), new Vector2(220, 201));
|
||||||
Material = uvMaterial,
|
test.Transform.AdjustSizeToTextureTransform(test.TextureTransform);
|
||||||
};
|
|
||||||
test.Transform.Position.Set(0, 2);
|
|
||||||
test.Transform.Size.Set(.5f);
|
|
||||||
|
|
||||||
scene.Objects.Add(test);
|
scene.Objects.Add(test);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue