High Performance Java Swing Animation David Wallace Croft 2004-05-22 Presented to the Plano Java Users Group Plano, TX Copyright 2004 David Wallace Croft.

Slides:



Advertisements
Similar presentations
Games in Python – the easy way
Advertisements

Digital Images in Java Java’s imaging classes. Java imaging library  Java has good support for image processing  Must master a handful of classes and.
BrightAuthor v3.7 software and BrightSign XD v4.7 firmware
More Java Drawing in 2D Animations with Timer. Drawing Review A simple two-dimensional coordinate system exists for each graphics context or drawing surface.
Basic Computer Hardware and Software.
COSC 4126 images - D Goforth Images, Buffering and Animation controlling full screen graphics.
Multimedia for the Web: Creating Digital Excitement Multimedia Element -- Graphics.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter Java Multimedia: Images, Animation, Audio.
Graphics Programming. In this class, we will cover: The difference between AWT and Swing Creating a frame Frame positioning Displaying information in.
Game Design and Programming. Objectives Classify the games How games are design How games are implemented What are the main components of a game engine.
World Wide Web1 Applications World Wide Web. 2 Introduction What is hypertext model? Use of hypertext in World Wide Web (WWW) – HTML. WWW client-server.
Vertical Retrace Interval An introduction to VGA techniques for smooth graphics animation.
AGD: 5. Game Arch.1 Objective o to discuss some of the main game architecture elements, rendering, and the game loop Animation and Games Development.
©2008. Renesas Technology America., All rights reserved. Renesas Direct Drive for Connecting to TFT-LCD Panels David Hedley – Staff Applications Engineer.
User Interface Programming in C#: Direct Manipulation Chris North CS 3724: HCI.
Pygame Dick Steflik.
Guide to Programming with Python
Digital Graphics and Computers. Hardware and Software Working with graphic images requires suitable hardware and software to produce the best results.
Computer Concepts – Illustrated 8 th edition Unit C: Computer Software.
Elements of a Computer System Dr Kathryn Merrick Thursday 4 th June, 2009.
CHAPTER 4 Images XNA Game Studio 4.0. Objectives Find out how the Content Manager lets you add pictures to Microsoft XNA games. Discover how pictures.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
MOMA Display Screens K u r t R a l s k e.
 2005 Pearson Education, Inc. All rights reserved Multimedia: Applets and Applications.
Tennis for Two, 1958, by William Higinbotham, Brookhaven National Lab CSE 380 – Computer Game Programming Graphics Device Management.
1-1 OBJ Copyright 2003, Paradigm Publishing Inc. Dr. Joseph Otto Silvia Castaneda Christopher deCastro CSULA Macromedia Flash MX Introduction.
CSCE Chapter 5 (Links, Images, & Multimedia) CSCE General Applications Programming Benito Mendoza 1 By Benito Mendoza Department.
CHAPTER 2: COMPUTER-SYSTEM STRUCTURES Computer system operation Computer system operation I/O structure I/O structure Storage structure Storage structure.
Addison Wesley is an imprint of © 2010 Pearson Addison-Wesley. All rights reserved. Chapter 7 The Game Loop and Animation Starting Out with Games & Graphics.
Omer Boyaci. Resources  
XP Practical PC, 3e Chapter 15 1 Creating Desktop Video and Animation.
Agenda Last class: Memory, Digitizing Numbers Today: Digitizing: Text
User Interface Programming in C#: Direct Manipulation Chris North CS 3724: HCI.
Programming Video Games
By Courtney Field Creative digital graphics. Types of graphics and examples There are a number of different types of graphics file formats. Each type.
CS378 - Mobile Computing Responsiveness. An App Idea From Nifty Assignments Draw a picture use randomness Pick an equation at random Operators in the.
2.1. T HE G AME L OOP Central game update and render processes.
Applets Yong Choi School of Business CSU, Bakersfield.
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 What is Computer Graphics?
Java Direct Manipulation Chris North cs3724: HCI.
Intro to Applets. Applet Applets run within the Web browser environment Applets bring dynamic interaction and live animation to an otherwise static HTML.
Copyright © 2006 by The McGraw-Hill Companies, Inc. All rights reserved. McGraw-Hill Technology Education Chapter 8B Graphics and Multimedia.
Advanced Computer Graphics Spring 2014 K. H. Ko School of Mechatronics Gwangju Institute of Science and Technology.
Marwan Al-Namari 1 Digital Representations. Bits and Bytes Devices can only be in one of two states 0 or 1, yes or no, on or off, … Bit: a unit of data.
Computer Graphics & Multimedia
Image Processing A Study in Pixel Averaging Building a Resolution Pyramid With Parallel Computing Denise Runnels and Farnaz Zand.
GAM666 – Introduction To Game Programming ● DirectDraw, the 2D component of DirectX, uses the term “surface” to mean an area of memory in which pixel data.
NOTE: To change the image on this slide, select the picture and delete it. Then click the Pictures icon in the placeholder to insert your own image. DATABASE.
Fall UI Design and Implementation1 Lecture 13: Animation.
Basic Computer Hardware and Software.
Advanced Java Screen Update Techniques SD’98 - Session 4406 Ted Faison Faison Computing Inc.
CPCS 391 Computer Graphics Lab One. Computer Graphics Using Java What is Computer Graphics: Computer graphics are graphics created using computers and,
Reference: What is it? A multimedia python library – Window Management – Graphics geometric shapes bitmaps (sprites) – Input Mouse Keyboard.
Computer Graphics Lecture 1 Introduction to Computer Graphics
CPT 450 Computer Graphics 12th Lecture – Animation.
What is Computer Graphics?
Computer Graphics: An Introduction
Animations.
Some Basics of Computer Graphics
Basic Computer Hardware & Software
What is Computer Graphics?
Example: Card Game Create a class called “Card”
CMPE 101 Introduction to Information Technologies Chapter 5: Application Software: Tools for Productivity Copyright © 2012 Pearson Education, Inc. Publishing.
Basic Computer Hardware and Software.
Introduction to Computer Graphics with WebGL
Applications Software
Game Loop Update & Draw.
What is Computer Graphics?
Desktop Window Manager
E-CONTENT GENERATION USING OPEN SOURCE TOOLS
Presentation transcript:

