问题描述
我搜索了&阅读了多个有关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上设置透明背景?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!