Presentation is loading. Please wait.

Presentation is loading. Please wait.

COSC 4126 images - D Goforth Images, Buffering and Animation controlling full screen graphics.

Similar presentations


Presentation on theme: "COSC 4126 images - D Goforth Images, Buffering and Animation controlling full screen graphics."— Presentation transcript:

1 COSC 4126 images - D Goforth Images, Buffering and Animation controlling full screen graphics

2 COSC 4126 images - D Goforth A screen manager class  manages the full screen display sets display parameters initializes, terminates full screen display provides access to full screen window take over display of screen to improve quality

3 COSC 4126 images - D Goforth Images  transparency  file formats  file input

4 COSC 4126 images - D Goforth Transparency  three types opaque transparent translucent

5 COSC 4126 images - D Goforth Opaque  every pixel displayed image

6 COSC 4126 images - D Goforth Transparent  every pixel displayed or not image

7 COSC 4126 images - D Goforth Translucent  every pixel can be partly transparent image

8 COSC 4126 images - D Goforth File formats  GIF – don’t use it – PNG always better  PNG any colour bit depth any transparency compression  JPEG 24 bit colour only opaque only efficient but lossy compression good for photos for screen use

9 COSC 4126 images - D Goforth Reading images - applets  methods in Applet class Image getImage (URL url) Image getImage (URL url, String fName)  image does not start loading till drawing of image begins

10 COSC 4126 images - D Goforth Reading images - applets e.g. import java.applet.*; import java.awt.*; public class ImageEG extends Applet { private Image im; public void init() { im = getImage(getDocumentBase(), ”photo.png”); } public void paint(Graphics g) { g.drawImage(im, 0, 0, this); }

11 COSC 4126 images - D Goforth Reading images - applications  image reader is in default toolkit: this method caches the image Image im = Toolkit.getDefaultToolkit().getImage(“photo.png”); to reload file for every display Image im = Toolkit.getDefaultToolkit().createImage(“photo.png”);  these methods work like the applet method (load with display)

12 COSC 4126 images - D Goforth Reading images - applications  to read an image completely: method does not return till image is loaded import javax.swing.*;... Image im = new ImageIcon(“photo.png”).getImage(); Brackeen files: ImageTest.java, ImageSpeedTest.java

13 COSC 4126 images - D Goforth Animation  animation = shape change + motion set of shapes (frames) are alternated in a timed sequence each shape is an Image 200 ms325 ms625 ms675 ms200 ms im1 im2im1 im3im1 one cycle, repeated

14 COSC 4126 images - D Goforth Animation  Animation class frames and times total time for one animation cycle current frame current time 200 ms325 ms625 ms675 ms200 ms im1 im2im1 im3im1 total time of cycle

15 COSC 4126 images - D Goforth Animation  store frames in a list (ArrayList) frame (AnimFrame) image plus duration ArrayList 0 im1 200 1 im2 325 2 im1 625 3 im3 675 200 ms325 ms625 ms675 ms200 ms im1 im2im1 im3im1 total time duration

16 COSC 4126 images - D Goforth Animation  updating the animation update current time (mod total duration) update current frame ArrayList 0 im1 200 1 im2 325 2 im1 625 3 im3 675 200 ms325 ms625 ms675 ms200 ms im1 im2im1 im3im1 total time duration

17 COSC 4126 images - D Goforth Animation animation loop  initialize current time from clock  while current time < end time get clock time determine elapsed time, new current time update animation(s) with elapsed time draw animations  Brackeen example AnimationTest1.java

18 COSC 4126 images - D Goforth Animation quality  active rendering – control painting directly (not through event queue)  double buffering (remove flicker)  synchronizing with monitor refresh rate (remove tearing) BufferStrategy class

19 COSC 4126 images - D Goforth Active rendering  full screen window ignores event-queue paint events fullScreen.ignoreRepaint(); then..  get graphics object for the window  paint the window  dispose the graphics object Graphics g = fullScreen.getGraphics(); draw(g); g.dispose();

20 COSC 4126 images - D Goforth Double buffering (eliminate flicker)  2 display buffers first is displayed while second is painted first, second swapped

21 COSC 4126 images - D Goforth Synchronizing with refresh (eliminate tearing)  switch buffers between refreshes, not during tear:  Brackeen example AnimationTest2.java

22 COSC 4126 images - D Goforth Brackeen’s ScreenManager class(1) ScreenManager  public ScreenManager()  public DisplayMode[] getCompatibleDisplayModes()  public DisplayMode findFirstCompatibleMode(DisplayMode modes[])  public DisplayMode getCurrentDisplayMode()  public boolean displayModesMatch(DisplayMode mode1, DisplayMode mode2)  public void setFullScreen(DisplayMode displayMode)

23 COSC 4126 images - D Goforth Brackeen’s ScreenManager class(2) ScreenManager  public JFrame getFullScreenWindow()  public int getWidth()  public int getHeight()  public Graphics2D getGraphics()  public void update()  public void restoreScreen()  public BufferedImage createCompatibleImage(int w, int h,  int transparancy)

24 COSC 4126 images - D Goforth Sprites: Shape change and Motion  object that moves on graphic display may change shape also  Sprite object Animation position on screen velocity get and set methods update method computes new position and Animation image

25 COSC 4126 images - D Goforth Sprite movement plus shape change  elapsed time et since last update ®distance moved ®x = x + et * dx ®y = y + et * dy ®Animation determines new image Brackeen code: Sprite.java SpriteTest1.java, SpriteTest2.java


Download ppt "COSC 4126 images - D Goforth Images, Buffering and Animation controlling full screen graphics."

Similar presentations


Ads by Google