summaryrefslogtreecommitdiffstats
path: root/src/demos/jgears
diff options
context:
space:
mode:
authorKenneth Russel <[email protected]>2005-06-30 19:30:25 +0000
committerKenneth Russel <[email protected]>2005-06-30 19:30:25 +0000
commit0afd53cb292d371c562aac7bb0e162ee2ff40bac (patch)
treef1c260f62b6659b9fb5fa6d96e4c8723e4fc55d7 /src/demos/jgears
parentbfef7ff416742912f7859792475f202e257b3bce (diff)
Fixed Issue 168: Add support for transparency in GLJPanel
Obey setOpaque() when selecting buffered image type. User must still request alpha bits in the GLCapabilities. Not supported on all back-end renderers; for example, Microsoft GDI renderer does not implement alpha bits when rendering to DIB sections. Added examples of use in JGears and JRefract demos. git-svn-id: file:///usr/local/projects/SUN/JOGL/git-svn/../svn-server-sync/jogl-demos/trunk@96 3298f667-5e0e-4b4a-8ed4-a3559d26a5f4
Diffstat (limited to 'src/demos/jgears')
-rw-r--r--src/demos/jgears/JGears.java31
1 files changed, 27 insertions, 4 deletions
diff --git a/src/demos/jgears/JGears.java b/src/demos/jgears/JGears.java
index ee0690c..59e6c79 100644
--- a/src/demos/jgears/JGears.java
+++ b/src/demos/jgears/JGears.java
@@ -2,6 +2,7 @@ package demos.jgears;
import java.awt.*;
import java.awt.event.*;
+import javax.swing.*;
import net.java.games.jogl.*;
@@ -14,11 +15,33 @@ import net.java.games.jogl.*;
public class JGears {
public static void main(String[] args) {
- Frame frame = new Frame("Gear Demo");
- GLJPanel drawable = GLDrawableFactory.getFactory().createGLJPanel(new GLCapabilities());
-
+ JFrame frame = new JFrame("Gear Demo");
+ frame.getContentPane().setLayout(new BorderLayout());
+ GLCapabilities caps = new GLCapabilities();
+ caps.setAlphaBits(8);
+ final GLJPanel drawable = GLDrawableFactory.getFactory().createGLJPanel(caps);
+ drawable.setOpaque(false);
drawable.addGLEventListener(new GearRenderer());
- frame.add(drawable);
+
+ JPanel gradientPanel = new JPanel() {
+ public void paintComponent(Graphics g) {
+ ((Graphics2D) g).setPaint(new GradientPaint(0, 0, Color.WHITE,
+ getWidth(), getHeight(), Color.DARK_GRAY));
+ g.fillRect(0, 0, getWidth(), getHeight());
+ }
+ };
+ gradientPanel.setLayout(new BorderLayout());
+ frame.getContentPane().add(gradientPanel, BorderLayout.CENTER);
+ gradientPanel.add(drawable, BorderLayout.CENTER);
+
+ final JCheckBox checkBox = new JCheckBox("Transparent", true);
+ checkBox.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ drawable.setOpaque(!checkBox.isSelected());
+ }
+ });
+ frame.getContentPane().add(checkBox, BorderLayout.SOUTH);
+
frame.setSize(300, 300);
final Animator animator = new Animator(drawable);
frame.addWindowListener(new WindowAdapter() {