Trouble getting CALayers to be transparent

  • I want to put  transparent CALayers over an OpenGL Texture and use
    CAAnimation to fade them in. I thought it would be possible to use
    Core Text in the CALayers to accomplish this.

    I can get Core Text into the CALayers. I can use CAAnimation to fade
    them in, but I cannot get the layers to be transparent.

    I have an existing/in progress hybrid Cocoa OpenGL appliction. Before
    Leopard, I was showing large amounts of scrollable text over an
    OpenGL texture by overlaying a transparent window (making it a child
    window) and adding a subview - an NSScrollView with a transparent
    background, into the child window which displayed my text.

    When Leopard came along, I thought it would be nice to animate the
    opacity resulting in a gentle fade in for each 'page' of text. But
    every experiment I have tried results in the text displayed on a
    white opaque background. Even without the CAAnimation.

    I am sure that I am just missing some fundamental simple point. I
    hope someone can help.

    I have tried:
    1. just telling the existing 'NSScrollview' in the transparent Child
    window  - setWantsLayer:YES
    Result - animates fading in text with white Opaque background.

    2. Subclassing CALayer and drawing the text in a
    drawInContext:(CGContextRef)context
    Using Coretext. Result - animates fading in Text with white Opaque background.

    2a. telling the new view that contains the subclassed CALayer -
    [theView setBackgroundColor:[NSColor clearColor]];

    2b. in my drawInContext:(CGContextRef)context: I try to fill the
    rectangle of the view with a transparent CGColor:
      CGContextBeginTransparencyLayer (context, NULL);
      CGContextClearRect(context, frame);
    etc. until
      CGContextEndTransparencyLayer (context);
    or
    CGFloat transparentValues[4] = {0.0, 0.0, 0.0, 0.0};
    CGColorSpaceRef space =
    CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB);
    CGColorRef clearOne  = CGColorCreate(space, transparentValues);

    Result: animates fading in Text with white Opaque background.

    2c. tried adding a compositing filter to the layer compositing 'srcOver'
    Result: animates fading in Text with white Opaque background.

    I have tried creating a coloured background, and the colour draws
    sort of translucently over the text and the white opaque background.

    Can anyone help? Is it a CoreText bug with CALayers or have I missed
    something really fundamental?

    Vickie
previous month january 2008 next month
MTWTFSS
  1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31      
Go to today