0

我搜索并阅读了多个关于 openGL 透明度的论坛,我发现了这段代码

gl.glEnable(GL2.GL_BLEND);
gl.glBlendFunc(GL2.GL_SRC_ALPHA, GL2.GL_ONE_MINUS_SRC_ALPHA);
gl.glEnable(GL2.GL_ALPHA_TEST);
gl.glAlphaFunc(GL2.GL_GREATER, 0.1f);
gl.glClearColor(0, 0, 0, 0);

有些人在方法中编写了这段代码init并得到了结果。我真的不知道混合了,但是我添加了这段代码,但什么也没发生!

这里有什么错误或误解吗!?我怎样才能做到这一点?

顺便说一句,我正在使用jogl 2.0

4

1 回答 1

-1

以下是如何GLJPanel通过改进它来制作透明的GLCapabilities

/** Creates an instance of a transparent GLJPanel. **/
public static final GLJPanel createTransparentPanel() {
    /* Instantiate a new set of GLCapabilities based upon the System's default parameters. */
    final GLCapabilities lGLCapabilities = new GLCapabilities(GLProfile.getDefault());
    /* Define that we don't wish for the background to be opaque. */
    lGLCapabilities.setBackgroundOpaque(false);
    /* Create a new GLJPanel based on these capabilities. */
    final GLJPanel lGLJPanel = new GLJPanel(lGLCapabilities);
    /* Disable opacity for the panel. */
    lGLJPanel.setOpaque(false);
    /* Return the panel. */
    return lGLJPanel;
}

然后可以将其添加到透明的JFrame. 您可以通过调用为您的 JFrame 启用透明度:

.setBackground(new Color(0,0,0,0));
于 2014-10-18T12:21:20.560 回答