我是游戏编程的相对新手。我知道如何使用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