From 20f8b1e2851d6e6c5313a3437bf067d6f488c0d1 Mon Sep 17 00:00:00 2001 From: Colin McMillen Date: Thu, 29 Jun 2023 16:01:49 -0400 Subject: [PATCH] load multiple textures, one for every JPG in the input directory --- Program.cs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/Program.cs b/Program.cs index 8c65524..87f1954 100644 --- a/Program.cs +++ b/Program.cs @@ -6,6 +6,7 @@ using OpenTK.Windowing.GraphicsLibraryFramework; // https://docs.sixlabors.com/api/ImageSharp/SixLabors.ImageSharp.Image.html using SixLabors.ImageSharp; using SixLabors.ImageSharp.Metadata.Profiles.Exif; +using System.IO; using System.Reflection.Metadata; using System.Runtime.CompilerServices; using static System.Runtime.InteropServices.JavaScript.JSType; @@ -191,7 +192,8 @@ public class Game : GameWindow { int VertexBufferObject; int ElementBufferObject; int VertexArrayObject; - Texture texture; + List textures; + int textureIndex = 0; Shader shader; Matrix4 projection; @@ -239,7 +241,13 @@ public class Game : GameWindow { GL.VertexAttribPointer(texCoordLocation, 2, VertexAttribPointerType.Float, false, 5 * sizeof(float), 3 * sizeof(float)); // Load textures from JPEGs. - texture = new Texture(@"c:\users\colin\pictures\photos\2023\06\27\DSC_0035.jpg"); + string[] files = Directory.GetFiles(@"c:\users\colin\pictures\photos\2023\06\27\"); + textures = new List(); + foreach (string file in files) { + if (file.ToLower().EndsWith(".jpg")) { + textures.Add(new Texture(file)); + } + } } protected override void OnUnload() { @@ -252,7 +260,7 @@ public class Game : GameWindow { GL.Clear(ClearBufferMask.ColorBufferBit); GL.BindVertexArray(VertexArrayObject); GL.ActiveTexture(TextureUnit.Texture0); - GL.BindTexture(TextureTarget.Texture2D, texture.Handle); + GL.BindTexture(TextureTarget.Texture2D, textures[textureIndex].Handle); shader.Use(); GL.DrawElements(PrimitiveType.Triangles, indices.Length, DrawElementsType.UnsignedInt, 0); SwapBuffers();