add sample code for drawing text and shapes

This commit is contained in:
Colin McMillen 2023-07-23 18:42:08 -04:00
parent 4a857b461c
commit 9de8c6de51
2 changed files with 19 additions and 7 deletions

View File

@ -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,6 +167,11 @@ public class Photo {
public Texture Texture() {
if (texture == placeholder && 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();
@ -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");

View File

@ -9,7 +9,9 @@
<ItemGroup>
<PackageReference Include="OpenTK" Version="4.7.7" />
<PackageReference Include="SixLabors.Fonts" Version="1.0.0-beta19" />
<PackageReference Include="SixLabors.ImageSharp" Version="3.0.1" />
<PackageReference Include="SixLabors.ImageSharp.Drawing" Version="1.0.0-beta15" />
</ItemGroup>
</Project>