• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: CGShading line, triangle?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: CGShading line, triangle?


  • Subject: Re: CGShading line, triangle?
  • From: Alex Eddy <email@hidden>
  • Date: Tue, 9 Dec 2003 11:04:53 -0800

On Tuesday, December 9, 2003, at 01:45 AM, Alastair Houghton wrote:
I think you can probably do what you want with a triangle using
multiple linear CGShadings (hint: you can fade the colour at the corner
down to transparent towards the other end of the triangle).

Ah, this approach seems like it would work, even if it takes three passes. (After writing some code... ) you can get the gradients to align correctly by drawing the gradient from the midpoint of the opposite side of the triangle to your corner plus half the vector of the opposite side. However, there is a crippling problem, see further below.

As far as doing a gradient fill of a thick line, I don't know any way
of getting the line's outline as a path, which is what you'd need in
order to do this. I think you'd have to convert it to a path manually;
it doesn't look stunningly tricky to do the necessary geometry.

But it is. The basic projection of the line endpoint onto a quad, and the addition of two arcs is easy enough, but there are some subtleties in Quartz-- for instance, if your line is between 0.0 and 1.0 pixels wide, it does not add rounded end caps, but at > 1.0 pixels it will. I don't want to recreate all of the geometry myself because I want to get _whatever it is that Quartz calculates_, not my interpretation of it.

BTW, the triangle thing would be easier (and hardware accelerated) in
OpenGL, if that's an option.

Yes, in OpenGL this is trivial which is why it is hard for me to understand how Quartz can't interpolate the same way.

However I am specifically trying to do this in Quartz in order to compare the geometry antialiasing quality against that of texture-mapped primitives in OpenGL. I already do my own geometry calculations there, I am trying to compare Quartz against that.



On Dec 9, 2003, at 9:49 AM, Henry McGilton wrote:
I suspect that what Alex wants here is a Gouraud shader. Looks like
CGShading is pretty limited --- axial and radial only?!?

At least it lets you specify a custom function for the interpolation... not just linear... :)

At first glance, you should be able to use the Axial shader with a clip
path that is constructed using NSBezierPath. What in the Axial shader is
not doing what you want?

OK, here is the crippling problem. The clip path is not antialiased. So if I fill a triangle with a solid color for one corner, that comes out antialiased, great. Then when I set the triangle as the clip path and overlay a translucent gradient from another corner's color, the edges are immediately aliased (a portion of the underlying color is visible beneath the rounded-to-nearest-integral clip path). This defeats the whole purpose of using Quartz.

The CGShading ADC example readme notes that the aliased edges bug is supposed to be fixed in Panther, but apparently it is not.

So, since in my particular case I want antialiased gradient-shaded primitives on screen (no print) and am not especially worried about the speed, I think the best approach using Quartz is to render the (rounded line / triangle / etc) path with solid white into an NSImage, render the gradient(s) into another NSImage, twiddle the first image into an alpha mask for the second image, and then composite the result into my view. Horrifically slow? Yep.

Any other alternatives? I'm listening...
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

  • Follow-Ups:
    • Re: CGShading line, triangle?
      • From: Alex Eddy <email@hidden>
References: 
 >Re: CGShading line, triangle? (From: Henry McGilton <email@hidden>)

  • Prev by Date: Mouse click inside NSView
  • Next by Date: accessibility vs dock
  • Previous by thread: Re: CGShading line, triangle?
  • Next by thread: Re: CGShading line, triangle?
  • Index(es):
    • Date
    • Thread