Jogl: How to make a transparent background on com.jogamp.opengl.swt.GLCanvas?

℡╲_俬逩灬. 提交于 2019-12-11 16:51:56

问题


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);

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?

I'm using jogl 2.0 by the way.


回答1:


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;
}

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));


来源:https://stackoverflow.com/questions/13106780/jogl-how-to-make-a-transparent-background-on-com-jogamp-opengl-swt-glcanvas

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!