diff --git a/Program.cs b/Program.cs index 9fc24cc..efa8096 100644 --- a/Program.cs +++ b/Program.cs @@ -4,9 +4,6 @@ using OpenTK.Windowing.Common; using OpenTK.Windowing.Desktop; 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; using System.Runtime.CompilerServices; using Image = SixLabors.ImageSharp.Image; @@ -24,9 +21,13 @@ public class CameraInfo { } public class Shader : IDisposable { - int Handle; + public int Handle; + private bool init = false; - public Shader() { + public Shader() {} + + public void Init() { + init = true; int VertexShader; int FragmentShader; @@ -99,6 +100,9 @@ void main() { } public void Use() { + if (!init) { + Console.WriteLine("Shader.Use(): must call Init() first"); + } GL.UseProgram(Handle); } @@ -218,7 +222,8 @@ public static class Util { public class Game : GameWindow { public Game(GameWindowSettings gwSettings, NativeWindowSettings nwSettings) : base(gwSettings, nwSettings) { } - static Texture TEXTURE_WHITE; + private static Image white1x1 = new(1, 1, new Rgba32(255, 255, 255)); + private static Texture TEXTURE_WHITE = new Texture(white1x1); UiGeometry geometry = new(); @@ -236,7 +241,7 @@ public class Game : GameWindow { int VertexArrayObject; List textures = new(); int textureIndex = 0; - Shader shader; + Shader shader = new Shader(); Matrix4 projection; protected override void OnUpdateFrame(FrameEventArgs e) { @@ -276,7 +281,7 @@ public class Game : GameWindow { GL.BindBuffer(BufferTarget.ElementArrayBuffer, ElementBufferObject); GL.BufferData(BufferTarget.ElementArrayBuffer, indices.Length * sizeof(uint), indices, BufferUsageHint.DynamicDraw); - shader = new Shader(); + shader.Init(); shader.Use(); // Because there's 5 floats between the start of the first vertex and the start of the second, @@ -294,8 +299,7 @@ public class Game : GameWindow { GL.VertexAttribPointer(texCoordLocation, 2, VertexAttribPointerType.Float, false, 5 * sizeof(float), 3 * sizeof(float)); // Create a blank white texture. - Image white1x1 = new(1, 1, new Rgba32(255, 255, 255)); - TEXTURE_WHITE = new Texture(white1x1); + // Load textures from JPEGs. string[] files = Directory.GetFiles(@"c:\users\colin\pictures\photos\2023\06\27\");