我是遊戲編程的相對新手。我知道如何使用setPixel()
將像素繪製到BufferedImage
。在較大的格式下速度非常慢,所以我繼續前進,發現VolatileImage
(花了我一個星期左右的時間)。繪製線條,字符串,矩形等相當容易,但我無法繪製單個像素。我已經嘗試過使用drawLine(x,y,x,y)
,但我在800x600圖像上獲得3-4 FPS。 java在VolatileImage
中沒有包含setPixel()
或setRGB()
的事實讓我非常生氣和困惑。爲什麼VolatileImage沒有set/getPixel()方法
我有4個問題:
有沒有辦法畫上一個VolatileImage,個別像素? (關於1440格式的FPS> 40)
能否繪製像素與更快的方法一個BufferedImage? (同1440,FPS> 40)
是否有任何其他的方式來繪製像素足夠快的3D遊戲?
我可以讓我的BufferedImage的硬件加速(使用
setAccelerationPriority(1F)
嘗試,但它不工作)
請,如果您有任何想法告訴我。我無法繼續讓我的遊戲沒有這個信息。我已經制作了3D渲染算法,但我需要能夠繪製快速像素。我對這個遊戲有很好的感覺。
下面的代碼,如果它可以幫助你來幫助我
public static void drawImageRendered (int x, int y, int w, int h) { // This is just a method to test the performance
int a[] = new int[3]; // The array containing R, G and B value for each pixel
bImg = Launcher.contObj.getGraphicsConfiguration().createCompatibleImage(800, 600); // Creates a compatible image for the JPanel object i am working with (800x600)
bImg.setAccelerationPriority(1F); // I am trying to get this image accelerated
WritableRaster wr = bImg.getRaster(); // The image's writable raster
for (int i = 0; i < bImg.getWidth(); i++) {
for (int j = 0; j < bImg.getHeight(); j++) {
a[0] = i % 256;
a[2] = j % 256;
a[1] = (j * i) % 256;
wr.setPixel(i, j, a); // Sets the pixels (You get a nice pattern)
}
}
g.drawImage(bImg, x, y, w, h, null);
}
我更希望不使用的OpenGL 或任何其他外部庫,只是普通的Java。
良好的工作夥計,以及我不知道你將如何繪製目標圖像,但我沒有刷新時間緩衝的圖像和繪畫問題(完全用純像素setRGB()),[this例如](http://arashmd.blogspot.com/2013/07/java-thread-example.html#lc)可能會有所幫助,它是關於屏幕保護程序,我已經超過60 FPS只有CPU,超過500 FPS與GPU – 2013-10-12 19:33:25
仍然沒有找到任何可以幫助我的東西 –
那麼您是否以平行方式繪製圖像?你如何管理目標圖像/畫框花花公子? – 2013-10-12 19:58:23