I have been playing recently with the new JOGL feature that allows to mix Swing and OpenGL without any artifact. Despite a few minor problems, I'm glad to say it works really well. I got two demos for you.
The first one shows one of the gears from the famous Gears demo used as an icon in a JButton. Whenever the mouse enters the button, the gear starts rotating. Besides the screenshot below, you can take a look at a video (http://jext.free.fr/button3d.mov
) and at the source code (http://jext.free.fr/3DButton.zip
). The source code is more a proof of concept than a real solution. I basically set a blank text on the JButton, change its layout to FlowLayout and add a GLJPanel and a JLabel into the button. As a drawback, the focus is not painted correctly. I have a few ideas for better implementations though.
The second demo is the opposite. Instead of putting an OpenGL scene into a JButton, it shows JButtons inside an OpenGL scene (+ extra Java2D stuff). I haven't released the source code yet because I'd like to disclose it at JavaPolis in two weeks. I will post the source code the 15th or the 16th of December. I have uploaded a video of the demo in different formats: QuickTime 7 (http://jext.free.fr/twinkle.mov
), XviD (http://jext.free.fr/twinkle.avi
) and DivX 6 (http://jext.free.fr/twinkle.divx
). The text and the pictures strip are drawn with Java2D and the buttons at the bottom left are JButton in a JPanel (the rounded rectangle).
While developing those demos I have stumbled into two important issues. First, using full scene antialiasing doesn't work (but Ken told me he'd be working on that
. Instead I am using the old ugly accum buffer trick but the major drawback is you lose the possible transparency of the GLJPanel. The second issue is related to Java2D antialiasing. The text and the rounded rectangle in the second demo are painted into offscreen BufferedImages. Painting them directly onto the screen procudes visual artifacts. Chris Campbell and I actually discovered that it happens with text if the font size is greater than 16 (if it is you'll see each character replaced by the last character of the string). So beware