点击JMenu选项会导致我的JOGL GLCanvas闪烁。
JMenu将setDefaultLightWeightPopupEnabled设置为false。我不想使用JGLPanel,因为它运行较慢(应用程序需要在全屏模式下运行)。
有趣的是,如果我在命令行中设置了sun.java2d.opengl=true,闪烁就会停止。然而,sun在默认情况下没有启用此功能的事实让我担心我的用户可能会遇到硬件不兼容的问题。
当单击菜单时,其他人是否看到下面的代码闪烁?
我尝试了所有的东西,比如使用JFrame和画布的双缓冲选项,但没有幸运地让画布不闪烁。
当查看菜单选项时,有没有人能让它不闪烁?
谢谢!
-Dan
import javax.media.opengl.*;
import javax.swing.*;
public class FlickerTest extends JFrame {
private GLCapabilities m_caps = new GLCapabilities();
public FlickerTest() {
super("FlickerTest");
GLCanvas canvas = new GLCanvas(m_caps);
add( canvas );
canvas.addGLEventListener( new MyGLEventListener() );
setSize( 640, 480 );
setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
// false lets the JMenuBar appear on top of the remote image openGL canvas
JPopupMenu.setDefaultLightWeightPopupEnabled(false);
setJMenuBar( getMyMenuBar() );
setVisible( true );
}
public static void main(String[] args) {
new FlickerTest();
}
private static JMenuBar getMyMenuBar() {
JMenuBar menuBar = new JMenuBar();
JMenu fileMenu = new JMenu("File");
JMenuItem quitMenuItem = new JMenuItem( "Quit" );
JMenuItem doSomething = new JMenuItem("Do Something");
fileMenu.add( quitMenuItem );
fileMenu.add( doSomething );
menuBar.add( fileMenu );
return menuBar;
}
private class MyGLEventListener implements GLEventListener {
private MyGLEventListener() {
}
public void init(GLAutoDrawable drawable) {
GL gl = drawable.getGL();
gl.glClearColor(1,1,0,0);
gl.glBlendFunc(GL.GL_ONE,GL.GL_ONE);
gl.glEnable(GL.GL_BLEND);
}
public synchronized void display( GLAutoDrawable p_glAutoDrawable ) {
GL gl = p_glAutoDrawable.getGL();
gl.glClear(GL.GL_COLOR_BUFFER_BIT);
gl.glColor3f(0,0,1);
gl.glRectf(-.5f,-.5f,.5f,.5f);
gl.glFlush();
}
public void reshape(GLAutoDrawable p_drawable, int x, int y, int w, int h) {
}
public void displayChanged(GLAutoDrawable drawable, boolean modeChanged, boolean deviceChanged) {
}
}
}发布于 2009-01-06 00:26:59
尝试在JFrame构造函数中调用createBufferStrategy(2);。这应该会在JFrame中启用双缓冲。
发布于 2009-02-06 10:18:06
这是由于AWT在JOGL重绘之前每次都会擦除GLCanvas造成的,可以通过在main()方法中插入以下行来解决此问题:
System.setProperty("sun.awt.noerasebackground", "true");
虽然这解决了给定的问题,但在应用程序的其他方面也可能产生副作用,例如在调整窗口大小时出现可见的伪像。我在我所有的JOGL应用程序中都使用了它,但没有任何问题。
发布于 2009-01-07 15:14:08
您可能想要添加一个animator。画布可能会闪烁,因为JFrame刷新速度不够快。
FPSAnimator = new FPSAnimator(GLCanvas,int TARGET_FPS, boolean);https://stackoverflow.com/questions/414915
复制相似问题