diff --git a/Program.cs b/Program.cs index 61748b7..a674b05 100644 --- a/Program.cs +++ b/Program.cs @@ -189,7 +189,7 @@ public class Game : GameWindow { public Game(GameWindowSettings gwSettings, NativeWindowSettings nwSettings) : base(gwSettings, nwSettings) { } static CameraInfo activeCamera = CameraInfo.NIKON_D7000; - static int thumbnailHeight = 100; + static int thumbnailHeight = 150; static int thumbnailWidth = (int) 1.0 * thumbnailHeight * activeCamera.Resolution.X / activeCamera.Resolution.Y; static Texture TEXTURE_WHITE; @@ -294,34 +294,44 @@ public class Game : GameWindow { protected override void OnRenderFrame(FrameEventArgs e) { base.OnRenderFrame(e); GL.Clear(ClearBufferMask.ColorBufferBit); + GL.BindBuffer(BufferTarget.ArrayBuffer, VertexBufferObject); + GL.ActiveTexture(TextureUnit.Texture0); - int borderWidth = 2; + int borderWidth = 0; int maxPhotoWidth = windowWidth - thumbnailWidth - borderWidth; Texture active = textures[textureIndex]; // TODO: handle the case where we need to letterbox vertically instead. + // TODO: pull these geometry calculations out into an object. int photoWidth = (int) (1.0 * windowHeight / active.Height * active.Width); int letterboxWidth = (maxPhotoWidth - photoWidth) / 2; - SetVertices(letterboxWidth, 0, photoWidth, windowHeight); - GL.BindBuffer(BufferTarget.ArrayBuffer, VertexBufferObject); - GL.BufferData(BufferTarget.ArrayBuffer, vertices.Length * sizeof(float), vertices, BufferUsageHint.DynamicDraw); - GL.ActiveTexture(TextureUnit.Texture0); - GL.BindTexture(TextureTarget.Texture2D, active.Handle); - GL.DrawElements(PrimitiveType.Triangles, indices.Length, DrawElementsType.UnsignedInt, 0); - + DrawTexture(active, letterboxWidth, 0, photoWidth, windowHeight); for (int i = 0; i < textures.Count; i++) { - SetVertices(windowWidth - thumbnailWidth, i * thumbnailHeight, thumbnailWidth, thumbnailHeight - borderWidth); - GL.BindBuffer(BufferTarget.ArrayBuffer, VertexBufferObject); - GL.BufferData(BufferTarget.ArrayBuffer, vertices.Length * sizeof(float), vertices, BufferUsageHint.DynamicDraw); - GL.ActiveTexture(TextureUnit.Texture0); - GL.BindTexture(TextureTarget.Texture2D, textures[i].Handle); - GL.DrawElements(PrimitiveType.Triangles, indices.Length, DrawElementsType.UnsignedInt, 0); + // FIXME: make this a rect or something + DrawTexture(textures[i], windowWidth - thumbnailWidth, i * thumbnailHeight, thumbnailWidth, thumbnailHeight - borderWidth); + if (i == textureIndex) { + DrawBox(windowWidth - thumbnailWidth, i * thumbnailHeight, thumbnailWidth, thumbnailHeight - borderWidth, 2); + } } SwapBuffers(); } + void DrawTexture(Texture texture, int left, int top, int width, int height) { + SetVertices(left, top, width, height); + GL.BufferData(BufferTarget.ArrayBuffer, vertices.Length * sizeof(float), vertices, BufferUsageHint.DynamicDraw); + GL.BindTexture(TextureTarget.Texture2D, texture.Handle); + GL.DrawElements(PrimitiveType.Triangles, indices.Length, DrawElementsType.UnsignedInt, 0); + } + + void DrawBox(int left, int top, int width, int height, int thickness) { + DrawTexture(TEXTURE_WHITE, left, top, width, thickness); + DrawTexture(TEXTURE_WHITE, left, top, thickness, height); + DrawTexture(TEXTURE_WHITE, left, top + height - thickness, width, thickness); + DrawTexture(TEXTURE_WHITE, left + width - thickness, top, thickness, height); + } + protected override void OnResize(ResizeEventArgs e) { base.OnResize(e); Console.WriteLine($"OnResize: {e.Width}x{e.Height}");