BufferedImage for fast display?

Hi all! I’m looking at starting a simple game, with a few sprites. I want to make a few sprites using BufferedImage, then blit the sprites quickly to the screen.

Query: How can I match the display (bit depth, RGB, BGR, etc. ) for the fastest blit?

I want to set this up before hand, not in the paint() method. Trying to create all the sprites in the paint() method would basically be kludgy, at best, and totaly unworkable at worst.

I want to set up the sprites in main(), or some method called by main, with images that match the screen bit depth.

Any ideas? Thanks for the help!

Hi there gojira!

I don’t quite understand your question, but I will try to help.

It seems like what you are trying to do is implement a form of double buffering, where instead of your graphics being drawn directly to the screen, it is drawn in your computer’s memory and then simply “flipped” over or copied to your screen.

If you want to set up your sprites before drawing them, I suppose you could load them in your program’s initialization phase, either the constructor if you are making an Application, or init() in an Applet.

Some other solutions to this:

  1. If you are looking for a full-fledged animation loop, complete with double buffering, you might want to check out Chapter 1 of this book-in-progress:
    http://fivedots.coe.psu.ac.th/~ad/jg/.
    This chapter also covers totally ignoring paint() altogether so you can perform your own graphics drawing whenever and wherever.

  2. There are a few sections on passive vs. active rendering here at the Java Tutorial:
    http://java.sun.com/docs/books/tutorial/extra/fullscreen/index.html

Sorry if this isn’t what you were looking for!
Smarto

Hey Smarto, thanks for those links. They look pretty good, I’ll have to check them out.

Basically I want to do a form of double buffering. I want to use a background image and then add seperate sprite images the background to form the final image. I plan to use these as seperate images, not quite double buffering, and use dirty rectangles to only update the areas that I want.

But that doesn’t matter. Right now, I only want one thing. How can I get the bit depth and color mode of the display so I can match it with my images I create?

I changed my original post to better say what I ment (you are right, I wasn’t too clear the first time).

Anyhoo, hopefully someone can answer.

http://www.gamelizard.com/JavaGameProgrammingPresentation.htm

Scroll down a bit to where I talk about how to get managed BufferedImages. With that strategy, you can ask for a BufferedImage with Translucency.WHATEVER constants which will be compatible with the current display.

 GraphicsConfiguration gc = GraphicsEnvironment.getLocalGraphicsEnvironment()
     .getDefaultScreenDevice().getDefaultConfiguration();

BufferedImage image = gc.createCompatibleImage(width, height,
     Transparency.TRANSLUCENT);

Woo! That looks like what I wanted! Thanks Mal, I’ll check this out. :slight_smile: