From: Diederick Niehorster Date: Fri, 16 Mar 2012 06:05:33 +0000 (+0000) Subject: now a toggle for perspective/orthogonal projection in shapes demo X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?a=commitdiff_plain;ds=sidebyside;h=ba18146fd9c60026c42e2dac896222b781fb588b;p=freeglut now a toggle for perspective/orthogonal projection in shapes demo git-svn-id: svn+ssh://svn.code.sf.net/p/freeglut/code/trunk/freeglut/freeglut@1152 7f0cb862-5218-0410-a997-914c9d46530a --- diff --git a/progs/demos/shapes/shapes.c b/progs/demos/shapes/shapes.c index 45f9944..eb4544f 100644 --- a/progs/demos/shapes/shapes.c +++ b/progs/demos/shapes/shapes.c @@ -13,6 +13,7 @@ - Esc   Quit - q Q   Quit - i I   Show info + - p P   Toggle perspective or orthographic projection - = +   Increase \a slices - - _   Decreate \a slices - , <   Decreate \a stacks @@ -64,6 +65,8 @@ static double orad = 1.0; /* doubles as size for objects other than Torus */ static int depth = 4; static double offset[ 3 ] = { 0, 0, 0 }; static GLboolean show_info = GL_TRUE; +static float ar; +static int persProject = 1; /* * These one-liners draw particular objects, fetching appropriate @@ -224,16 +227,9 @@ static void shapesPrintf (int row, int col, const char *fmt, ...) static void resize(int width, int height) { - const float ar = (float) width / (float) height; + ar = (float) width / (float) height; glViewport(0, 0, width, height); - - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - glFrustum(-ar, ar, -1.0, 1.0, 2.0, 100.0); - - glMatrixMode(GL_MODELVIEW); - glLoadIdentity() ; } static void display(void) @@ -241,6 +237,15 @@ static void display(void) const double t = glutGet(GLUT_ELAPSED_TIME) / 1000.0; const double a = t*90.0; + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + if (persProject) + glFrustum(-ar, ar, -1.0, 1.0, 2.0, 100.0); + else + glOrtho(-ar*3, ar*3, -3.0, 3.0, 2.0, 100.0); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glEnable(GL_LIGHTING); @@ -309,6 +314,9 @@ key(unsigned char key, int x, int y) case '0': case ')': ++depth; break; + case 'P': + case 'p': persProject=!persProject; break; + default: break; }