Jogl:如何在com.jogamp.opengl.swt.GLCanvas上设置透明背景? [英] Jogl: How to make a transparent background on com.jogamp.opengl.swt.GLCanvas?

查看:281
本文介绍了Jogl:如何在com.jogamp.opengl.swt.GLCanvas上设置透明背景?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I searched & read multiple forums about openGL transparency and I found this piece of code

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方法中编写了此代码,并获得了结果.我真的不了解Blending,但是我添加了这段代码,什么也没发生!

Some people wrote this code inside the init method and got result. I really don't know anymore about Blending, but I added this code and nothing happened!

这里是否有任何错误或误解!?我该怎么办?

Is there any mistake or misunderstanding here!? How can I do that?

我正在使用jogl 2.0.

推荐答案

在这里,您可以通过优化GLCapabilities来制作透明的GLJPanel:

Here is how you can make a transparent GLJPanel, via refining it's 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启用透明性:

This can then be added to a transparent JFrame. You can enable transparency for your JFrame by calling:

.setBackground(new Color(0,0,0,0));

这篇关于Jogl:如何在com.jogamp.opengl.swt.GLCanvas上设置透明背景?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