Skip to main content

Clip region edge match: bug or feature?

Please note these forums are being decommissioned and use the new and improved forums at
1 reply [Last post]
Joined: 2010-02-02

Greetings! I'm trying to implement simple one-color Gouraud-shaded triangles with Graphics2D primitives and no OpenGL . This is a low performance graphics fallback option for the (apparently) many video cards out there that don't play very well with JOGL, which is the main rendering path.

I'm building a color gradient in a BufferedImage and then using drawImage(bufferedImage, AffineTransform, Observer) and setClip() to the triangle. The affine transform does a triangle-to-triangle mapping to put the right swatch of pixels in the unclipped region.

There is no transform applied to the clipping region.

This all works very nicely and is easily fast enough except...

One problem: There are white pixels sprinkled along the boundaries between triangles.

This indicates that clip region edges given with exactly the same vertices don't mesh perfectly as polygon edges do. Argh...

Odd thing: tried painting each triangle 4 times: at normal location plus one pixel east, north, and northeast, expecting this to be a brute force solution. No joy. The white pixels are still there. Moreover, set the JPanel background to dark gray and the bad pixels turned that color. So it appears that pixels just outside the clip boundary are being painted with the _component_ background.

So this is starting to look like an image clipping bug or anti-aliasing getting in the way (I tried hints to turn aa off, but again no joy) or else something about the API I'm not getting.

Before I toss this painfully close-but-no-cigar attempt and move on to another, does anyone have ideas?

I can post code, but someone else seems to have run into the same behavior and already has posted an example:


Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joined: 2010-02-02

Really frustrating. I re-implemented by computing a custom GradientPaint for each triangle. It works fine, but it's about 10 times slower than the drawImage - almost a second for the ~5000 triangles I need.

Some help would really be appreciated.