- glViewport(0, 0, (GLsizei) w, (GLsizei) h);
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- gluPerspective(45, (GLdouble) w / (GLdouble) h, 3, 8);
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
- glTranslatef(0, 0, -5);
+ double h = (GLfloat) height / (GLfloat) width;
+
+ if (width > height * 5) { /* tiny window: show middle */
+ height = width * 9/16;
+ h = height / (GLfloat) width;
+ }
+ glViewport(0, 0, width, height);
+ glMatrixMode(GL_PROJECTION);
+ glLoadIdentity();
+ gluPerspective(45, 1/h, 3, 8);
+ glMatrixMode(GL_MODELVIEW);
+ glLoadIdentity();
+ glTranslatef(0, 0, -5);