tweaked z_camera constant for default 60 deg perspective angle

This commit is contained in:
Tomas Frydrych 2007-06-26 16:07:14 +00:00
parent f4029ab77c
commit 761a5f4d9d
3 changed files with 50 additions and 10 deletions

View File

@ -1,3 +1,12 @@
2007-06-26 Tomas Frydrych <tf@openedhand.com>
* clutter/cogl/gl/cogl.c:
* clutter/cogl/gles/cogl.c:
(cogl_setup_viewport):
For default perspective angle of 60 degrees, use a hardcoded
z_camera constant that provides minimal artefacts when rendering
text; for other angles we calculate.
2007-06-26 Tomas Frydrych <tf@openedhand.com> 2007-06-26 Tomas Frydrych <tf@openedhand.com>
* clutter/clutter-actor.h: * clutter/clutter-actor.h:

View File

@ -494,7 +494,6 @@ cogl_setup_viewport (guint width,
ClutterFixed z_far) ClutterFixed z_far)
{ {
GLfloat z_camera; GLfloat z_camera;
ClutterFixed fovy_rad = CFX_MUL (fovy, CFX_PI) / 180;
GE( glViewport (0, 0, width, height) ); GE( glViewport (0, 0, width, height) );
@ -506,10 +505,31 @@ cogl_setup_viewport (guint width,
GE( glMatrixMode (GL_MODELVIEW) ); GE( glMatrixMode (GL_MODELVIEW) );
GE( glLoadIdentity () ); GE( glLoadIdentity () );
/* camera distance from screen, 0.5 * tan (FOV) */ /*
#define DEFAULT_Z_CAMERA 0.866025404f * camera distance from screen, 0.5 * tan (FOV)
z_camera = CLUTTER_FIXED_TO_FLOAT (CFX_DIV (clutter_sinx (fovy_rad), *
clutter_cosx (fovy_rad)) >> 1); * 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( glTranslatef (-0.5f, -0.5f, -z_camera) );
GE( glScalef ( 1.0f / width, GE( glScalef ( 1.0f / width,
-1.0f / height, -1.0f / height,

View File

@ -502,7 +502,6 @@ cogl_setup_viewport (guint w,
gint width = (gint) w; gint width = (gint) w;
gint height = (gint) h; gint height = (gint) h;
ClutterFixed z_camera; ClutterFixed z_camera;
ClutterFixed fovy_rad = CFX_MUL (fovy, CFX_PI) / 180;
GE( glViewport (0, 0, width, height) ); GE( glViewport (0, 0, width, height) );
GE( glMatrixMode (GL_PROJECTION) ); GE( glMatrixMode (GL_PROJECTION) );
@ -517,10 +516,22 @@ cogl_setup_viewport (guint w,
GE( glMatrixMode (GL_MODELVIEW) ); GE( glMatrixMode (GL_MODELVIEW) );
GE( glLoadIdentity () ); GE( glLoadIdentity () );
/* camera distance from screen, 0.5 * tan (FOV) */ /*
#define DEFAULT_Z_CAMERA 0.866025404f * camera distance from screen, 0.5 * tan (FOV)
z_camera = CFX_DIV (clutter_sinx (fovy_rad), *
clutter_cosx (fovy_rad)) >> 1; * 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)); GE( glTranslatex (-1 << 15, -1 << 15, -z_camera));