High Performance Java Swing Animation David Wallace Croft Presented to the Plano Java Users Group Plano, TX Copyright 2004 David Wallace Croft. This work is licensed under the Creative Commons Attribution License.

David Wallace Croft ● Founder and VP, Game Developers Java Users Group ( ● Taught Java game programming at the Institute of Interactive Arts & Engineering at UTD ● Author of "Advanced Java Game Programming" ( ● Software Developer, NIST ATP "Peer-to- Peer Virtual Reality Learning Environments" research grant project, Whoola Inc.

Open Source ● All code presented today is Open Source ● Code documented in detail in the book "Advanced Java Game Programming" ● Source code available for download from ● Public Domain multimedia files also available ● This presentation archived on CroftSoft website

Performance Issues ● Clock resolution ● Hardware acceleration ● Repaint algorithm

Clock Resolution ● Need at least 24 fps for smooth animation ● Period of less than 42 ms ● System.currentTimeMillis() ● Clock resolution 50 to 60 ms on some Windows ● Swing Timer class limited to 20 fps ● Possibly due to clock resolution? ● Thread.sleep() within loop finer control

Animation Loop ● Phase 1: update sprite positions ● Phase 2: repaint sprites at new positions ● Phase 3: delay

LoopGovernor ● Slows animation loop down to desired frame rate ● Too slow = jerky animation ● Too fast = faster than monitor refresh, 100% CPU Do not squander time, for that is the stuff life is made of. -- Benjamin Franklin ● FixedDelayLoopGovernor ● SamplerLoopGovernor ● WindowedLoopGovernor

Hardware Acceleration ● Hardware acceleration for images ● Added to Java in version 1.4 ● Big difference in performance

Definitions ● VRAM = Video Random Access Memory ● Blit = BLT = Block Line Transfer ● Buffer = block of memory for image data ● Pixel = picture element ● Render = calculate and store pixel data ● Primary surface = screen surface ● Back buffer = offscreen image

Class Image ● Package java.awt ● Holds pixel (picture element) data ● Abstract superclass ● Subclasses – BufferedImage – VolatileImage

BufferedImage ● Quick and easy to modify pixel data ● Pixel data not in video memory ● Slow to transfer to video memory ● Blitting ● No hardware acceleration for drawing ops

VolatileImage ● Component.createVolatileImage(width,height ) ● Pixel data in video memory (VRAM) ● Hardware acceleration for drawing ops ● Video memory is volatile ● Screen saver will invalidate ● Must check and reload ● boolean VolatileImage.contentsLost()

CompatibleImage ● GraphicsConfiguration.createCompatibleIma ge() ● Pixel format conversion not needed ● BufferedImage for pixel manipulation ● VolatileImage cache for fast blitting ● Caching mechanism validates volatile memory ● Best for static images since cached ● Caching algorithm out of your control

Transparency ● GraphicsConfiguration.createCompatibleIma ge ( width, height, transparency ) ● Transparency.OPAQUE ● Transparency.BITMASK ● Transparency.TRANSLUCENT ● TRANSLUCENT not accelerated so slow ● Transparency lost when copying to VolatileImage

Translucent Demo ● SpriteDemo fog option ● Performance drops

Scaled BLT ● Graphics.drawImage ( x, y, width, height, null ) ● Slow ● Solution = pre-scale

loadAutomaticImage() ● com.croftsoft.core.awt.image.ImageLib ● Source code review

Repaint Algorithm ● Default algorithm in Swing bad for animation ● Creates union of dirty rectangles ● Slows down when rectangles far apart ● Demonstration using Sprite

RepaintCollector ● Phase 1: Collects repaint requests ● Phase 2: Delivers repaint requests ● Coalesces requests for efficiency ● Default algorithm in Swing bad for animation ● SimpleRepaintCollector ● BooleanRepaintCollector ● CoalescingRepaintCollector

References ● Jeffrey Kesselman, Understanding the AWT Image Types ● Michael Martak, Full-Screen Exclusive Mode API ● Sun, High Performance Graphics ● Sun, The VolatileImage API User Guide

Questions? ● Also ask via book discussion mailing list