Skip to content
This repository has been archived by the owner on Jan 14, 2023. It is now read-only.

Does not render for transparent backgrounds #35

Open
Jire opened this issue Sep 10, 2016 · 0 comments
Open

Does not render for transparent backgrounds #35

Jire opened this issue Sep 10, 2016 · 0 comments

Comments

@Jire
Copy link

Jire commented Sep 10, 2016

GLG2D, and seemingly every JOGL/LWJGL do not render on transparent backgrounds (backgrounds with a color alpha of less than 1F). It renders absolutely nothing, even on 0.999F, but as soon as the alpha is 1F it works as intended.

The reason this is so important is to make "overlays" which draw directly atop the desktop, which is quite common in game mods / cheats.

Here's my demo:

import org.jogamp.glg2d.GLG2DCanvas;

import javax.swing.*;
import java.awt.*;

public final class OverlayDemo extends JWindow {

    private static final Dimension SCREEN_SIZE = Toolkit.getDefaultToolkit().getScreenSize();

    private final JPanel frame = new JPanel() {
        @Override
        protected void paintComponent(Graphics g) {
            g.setColor(Color.GREEN);
            g.fillRect(100, 100, 200, 200);
        }
    };

    private OverlayDemo() {
        setSize(SCREEN_SIZE);
        setBackground(new Color(0, 0, 0, 0 /* alpha */));

        frame.setSize(SCREEN_SIZE);
        frame.setDoubleBuffered(true);

        setContentPane(new GLG2DCanvas(frame));
        setVisible(true);

        new Thread(() -> {
            while (!Thread.interrupted()) {
                repaint();
                try {
                    Thread.sleep(50);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                    return;
                }
            }
        }).start();
    }

    public static void main(String[] args) {
        SwingUtilities.invokeLater(OverlayDemo::new);
    }

}
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant