No more borders at OpenGL rendering, if window has different aspect ratio than 1...
authorAndreas Eversberg <jolly@eversberg.eu>
Sat, 21 Jul 2018 16:55:13 +0000 (18:55 +0200)
committerAndreas Eversberg <jolly@eversberg.eu>
Sat, 21 Jul 2018 16:55:13 +0000 (18:55 +0200)
Instead the view is expanded horizontally (if apsect is below 1.6) or vertically (if aspect is above 1.6).

src/libopengl/opengl.c
src/mercenary/main.c

index 6bb8e9a..d992366 100644 (file)
@@ -123,7 +123,8 @@ void opengl_clear(int _flip_y)
 void opengl_viewport(int view_width, int view_height, int split, int benson_at_line, double fov, double benson_size)
 {
        int view_x = 0, view_y = 0;
-       int new_width, new_height;
+       double factor_height = 1.0;
+       double factor_width = 1.0;
 
        /* center view, or put it in the top half of the window */
        if (split == 1) {
@@ -137,22 +138,17 @@ void opengl_viewport(int view_width, int view_height, int split, int benson_at_l
        if (view_width < 1 || view_height < 1)
                return;
 
-       /* calculate a viewport that has apect of image_width:image_height */
-       if (view_height * image_width > view_width * image_height) {
-               new_height = view_width * image_height / image_width;
-               view_y = view_y + view_height / 2 - new_height / 2;
-               view_height = new_height;
-       } else if (view_height * image_width < view_width * image_height) {
-               new_width = view_height * image_width / image_height;
-               view_x = view_x + view_width / 2 - new_width / 2;
-               view_width = new_width;
-       }
+       /* expand width or height, if apect of image_width:image_height does not match the view_width:view_height */
+       if (view_height * image_width > view_width * image_height)
+               factor_height = (double)(view_height * image_width) / (double)(view_width * image_height);
+       else if (view_height * image_width < view_width * image_height)
+               factor_width = (double)(view_width * image_height) / (double)(view_height * image_width);
 
        /* avoid views that are too small */
        if (view_width < 1 || view_height < 1)
                return;
 
-       /* viewport and projection matrix */
+       /* projection matrix */
        glViewport((GLsizei)view_x, (GLsizei)view_y, (GLsizei)view_width, (GLsizei)view_height);
        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
@@ -165,7 +161,7 @@ void opengl_viewport(int view_width, int view_height, int split, int benson_at_l
        double benson_start_at_position = ((double)image_height - (double)benson_at_line) * benson_size;
        double top = slope * ((double)image_height - benson_start_at_position) / (double)image_width;
        double bottom = -slope * ((double)image_height * 2.0 - ((double)image_height - benson_start_at_position)) / (double)image_width;
-       glFrustum(left, right, bottom, top, 1.0, 5000000000.0);
+       glFrustum(left * factor_width, right * factor_width, bottom * factor_height, top * factor_height, 1.0, 5000000000.0);
 
        glMatrixMode(GL_MODELVIEW);
 }
index 0ce1a68..5d61b5c 100644 (file)
@@ -1155,7 +1155,10 @@ static void keyboard_sdl(int down, enum keycode keycode)
                        disp_fov:
                        {
                                char text[16];
-                               sprintf(text, "%.2f", config_fov);
+                               if (config_fov < 63.5 || config_fov > 64.5)
+                                       sprintf(text, "%.2f", config_fov);
+                               else
+                                       sprintf(text, "%.2f (default)", config_fov);
                                osd_info("FOV", text);
                        }
 #endif