From 3cdc195408626066c033868a68a3f50a3d9c6e95 Mon Sep 17 00:00:00 2001 From: Tomas Frydrych Date: Tue, 26 Jun 2007 16:07:14 +0000 Subject: [PATCH] tweaked z_camera constant for default 60 deg perspective angle --- gl/cogl.c | 30 +++++++++++++++++++++++++----- gles/cogl.c | 21 ++++++++++++++++----- 2 files changed, 41 insertions(+), 10 deletions(-) diff --git a/gl/cogl.c b/gl/cogl.c index d99649917..c8a3cda29 100644 --- a/gl/cogl.c +++ b/gl/cogl.c @@ -494,7 +494,6 @@ cogl_setup_viewport (guint width, ClutterFixed z_far) { GLfloat z_camera; - ClutterFixed fovy_rad = CFX_MUL (fovy, CFX_PI) / 180; GE( glViewport (0, 0, width, height) ); @@ -506,10 +505,31 @@ cogl_setup_viewport (guint width, GE( glMatrixMode (GL_MODELVIEW) ); GE( glLoadIdentity () ); - /* camera distance from screen, 0.5 * tan (FOV) */ -#define DEFAULT_Z_CAMERA 0.866025404f - z_camera = CLUTTER_FIXED_TO_FLOAT (CFX_DIV (clutter_sinx (fovy_rad), - clutter_cosx (fovy_rad)) >> 1); + /* + * camera distance from screen, 0.5 * tan (FOV) + * + * We have been having some problems with this; the theoretically correct + * value of 0.866025404f for the default 60 deg fovy angle happens to be + * touch to small in reality, which on full-screen stage with an actor of + * the same size results in about 1px on the left and top edges of the + * actor being offscreen. Perhaps more significantly, it also causes + * hinting artifacts when rendering text. + * + * So for the default 60 deg angle we worked out that the value of 0.8699 + * is giving correct stretch and no noticeable artifacts on text. + */ +#define DEFAULT_Z_CAMERA 0.8699f + z_camera = DEFAULT_Z_CAMERA; + + if (fovy != CFX_60) + { + ClutterFixed fovy_rad = CFX_MUL (fovy, CFX_PI) / 180; + + z_camera = + CLUTTER_FIXED_TO_FLOAT (CFX_DIV (clutter_sinx (fovy_rad), + clutter_cosx (fovy_rad)) >> 1); + } + GE( glTranslatef (-0.5f, -0.5f, -z_camera) ); GE( glScalef ( 1.0f / width, -1.0f / height, diff --git a/gles/cogl.c b/gles/cogl.c index b279df59e..3fb1631aa 100644 --- a/gles/cogl.c +++ b/gles/cogl.c @@ -502,7 +502,6 @@ cogl_setup_viewport (guint w, gint width = (gint) w; gint height = (gint) h; ClutterFixed z_camera; - ClutterFixed fovy_rad = CFX_MUL (fovy, CFX_PI) / 180; GE( glViewport (0, 0, width, height) ); GE( glMatrixMode (GL_PROJECTION) ); @@ -517,10 +516,22 @@ cogl_setup_viewport (guint w, GE( glMatrixMode (GL_MODELVIEW) ); GE( glLoadIdentity () ); - /* camera distance from screen, 0.5 * tan (FOV) */ -#define DEFAULT_Z_CAMERA 0.866025404f - z_camera = CFX_DIV (clutter_sinx (fovy_rad), - clutter_cosx (fovy_rad)) >> 1; + /* + * camera distance from screen, 0.5 * tan (FOV) + * + * See comments in ../gl/cogl.c + */ +#define DEFAULT_Z_CAMERA 0.8699f + z_camera = CLUTTER_FLOAT_TO_FIXED (DEFAULT_Z_CAMERA); + + if (fovy != CFX_60) + { + ClutterFixed fovy_rad = CFX_MUL (fovy, CFX_PI) / 180; + + z_camera = CFX_DIV (clutter_sinx (fovy_rad), + clutter_cosx (fovy_rad)) >> 1; + } + GE( glTranslatex (-1 << 15, -1 << 15, -z_camera));