我希望有人碰巧遇到了以下問題。在Mac OS上不支持Java頁面翻轉?
我的Java應用程序在Mac上有圖形性能問題,所以我做了一個簡單的測試應用程序(下面的代碼)。當我在Windows上運行此,控制檯告訴我:
的GraphicsConfiguration翻轉?真
BufferStrategy翻轉?真正
當我運行在Mac OS完全相同的代碼,我得到:
的GraphicsConfiguration翻轉?真
BufferStrategy翻轉?假
這是否意味着在Mac OS上,在窗口應用程序中不支持翻頁?是否有任何技巧可以使頁面在Mac OS上無需全屏翻動?
所有指針都非常歡迎,
Mattijs
在Windows XP和Mac OS 10.5使用JDK 1.6。
代碼:
import java.awt.image.BufferStrategy;
import javax.swing.*;
import java.awt.*;
public class Test {
int width = 640;
int height = 480;
GraphicsEnvironment graphEnv = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice graphDevice = graphEnv.getDefaultScreenDevice();
GraphicsConfiguration graphicConf = graphDevice.getDefaultConfiguration();
public Test() {
JFrame jFrame = new JFrame(graphicConf);
jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jFrame.setTitle("double buffer test");
jFrame.setResizable(false);
jFrame.setFocusTraversalKeysEnabled(false);
Canvas canvas = new Canvas();
canvas.setSize(width, height);
canvas.setIgnoreRepaint(true);
jFrame.getContentPane().add(canvas);
jFrame.pack();
jFrame.setVisible(true);
System.out.println("GraphicsConfiguration flipping? " + graphicConf.getBufferCapabilities().isPageFlipping());
canvas.createBufferStrategy(2);
BufferStrategy bufferStrategy = canvas.getBufferStrategy();
System.out.println("BufferStrategy flipping? " + bufferStrategy.getCapabilities().isPageFlipping());
while(true) {
Graphics g = bufferStrategy.getDrawGraphics();
g.setColor(Color.BLACK);
g.fillRect(0,0,width,height);
g.setColor(Color.RED);
g.drawLine((int)(Math.random()*width),(int)(Math.random()*height),
(int)(Math.random()*width),(int)(Math.random()*height));
bufferStrategy.show();
g.dispose();
}
}
public static void main(String[] args) {
new Test();
}
}
這是前一段時間,但我已經成功地使用頁面翻轉(不是全屏)在JOGL在Mac上。 – finnw 2010-06-25 19:36:32