letterbox the image so that the aspect ratio is right
This commit is contained in:
parent
a3360b1420
commit
0625040304
11
Program.cs
11
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);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user