Hello,
Thanks for the info. I was getting rather confused on how to take advantage of hardware and somehow got it in my mind that by default all rendering would be in software. The archived posts I read kept talking about that createCompatibleImage method. So I should be okay by just using the toolkit?
following is the code I am using and still cannot draw to the buffered image can anyone see what I am doing wrong? (Although I don’t really need to do it anyway)
import java.awt.geom.*;
import java.awt.event.*;
import java.awt.image.*;
import java.awt.*;
public class test implements ImageObserver
{
private Image _image;
private int _intImageCount;
public void start()
{
Frame f = new Frame();
f.setIgnoreRepaint(true);
f.setUndecorated(true);
f.setBackground(Color.BLACK);
GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().setFullScreenWindow(f);
f.createBufferStrategy(2);
BufferStrategy buffer = f.getBufferStrategy();
loadImage();
int frames = 0;
long lStartRenderingTime = System.currentTimeMillis();
while(frames < 2000)
{
Graphics2D graphics = (Graphics2D) buffer.getDrawGraphics();
clear(graphics);
AffineTransform at = new AffineTransform();
graphics.drawImage(_image,at,f);
buffer.show();
graphics.dispose();
frames++;
}
long lEndRenderingTime = System.currentTimeMillis();
GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().setFullScreenWindow(null);
f.dispose();
System.out.println("Rendering Loop Time --> " + (lEndRenderingTime - lStartRenderingTime));
System.out.println("Frames --> " + frames);
System.out.println("FPS --> " + (1000 / ((lEndRenderingTime - lStartRenderingTime) / frames)) );
}
protected void clear(Graphics2D graphics)
{
graphics.setColor(Color.BLACK);
graphics.setClip(0,0,1024,768);
graphics.fillRect(0,0,1024,768);
}
public void loadImage()
{
Image image = Toolkit.getDefaultToolkit().createImage("c:\\corsairImages\\Corsair.png");
while(image.getHeight(null) == -1 && image.getWidth(null) == -1)
{
//Just Wait
}
//_image = image;
_image = createCompatibleImage(image);
_intImageCount++;
}
private Image createCompatibleImage(Image loadedImage)
{
GraphicsConfiguration gc = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration();
BufferedImage image = gc.createCompatibleImage(loadedImage.getWidth(null),loadedImage.getHeight(null),Transparency.BITMASK);
image.createGraphics().drawImage(loadedImage,new AffineTransform(),this);
return image;
}
public static void main(String args[])
{
test t = new test();
t.start();
}
public boolean imageUpdate(Image img,int infoflags,int x,int y,int width,int height)
{
int intResult = infoflags & ImageObserver.ALLBITS;
if(intResult == ImageObserver.ALLBITS)
System.out.println("Buffered Image Loaded");
else
System.out.println("image loading...........");
return true;
}
}