load multiple textures, one for every JPG in the input directory

This commit is contained in:
Colin McMillen 2023-06-29 16:01:49 -04:00
parent d3e7718b5f
commit 20f8b1e285

View File

@ -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<Texture> 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<Texture>();
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();