Browse Source

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

main
Colin McMillen 1 year ago
parent
commit
20f8b1e285
  1. 14
      Program.cs

14
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<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();

Loading…
Cancel
Save