From 9f57cfa1b2760a4cc0d761ac8830711fb1b409a1 Mon Sep 17 00:00:00 2001 From: David Rose Date: Thu, 26 Feb 2004 18:46:44 +0000 Subject: [PATCH] add fill_ratio --- panda/src/distort/projectionScreen.cxx | 24 +++++++++++++++++++++--- panda/src/distort/projectionScreen.h | 5 +++-- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/panda/src/distort/projectionScreen.cxx b/panda/src/distort/projectionScreen.cxx index d70a5a1b06..52a6d3fe0d 100644 --- a/panda/src/distort/projectionScreen.cxx +++ b/panda/src/distort/projectionScreen.cxx @@ -163,10 +163,22 @@ set_projector(const NodePath &projector) { // and vertical dimension of the projector, // respectively; distance represents the approximate // distance of the screen from the lens center. +// +// The fill_ratio parameter specifies the fraction of +// the image to cover. If it is 1.0, the entire image +// is shown full-size; if it is 0.9, 10% of the image +// around the edges is not part of the grid (and the +// grid is drawn smaller by the same 10%). This is +// intended to work around graphics drivers that tend to +// show dark edges or other unsatisfactory artifacts +// around the edges of textures: render the texture +// larger than necessary by a certain fraction, and make +// the screen smaller by the inverse fraction. //////////////////////////////////////////////////////////////////// PT(GeomNode) ProjectionScreen:: generate_screen(const NodePath &projector, const string &screen_name, - int num_x_verts, int num_y_verts, float distance) { + int num_x_verts, int num_y_verts, float distance, + float fill_ratio) { nassertr(!projector.is_empty() && projector.node()->is_of_type(LensNode::get_class_type()), NULL); @@ -188,10 +200,15 @@ generate_screen(const NodePath &projector, const string &screen_name, coords.reserve(num_verts); float x_scale = 2.0f / (num_x_verts - 1); float y_scale = 2.0f / (num_y_verts - 1); + for (int yi = 0; yi < num_y_verts; yi++) { for (int xi = 0; xi < num_x_verts; xi++) { LPoint2f film = LPoint2f((float)xi * x_scale - 1.0f, (float)yi * y_scale - 1.0f); + + // Reduce the image by the fill ratio. + film *= fill_ratio; + LPoint3f near_point, far_point; lens->extrude(film, near_point, far_point); @@ -264,14 +281,15 @@ generate_screen(const NodePath &projector, const string &screen_name, //////////////////////////////////////////////////////////////////// void ProjectionScreen:: regenerate_screen(const NodePath &projector, const string &screen_name, - int num_x_verts, int num_y_verts, float distance) { + int num_x_verts, int num_y_verts, float distance, + float fill_ratio) { // First, remove all existing children. remove_all_children(); // And attach a new child. PT(GeomNode) geom_node = generate_screen(projector, screen_name, num_x_verts, num_y_verts, - distance); + distance, fill_ratio); add_child(geom_node); } diff --git a/panda/src/distort/projectionScreen.h b/panda/src/distort/projectionScreen.h index 36e087ec9a..f4c70176ab 100644 --- a/panda/src/distort/projectionScreen.h +++ b/panda/src/distort/projectionScreen.h @@ -67,9 +67,10 @@ PUBLISHED: PT(GeomNode) generate_screen(const NodePath &projector, const string &screen_name, int num_x_verts, int num_y_verts, - float distance); + float distance, float fill_ratio); void regenerate_screen(const NodePath &projector, const string &screen_name, - int num_x_verts, int num_y_verts, float distance); + int num_x_verts, int num_y_verts, float distance, + float fill_ratio); PT(PandaNode) make_flat_mesh(const NodePath &camera); INLINE void set_invert_uvs(bool invert_uvs);