[vtk-developers] vtkTextActor (and vtkTextures?) with gradient backgrounds

David Feng dfeng at cs.unc.edu
Tue Oct 27 09:19:46 EDT 2009


Karthik Krishnan wrote:
> On Tue, Oct 27, 2009 at 8:11 AM, Jeff Baumes <jeff.baumes at kitware.com> wrote:
>   
>> On Mon, Oct 26, 2009 at 10:19 PM, David Feng <dfeng at cs.unc.edu> wrote:
>>     
>>> It looks vtkTextActor doesn't play well with gradient backgrounds.  The
>>> background disappears entirely when I add a vtkTextActor to my renderer,
>>> which is embedded in a vtkRenderView.  I suspect it's because vtkTextActor
>>> uses a vtkTexture, which enables GL_ALPHA_TEST (in the OpenGL version).  The
>>> background is rendered as a 0.0 alpha colored quad (when gradient
>>> backgrounds are enabled), and the alpha function is discarding all 0.0 alpha
>>> fragments for the following reason:
>>>
>>>  // don't accept fragments if they have zero opacity. this will stop the
>>>  // zbuffer from be blocked by totally transparent texture fragments.
>>>  glAlphaFunc (GL_GREATER, static_cast<GLclampf>(0));
>>>  glEnable (GL_ALPHA_TEST);
>>>
>>> Simply adding glDisable(GL_ALPHA_TEST) to the PostRender method didn't
>>> seem to affect my output, so my diagnosis could be wrong.  If it is
>>> something along these lines, I'm seems like all vtkTextures will clobber
>>> gradient backgrounds.
>>>
>>> Regardless, it looks like vtkTextMapper doesn't cause these problems, so
>>> I'll be switch to that for now.  Does anyone know of a simple way to have
>>> the vtkTextMapper scale with viewport size?
>>>
>>>       
>> The issue we have run into several times with the gradient background is
>> that mappers/actors in VTK do not always reset their state after rendering.
>> It is not textures in general since I've used textures with a gradient
>> background before (e.g. in vtkGeoView).
>> I believe the text mapper draws pixels directly on the screen, so they are
>> always constant size. The text actor renders a texture to a quad in the
>> scene, which is why it can scale.
>>     
>
> That is right. We've noticed the issue and we tend to use
> vtkTextMapper for this, and other reasons, in some of our
> applications.
>
> We do manage to control the scaling of the actor with the viewport
> size. See the class vtkCornerAnnotation and its associated tests as an
> example. This uses a vtkTextMapper and scales as the viewport size
> changes. Essentially, it changes the font size on the text mapper in
> its internal render method RenderOpaqueGeometry. So everytime the
> viewport is scaled, the text mapper automatically assumes the right
> size. You could do the same by wrapping your mapper/actor2D pair in
> your own vtkActor2D.
>
> Hope this helps.
>
>   
That's helpful -- I'll take a look.  I also ran into unusual blending 
problems that resulted in the text looking thick and pixelated when 
rendering a vtkTextActor to a framebuffer object (but only 
sometimes...), which is probably happening for similar reasons.

Thanks for the help,
David



More information about the vtk-developers mailing list