From 1fbbf873ce0993536eafe9f9f01eb0ca24fececa Mon Sep 17 00:00:00 2001 From: Ash Tyndall Date: Sun, 9 Oct 2011 19:14:08 +0800 Subject: [PATCH] --- scene.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/scene.c b/scene.c index 7e72ae6..4fea15a 100644 --- a/scene.c +++ b/scene.c @@ -463,7 +463,7 @@ void makeMenu() { * @param width New width * @param height New height */ -void windowReshape(int width, int height) { +void windowReshape(int w, int h) { /*glViewport(0, 0, (GLsizei)width, (GLsizei)height); printf("Width: %d, height: %d\n", width, height); glMatrixMode(GL_PROJECTION); @@ -476,6 +476,18 @@ void windowReshape(int width, int height) { GLdouble a = (GLfloat)height/(GLfloat)width; GLdouble fov = 60; glFrustum( -a*near*tan(fov/2), a*near*tan(fov/2), -a*near*tan(fov/2), a*near*tan(fov/2), near, far )*/ + glViewport(0, 0, (GLsizei) w, (GLsizei) h); // what's GLsizei? Why is it called inside glViewPort? + glMatrixMode(GL_PROJECTION); // is it necessary to reset the projection matrix? + glLoadIdentity(); + if (w <= h) // is this calculation universal, could I use it on another program? + glOrtho(-5.0, 5.0, -5.0*(GLfloat)h/(GLfloat)w, + 5.0*(GLfloat)h/(GLfloat)w, -5.0, 5.0); + + else + glOrtho(-5.0*(GLfloat)w/(GLfloat)h, + 5.0*(GLfloat)w/(GLfloat)h, -5.0, 5.0, -5.0, 5.0); + glMatrixMode(GL_MODELVIEW); // why do I set to GL_MODELVIEW at the end? + glLoadIdentity(); // why does it get a reset? } /** -- 2.20.1