Swing panel displays pixels of previous frame where pixels of current frame have alpha<1

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Swing panel displays pixels of previous frame where pixels of current frame have alpha<1

Martin
Hi,

I got a surprising bug with GLJPanel (Swing) which does not occur with GLCanvas (AWT).

To summarize my issue : I display translucent polygons which let appear content of the previous image exactly where the alpha is < 1 (see image below).

Would someone have a suggestion to solve this, given that I already verified the bellow ideas :
- Changing GLCapabilities.setBackgroundOpaque(true/false)
- Changing GLCapabilities.setDoubledBuffer(true/false)
- Changing setAutoSwapBuffer(true/false)
- Changing the depth buffer clear value (tried 1, 10, 10000, -1, -10)
- Changing the clear color to a copy of default clear color to ensure its alpha channel was not modified accidentally. Also verified that the clear color alpha channel is 1.
- The fact that AWT works proves that there is no OpenGL misconfiguration (e.g. no reason to think that the depth buffer is not cleared)

 

Reply | Threaded
Open this post in threaded view
|

Re: Swing panel displays pixels of previous frame where pixels of current frame have alpha<1

jeffreportmill
I've seen a problem where sometimes when interactively rotating I see a frame where background is red or black instead of white. It hadn't occurred to me that it might be a transparency issue. I also don't seem to see it as often for some reason (maybe it has improved with last MacOS update). I don't see it at all when transpiling to the browser (uses WebGL).

I've had trouble trying to understand the best way to render to a BufferedImage, switching from GLJPanel to GLWindow GLDrawableFactory.createOffscreenAutoDrawable() that I've separated that code into a separate source file so I can easily change it out (though I can mostly only get things to work seemlessly on Apple M1 with GLWindow - even then I'm stuck on JDK 8 v241):

    https://github.com/reportmill/SnapKitGL/blob/main/src/snapgl/DrawableUtils.java

I try to stick with just rendering to BufferedImage to simplify and isolate my OpenGL interaction with Swing. There are probably use cases down the road that will pay a performance hit for not trying to render to an onscreen window, but I prefer the simplicity. WebGL seems to encourage this model, though an HTML Canvas acts like an image that be both onscreen or off.

In any case, good luck with it! I always appreciate your help on this forum and I wish I could be of more help. :-)

jeff
Reply | Threaded
Open this post in threaded view
|

Re: Swing panel displays pixels of previous frame where pixels of current frame have alpha<1

Martin
Hi,

Thank you Jeff for sharing your experience on this. I can add something a bit similar : usually, when keeping the same 3D viewpoint in a GLJPanel, the content is a bit darker at the first frame. I then get the correct coloring after 2 or 3 frames.

GLJPanel also uses the idea of processing GL offscreen (see the backend initialization here) .

The offscreen backend relies on an OpenGL PBuffer allowing to retrieve a BufferedImage. I sometime see an FBOUtil so I am not sure the backend always use a PBuffer, but in both case this is the same idea of rendering offscreen.

I don't think you loose anything with your DrawableUtils compared to GLJPanel. And you have a more readable code :) The source code of GLJPanel is big (2600+ LOC!) so it will be hard to debug. I'll probably follow your approach if I can't find an explanation for this bug.