Drawing directly onto the BufferStrategy

In previous project, I have done my Java2D rendering by drawing onto a BufferedImage and drawing that to a BufferStrategy. This allowed me to scale the image to acheive a low-resultion effect at higher resolution windows by drawing the image as


g.drawImage(image, 0, 0, width, height, null);

but when I make the window, I go


main.setPreferredSize(new Dimension(width * scale, height * scale));

Thus making it three times more spread out.

Anyways I just found out how much more efficient it is to draw directly onto the BufferStrategy instead of using a BufferedImage. So my question is:

How can I draw directly onto the BufferStrategy and still scale the image? Is this possible at all?

Thanks,
| Nathan

Wouldn’t drawing directly on the BufferStrategy nullify its use? Isn’t its purpose to do the double buffering for you so you don’t have to keep track of the off-screen fully drawn image?

I’ve worded that badly, this is what I use

                // Create BufferStrategy
      BufferStrategy bs = getBufferStrategy();
		if (bs == null) {
			createBufferStrategy(3);
			return;
		}

                // Get BufferStategy's graphics object //
		Graphics g = bs.getDrawGraphics();
                // Clear the screen
		g.fillRect(0, 0, getWidth(), getHeight());

		int ww = WIDTH * SCALE;
		int hh = HEIGHT * SCALE;

                // draw on it
		g.drawImage(image, 0, 0, ww, hh, null);
                
                // dispose of it (finished drawing)
		g.dispose();
                // show it
		bs.show();

When you are drawing you can cast your Graphics object to a Graphics2D object. Then call Graphics2D.scale(). Then do your drawing after calling scale. All future drawing calls will be scaled.

Depending on exactly what drawing operations you are doing, it may be faster to draw at ‘normal’ scale into a VolatileImage, and draw that scaled to the BufferStrategy.