diff --git a/Program.cs b/Program.cs index 83c1838..ecc1437 100644 --- a/Program.cs +++ b/Program.cs @@ -140,21 +140,19 @@ void main() { public class Photo { public Texture Texture; + public bool Loaded = false; + private readonly string filename; - public Photo(string filename) { - Image image = Image.Load(filename); - Texture = new Texture(image); + public Photo(string filename, Texture unloadedTexture) { + this.filename = filename; + Texture = unloadedTexture; } -} -public class Texture : IDisposable { - public int Handle; - public Vector2i Size; + public void Load() { + Image image = Image.Load(filename); - public Texture(Image image) { - Size = new Vector2i(image.Width, image.Height); Console.WriteLine("----------------------------------"); - Console.WriteLine($"image loaded: {Size}"); + Console.WriteLine($"image loaded: {image.Width}x{image.Height}"); ExifProfile? exifs = image.Metadata.ExifProfile; if (exifs != null) { @@ -164,6 +162,17 @@ public class Texture : IDisposable { } } } + Texture = new Texture(image); + Loaded = true; + } +} + +public class Texture : IDisposable { + public int Handle; + public Vector2i Size; + + public Texture(Image image) { + Size = new Vector2i(image.Width, image.Height); byte[] pixelBytes = new byte[Size.X * Size.Y * Unsafe.SizeOf()]; image.CopyPixelDataTo(pixelBytes); image.Dispose(); @@ -345,9 +354,14 @@ public class Game : GameWindow { // 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\"); - foreach (string file in files) { + for (int i = 0; i < files.Count(); i++) { + string file = files[i]; if (file.ToLower().EndsWith(".jpg")) { - photos.Add(new Photo(file)); + Photo photo = new(file, TEXTURE_WHITE); + if (i == 0) { + photo.Load(); + } + photos.Add(photo); if (photos.Count > 10) { break; } @@ -388,6 +402,7 @@ public class Game : GameWindow { SwapBuffers(); } + // FIXME: pull these out into a Util class and let photos be able to draw themselves? void DrawTexture(Texture texture, Box2i box) { DrawTexture(texture, box, Color4.White); }