java图形界面2d,集成图形上的Java2D绘图缓慢

I'm working on a simple 2D game, rendering via the Java2D API. I've noticed that when I try to draw on integrated graphics card the performance crashes.

I've tested this game on both my main rig with a newer ATI Radeon and my 5 year old laptop which also has an (incredibly antiquated) Radeon. On both I get good FPS, but when I try to use my Intel i5's onboard HD 4000 graphics, it crawls at around 20 FPS.

I'm using Full Screen Exclusive mode.

At any given moment, I am rendering approximately 1000 images at once.

Annoyingly, when I try to getAvailableAcceleratedMemory() it just returns -1 for this card, and it seems to refuse to accelerate any images.

Does anyone have any ideas how to fix this issue?

Rendering code:

Graphics g = bufferStrategy.getDrawGraphics();

g.drawImage(img, x, y, img.getWidth(), img.getHeight(), null)

g.dispose();

bufferStrategy.show();

Image Loading code:

BufferedImage I = null;

I = ImageIO.read(new File(currentFolder+imgPath));

imgMap.put(imgIdentifier, I);

The images are stored in a hashmap of BufferedImages identified by strings, so when an entity needs to draw and image it just gets it out of the hashmap and draws it. In the current case, the entities are mostly floor and wall tiles, so they never change (and thus don't have to get the image from the hashmap other than the very first time).

EDIT - I've incorporated MadProgrammer's method, but it didn't change my FPS.

解决方案

This is an example of converting an image to a compatiable image...not an answer in of itself

This is some of the library code that I use...

public static BufferedImage createCompatibleImage(BufferedImage image) {

BufferedImage target = createCompatibleImage(image, image.getWidth(), image.getHeight());

Graphics2D g2d = target.createGraphics();

g2d.drawImage(image, 0, 0, null);

g2d.dispose();

return target;

}

public static BufferedImage createCompatibleImage(BufferedImage image,

int width, int height) {

return getGraphicsConfiguration().createCompatibleImage(width, height, image.getTransparency());

}

public static GraphicsConfiguration getGraphicsConfiguration() {

return GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration();

}

I would do something like...

I = createCompatibleImage(ImageIO.read(new File(currentFolder+imgPath)));

imgMap.put(imgIdentifier, I);

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值