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) {
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();
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);
}