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