From 855c97241bdfa89e7741a464f979ea3d38d7734e Mon Sep 17 00:00:00 2001 From: Colin McMillen Date: Thu, 6 Jul 2023 18:31:50 -0400 Subject: [PATCH] add CameraInfo class; load textures from Image rather than a pathname --- Program.cs | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/Program.cs b/Program.cs index 7fad12a..0f5d34a 100644 --- a/Program.cs +++ b/Program.cs @@ -15,6 +15,17 @@ using Image = SixLabors.ImageSharp.Image; namespace SemiColinGames; +public class CameraInfo { + public readonly Vector2i Resolution; + + private CameraInfo(Vector2i resolution) { + Resolution = resolution; + } + + public static readonly CameraInfo NIKON_D7000 = new CameraInfo(new Vector2i(4928, 3264)); + public static readonly CameraInfo IPHONE_12_MINI = new CameraInfo(new Vector2i(4032, 3024)); +} + public class Shader : IDisposable { int Handle; @@ -128,8 +139,7 @@ public class Texture : IDisposable { public int Width; public int Height; - public Texture(string path) { - Image image = Image.Load(path); + public Texture(Image image) { Width = image.Width; Height = image.Height; Console.WriteLine($"image loaded: {Width}x{Height}"); @@ -178,6 +188,10 @@ public class Texture : IDisposable { public class Game : GameWindow { public Game(GameWindowSettings gwSettings, NativeWindowSettings nwSettings) : base(gwSettings, nwSettings) { } + static CameraInfo activeCamera = CameraInfo.NIKON_D7000; + static int thumbnailHeight = 100; + static int thumbnailWidth = (int) 1.0 * thumbnailHeight * activeCamera.Resolution.X / activeCamera.Resolution.Y; + int frameCount; int windowWidth; int windowHeight; @@ -226,6 +240,8 @@ public class Game : GameWindow { protected override void OnLoad() { base.OnLoad(); + Console.WriteLine($"thumbnail size: {thumbnailWidth}x{thumbnailHeight}"); + GL.ClearColor(0.0f, 0.0f, 0.05f, 1.0f); VertexArrayObject = GL.GenVertexArray(); @@ -261,7 +277,8 @@ public class Game : GameWindow { textures = new List(); foreach (string file in files) { if (file.ToLower().EndsWith(".jpg")) { - textures.Add(new Texture(file)); + Image image = Image.Load(file); + textures.Add(new Texture(image)); } } } @@ -275,8 +292,6 @@ public class Game : GameWindow { frameCount++; GL.Clear(ClearBufferMask.ColorBufferBit); - int thumbnailWidth = 150; - int thumbnailHeight = 100; int borderWidth = 2; int maxPhotoWidth = windowWidth - thumbnailWidth - borderWidth;