From 9de8c6de517648f969f6251a1bafdf1cf63d1541 Mon Sep 17 00:00:00 2001 From: Colin McMillen Date: Sun, 23 Jul 2023 18:42:08 -0400 Subject: [PATCH] add sample code for drawing text and shapes --- Program.cs | 24 +++++++++++++++++------- Totte.csproj | 2 ++ 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/Program.cs b/Program.cs index 45c28d9..0a472c2 100644 --- a/Program.cs +++ b/Program.cs @@ -3,10 +3,13 @@ using OpenTK.Mathematics; using OpenTK.Windowing.Common; using OpenTK.Windowing.Desktop; using OpenTK.Windowing.GraphicsLibraryFramework; -using System.Runtime.CompilerServices; // https://docs.sixlabors.com/api/ImageSharp/SixLabors.ImageSharp.Image.html using Image = SixLabors.ImageSharp.Image; +using SixLabors.Fonts; using SixLabors.ImageSharp.Metadata.Profiles.Exif; +using SixLabors.ImageSharp.Drawing.Processing; +using SixLabors.ImageSharp.Drawing; +using System.Runtime.CompilerServices; namespace SemiColinGames; @@ -164,10 +167,15 @@ public class Photo { public Texture Texture() { if (texture == placeholder && image != null) { - Console.WriteLine("making texture for " + file); - texture = new Texture(image); - image.Dispose(); - image = null; + IPath yourPolygon = new Star(x: 2000.0f, y: 1000.0f, prongs: 5, innerRadii: 20.0f, outerRadii: 50.0f, angle: Util.PI); + image.Mutate(x => x.Fill(Color.White, yourPolygon)); + Font font = SystemFonts.CreateFont("Consolas", 120); + string text = "oh no i made a memegen"; + image.Mutate(x => x.DrawText(text, font, Color.White, new PointF(800, 10))); + Console.WriteLine("making texture for " + file); + texture = new Texture(image); + image.Dispose(); + image = null; } return texture; } @@ -245,6 +253,8 @@ public class UiGeometry { } public static class Util { + public const float PI = (float) Math.PI; + public static Box2i makeBox(int left, int top, int width, int height) { return new Box2i(left, top, left + width, top + height); } @@ -384,8 +394,8 @@ public class Game : GameWindow { GL.VertexAttribPointer(texCoordLocation, 2, VertexAttribPointerType.Float, false, 5 * sizeof(float), 3 * sizeof(float)); // Load textures from JPEGs. - // string[] files = Directory.GetFiles(@"c:\users\colin\desktop\photos-test\"); - string[] files = Directory.GetFiles(@"c:\users\colin\pictures\photos\2023\07\14\"); + string[] files = Directory.GetFiles(@"c:\users\colin\desktop\photos-test\"); + // string[] files = Directory.GetFiles(@"c:\users\colin\pictures\photos\2023\07\14\"); // string[] files = Directory.GetFiles(@"C:\Users\colin\Pictures\photos\2018\06\23"); // string[] files = Directory.GetFiles(@"C:\Users\colin\Desktop\Germany all\104D7000"); diff --git a/Totte.csproj b/Totte.csproj index 640d5de..fc7046b 100644 --- a/Totte.csproj +++ b/Totte.csproj @@ -9,7 +9,9 @@ + +