【发布时间】:2013-10-17 14:46:05
【问题描述】:
很长一段时间,1-2 个月,我一直试图找到这个特定问题的答案:
我的图像硬件无法加速!
我一直在网上搜索,创建了自己的方法,用键盘敲击我的头(仍然感到疼痛)但没有成功。
虽然我讨厌 Java SDK 以外的库,但我尝试了 LWJGL 和 JOGL,但由于某些愚蠢的原因,它们无法在我的计算机上运行。
我尝试使用System.setProperty("Dsun.java2d.opengl", "True"),我使用了 VolatileImage,但我无法为其绘制单个像素。(我尝试使用drawLine(x,y,x,y),但速度很慢)
现在我很绝望。我会做任何事情来解决这个问题!所以,如果你知道解决方案(我知道你们中的一些人知道)请告诉我,这样我就可以解决这个问题。
我的代码:
public static void render(int x, int y, int w, int h, ) {
int a[] = new int[3]; // The array that contains RGB values for every pixel
BufferedImage bImg = Launcher.contObj.getGraphicsConfiguration().createCompatibleImage(800, 600, Transparency.TRANSLUCENT); // Creates an image compatible to my JPanel (Runs at 20-24 FPS on 800x600 resolution)
int[] wr = ((DataBufferInt) bImg.getRaster().getDataBuffer()).getData(); // Contains the image data, used for drawing pixels
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] = i * j % 256;
wr[i + j * bImg.getWidth()] = new Color(a[0], a[1], a[2]).getRGB(); // Sets the pixels from a[]
}
}
bImg.flush();
g.drawImage(bImg, x, y, w, h, null); // Draws the image on the JPanel
g.dispose();
System.out.println(bImg.getCapabilities(Launcher.contObj.getGraphicsConfiguration()).isAccelerated()); // Prints out whether I was successful and made the image accelerated or failed and made everything worse
}
我希望你能理解代码。请以任何方式修改它以帮助我找到解决问题的方法。
注意:请不要发布有关外部库的任何内容,除非您完全确定没有它们我无法正常工作。
还有,是不是我的显卡不支持加速? (因为我看到了硬件加速适用于其他人但不适用于我的帖子)顺便说一句,它是 GeForce 430 GT。
提前致谢!
【问题讨论】:
-
您希望将不断绘制像素的图像缓冲区移至 GPU 会带来什么样的性能提升?你知道,多次写入内存然后一次将整个内容转储到 GPU 比对 GPU 进行多次单独调用要快。
-
你试过我贴的例子吗!
标签: java graphics 3d acceleration