From 0625040304eae94c086b0d0017a81ed106d14d4d Mon Sep 17 00:00:00 2001 From: Colin McMillen Date: Thu, 29 Jun 2023 22:52:52 -0400 Subject: [PATCH] letterbox the image so that the aspect ratio is right --- Program.cs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/Program.cs b/Program.cs index 730bbf6..1e840ac 100644 --- a/Program.cs +++ b/Program.cs @@ -278,13 +278,18 @@ public class Game : GameWindow { int thumbnailWidth = 150; int thumbnailHeight = 100; int borderWidth = 2; - int photoWidth = windowWidth - thumbnailWidth - borderWidth; + int maxPhotoWidth = windowWidth - thumbnailWidth - borderWidth; - SetVertices(0, 0, photoWidth, windowHeight); + Texture active = textures[textureIndex]; + // TODO: handle the case where we need to letterbox vertically instead. + int photoWidth = (int) (1.0 * windowHeight / active.Height * active.Width); + int letterboxWidth = (maxPhotoWidth - photoWidth) / 2; + + SetVertices(letterboxWidth, 0, photoWidth + letterboxWidth, 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, textures[textureIndex].Handle); + GL.BindTexture(TextureTarget.Texture2D, active.Handle); shader.Use(); GL.DrawElements(PrimitiveType.Triangles, indices.Length, DrawElementsType.UnsignedInt, 0);