From ec2989a9b094742dc7192cc4d85492764be95ac9 Mon Sep 17 00:00:00 2001 From: Colin McMillen Date: Fri, 7 Jul 2023 23:41:32 -0400 Subject: [PATCH] use a Vector2i for Texture size --- Program.cs | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/Program.cs b/Program.cs index 06a14eb..6f8113d 100644 --- a/Program.cs +++ b/Program.cs @@ -3,8 +3,8 @@ using OpenTK.Mathematics; using OpenTK.Windowing.Common; using OpenTK.Windowing.Desktop; using OpenTK.Windowing.GraphicsLibraryFramework; -// https://docs.sixlabors.com/api/ImageSharp/SixLabors.ImageSharp.Image.html using System.Runtime.CompilerServices; +// https://docs.sixlabors.com/api/ImageSharp/SixLabors.ImageSharp.Image.html using Image = SixLabors.ImageSharp.Image; namespace SemiColinGames; @@ -138,26 +138,23 @@ void main() { public class Texture : IDisposable { public int Handle; - // FIXME: use a Vector2i for dimensions. - public int Width; - public int Height; + public Vector2i Size; public Texture(Image image) { - Width = image.Width; - Height = image.Height; - Console.WriteLine($"image loaded: {Width}x{Height}"); + Size = new Vector2i(image.Width, image.Height); + Console.WriteLine($"image loaded: {Size}"); //foreach (IExifValue exif in image.Metadata.ExifProfile.Values) { // Console.WriteLine($"{exif.Tag} : {exif.GetValue()}"); //} - byte[] pixelBytes = new byte[Width * Height * Unsafe.SizeOf()]; + byte[] pixelBytes = new byte[Size.X * Size.Y * Unsafe.SizeOf()]; image.CopyPixelDataTo(pixelBytes); image.Dispose(); Handle = GL.GenTexture(); GL.ActiveTexture(TextureUnit.Texture0); GL.BindTexture(TextureTarget.Texture2D, Handle); - GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, image.Width, image.Height, 0, PixelFormat.Rgba, PixelType.UnsignedByte, pixelBytes); + GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, Size.X, Size.Y, 0, PixelFormat.Rgba, PixelType.UnsignedByte, pixelBytes); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int) TextureMinFilter.LinearMipmapLinear); // FIXME: is this right? GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int) TextureMagFilter.Nearest); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int) TextureWrapMode.ClampToBorder); @@ -321,11 +318,11 @@ public class Game : GameWindow { Texture active = textures[textureIndex]; // FIXME: make a function for scaling & centering one box on another. - double scaleX = 1.0 * geometry.PhotoBox.Size.X / active.Width; - double scaleY = 1.0 * geometry.PhotoBox.Size.Y / active.Height; + double scaleX = 1.0 * geometry.PhotoBox.Size.X / active.Size.X; + double scaleY = 1.0 * geometry.PhotoBox.Size.Y / active.Size.Y; double scale = Math.Min(scaleX, scaleY); - int renderWidth = (int) (active.Width * scale); - int renderHeight = (int) (active.Height * scale); + int renderWidth = (int) (active.Size.X * scale); + int renderHeight = (int) (active.Size.Y * scale); Box2i photoBox = Util.makeBox((int) geometry.PhotoBox.Center.X - renderWidth / 2, (int) geometry.PhotoBox.Center.Y - renderHeight / 2, renderWidth, renderHeight); DrawTexture(active, photoBox); for (int i = 0; i < textures.Count; i++) {