Double-Buffering Without drawImage?

Discussion in 'Java' started by Lash Rambo, Jul 10, 2004.

  1. Lash Rambo

    Lash Rambo Guest

    Is is possible to do away with the drawImage(offscreenImage) step of
    double-buffering in Java?

    Specifically, what I'm thinking of is two graphics contexts that can be
    toggled between. One graphics context will be off-screen and drawn to,
    while the other is on-screen and left alone. When the drawing is done and
    it's time to present a new frame, simply swap the two graphics contexts's
    references. In other words, the graphics context that was the off-screen
    one becomes the on-screen one, and vice versa.

    Is this possible, for instance, with java.applet.Applet? If so, it'd seem
    to eliminate a lot of overhead, particularly for large scenes that need to
    be completely redrawn each frame.
     
    Lash Rambo, Jul 10, 2004
    #1
    1. Advertising

  2. On Fri, 09 Jul 2004 23:00:48 GMT, Lash Rambo <> wrote:

    > Is is possible to do away with the drawImage(offscreenImage) step of
    > double-buffering in Java?
    >
    > Specifically, what I'm thinking of is two graphics contexts that can be
    > toggled between. One graphics context will be off-screen and drawn to,
    > while the other is on-screen and left alone. When the drawing is done
    > and
    > it's time to present a new frame, simply swap the two graphics contexts's
    > references. In other words, the graphics context that was the off-screen
    > one becomes the on-screen one, and vice versa.
    >
    > Is this possible, for instance, with java.applet.Applet? If so, it'd
    > seem
    > to eliminate a lot of overhead, particularly for large scenes that need
    > to
    > be completely redrawn each frame.


    You seem to be applying the "Graphics Context" idea exported
    from another language. In Java, it does NOT imply a chunk of
    memory you can "simply swap"

    Bill

    --
    Using Opera's revolutionary e-mail client: http://www.opera.com/m2/
     
    William Brogden, Jul 10, 2004
    #2
    1. Advertising

  3. Lash Rambo

    Ryan Stewart Guest

    "Lash Rambo" <> wrote in message
    news:Xns9521B76D54976lramboobmarlcom@68.12.19.6...
    > Is is possible to do away with the drawImage(offscreenImage) step of
    > double-buffering in Java?
    >
    > Specifically, what I'm thinking of is two graphics contexts that can be
    > toggled between. One graphics context will be off-screen and drawn to,
    > while the other is on-screen and left alone. When the drawing is done and
    > it's time to present a new frame, simply swap the two graphics contexts's
    > references. In other words, the graphics context that was the off-screen
    > one becomes the on-screen one, and vice versa.
    >
    > Is this possible, for instance, with java.applet.Applet? If so, it'd seem
    > to eliminate a lot of overhead, particularly for large scenes that need to
    > be completely redrawn each frame.

    You want page flipping. Have a look at the createBufferStrategy and
    getBufferStrategy methods of java.awt.Window. A caution: the book I read
    about it said that there were occasional problems calling getBufferStrategy
    immediately after createBufferStrategy. It recommended trying the get every
    20 ms or so in a loop until it is successful or a couple of seconds has
    passed (in which case throw an Exception and exit).
     
    Ryan Stewart, Jul 10, 2004
    #3
  4. Lash Rambo

    Lash Rambo Guest

    "Ryan Stewart" <> wrote in
    news::

    > "Lash Rambo" <> wrote in message
    > news:Xns9521B76D54976lramboobmarlcom@68.12.19.6...
    >> Is is possible to do away with the drawImage(offscreenImage) step of
    >> double-buffering in Java?
    >>
    >> Specifically, what I'm thinking of is two graphics contexts that can
    >> be toggled between. One graphics context will be off-screen and
    >> drawn to, while the other is on-screen and left alone. When the
    >> drawing is done and it's time to present a new frame, simply swap the
    >> two graphics contexts's references. In other words, the graphics
    >> context that was the off-screen one becomes the on-screen one, and
    >> vice versa.
    >>
    >> Is this possible, for instance, with java.applet.Applet? If so, it'd
    >> seem to eliminate a lot of overhead, particularly for large scenes
    >> that need to be completely redrawn each frame.

    >
    > You want page flipping. Have a look at the createBufferStrategy and
    > getBufferStrategy methods of java.awt.Window. A caution: the book I
    > read about it said that there were occasional problems calling
    > getBufferStrategy immediately after createBufferStrategy. It
    > recommended trying the get every 20 ms or so in a loop until it is
    > successful or a couple of seconds has passed (in which case throw an
    > Exception and exit).


    Yes! That's exactly what I was looking for. Not sure if it will work
    the way I think it will, but it looks promising. Thanks, Ryan!
     
    Lash Rambo, Jul 10, 2004
    #4
  5. Lash Rambo

    Guest

    Lash Rambo <> wrote:
    > Is is possible to do away with the drawImage(offscreenImage) step of
    > double-buffering in Java?
    >
    > Specifically, what I'm thinking of is two graphics contexts that can be
    > toggled between. One graphics context will be off-screen and drawn to,
    > while the other is on-screen and left alone. When the drawing is done and
    > it's time to present a new frame, simply swap the two graphics contexts's
    > references. In other words, the graphics context that was the off-screen
    > one becomes the on-screen one, and vice versa.
    >
    > Is this possible, for instance, with java.applet.Applet? If so, it'd seem
    > to eliminate a lot of overhead, particularly for large scenes that need to
    > be completely redrawn each frame.


    If you're not limited to AWT, and can use Swing, I think you get
    double buffering "for free"; i.e., extend javax.swing.JPanel, override
    paintComponent() to do your painting, and allow Swing to handle all
    the double buffering details for you. With luck, Swing is already
    designed to leverage the most efficient kind of double buffering
    available to the underlying platform (whether that be bit blitting
    from main memory, or from graphics memory, or page flipping, or
    whatever).
     
    , Jul 11, 2004
    #5
  6. Lash Rambo

    Lash Rambo Guest

    wrote in
    news:40f0c3d9$0$175$:

    > Lash Rambo <> wrote:
    >> Is is possible to do away with the drawImage(offscreenImage) step of
    >> double-buffering in Java?
    >>
    >> Specifically, what I'm thinking of is two graphics contexts that can
    >> be toggled between. One graphics context will be off-screen and
    >> drawn to, while the other is on-screen and left alone. When the
    >> drawing is done and it's time to present a new frame, simply swap the
    >> two graphics contexts's references. In other words, the graphics
    >> context that was the off-screen one becomes the on-screen one, and
    >> vice versa.
    >>
    >> Is this possible, for instance, with java.applet.Applet? If so, it'd
    >> seem to eliminate a lot of overhead, particularly for large scenes
    >> that need to be completely redrawn each frame.

    >
    > If you're not limited to AWT, and can use Swing, I think you get
    > double buffering "for free"; i.e., extend javax.swing.JPanel, override
    > paintComponent() to do your painting, and allow Swing to handle all
    > the double buffering details for you. With luck, Swing is already
    > designed to leverage the most efficient kind of double buffering
    > available to the underlying platform (whether that be bit blitting
    > from main memory, or from graphics memory, or page flipping, or
    > whatever).


    Alright, I'll research this, as well. It'd certainly make things a lot
    easier!
     
    Lash Rambo, Jul 15, 2004
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Michele Puccini
    Replies:
    0
    Views:
    405
    Michele Puccini
    Nov 9, 2003
  2. Wolfgang
    Replies:
    3
    Views:
    6,100
    Knute Johnson
    Feb 10, 2004
  3. OtisUsenet
    Replies:
    3
    Views:
    12,553
    OtisUsenet
    Feb 24, 2004
  4. Sydex
    Replies:
    12
    Views:
    6,500
    Victor Bazarov
    Feb 17, 2005
  5. dhavalshah
    Replies:
    0
    Views:
    376
    dhavalshah
    Dec 26, 2008
Loading...

Share This Page