Hi, I talked about the tearing issue in my blog entry and article on choppy animations: http://weblogs.java.net/blog/chet/archive/2006/02/make_your_anima.html http://today.java.net/pub/a/today/2006/02/23/smooth-moves-solutions.html
You're basically running into a vertical refresh artifact. Running fullscreen with a BufferStrategy is a decent way to work around this; depending on the platform and the situation, we will usually give you a Flip strategy, which is (usually) synchronized with the vertical refresh of the display to avoid tearing. There are some things that might contribute to this not working, however: - What platform are you running on? It's possible that the Flip strategy on your particular platform is actually doing a copy behind the scenes, which would be the same as the BltBufferStrategy, which runs smack into the refresh artifact. - What pipeline are you using? The default? Are you specifying OpenGL? or Direct3D? What release are you using? These can all affect how we are implementing the buffer strategy under the hood. - The graphics operations you do to the back buffer could actually impact things as well; it's possible that we would punt the buffer to system memory in some situations because the operations you are doing (apart from the flip/blt) are faster in software. This is particularly the case for translucency; reading from video memory is an amazingly slow operation, and we do not necessarily support translucency through hardware on all platforms. Anyway, hopefully this helps you track things down a bit... Chet. [EMAIL PROTECTED] wrote:
I've been trying to work around an issue involving tearing during a buffered rendering process in my code. Im using a buffer strategy to page flip to BufferedImages to conduct a animation. The problem is that on every interation of the render the square box that I render it tearing. I have purchased multiple books and have visted multiple web sites on how to solve the tearing problem. And I in NO MEANS want to copy or use someone elses code. Pasted below is the code that I developed. Any suggestions are welcome. Thanks. import java.awt.*; import java.awt.image.*; import java.awt.event.*; import javax.swing.*; import java.io.*; import java.awt.geom.*; public class GameEngine implements Runnable { private GraphicsConfiguration[] gc; private GraphicsDevice gd; private GraphicsEnvironment ge; private DisplayMode dm; private DisplayMode dms[]; private JFrame frame; private Container c; private File file; private FileWriter writer; private BufferCapabilities buffercap; private ImageCapabilities imagecap; private Window window; private BufferStrategy bufstrat; private Thread t; private int x = 0; private BufferedImage back1; private BufferedImage back2; public GameEngine() { t = new Thread(this,"Game Loop"); try { SwingUtilities.invokeAndWait(new Runnable(){ public void run() { try { initGraphics(); init(); } catch(Exception e) { e.printStackTrace(); } } }); } catch(Exception e) { e.printStackTrace(); } } public void initGraphics() { ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); gd = ge.getDefaultScreenDevice(); dm = gd.getDisplayMode(); gc = gd.getConfigurations(); dms = gd.getDisplayModes(); back1 = new BufferedImage(dm.getWidth(),dm.getHeight(),BufferedImage.TYPE_INT_ARGB); back2 = new BufferedImage(dm.getWidth(),dm.getHeight(),BufferedImage.TYPE_INT_ARGB); try { file = new File("C:/GraphicsInfo.txt"); writer = new FileWriter(file); writer.write("Ideology Software Corporation\n"); writer.write("Sample Game Information\n\n"); writer.write("Display Information"); writer.write("\n\n"); writer.write("Width " + dm.getWidth()); writer.write("Height " + dm.getHeight()); writer.write("\n\n"); writer.write("Supported Display Modes"); writer.write("\n\n"); for(int k = 0;k < dms.length;k++) { writer.write("\n\n"); writer.write("Display Mode " + k); writer.write("\n\n"); writer.write("Width " + dms[k].getWidth()); writer.write("\n"); writer.write("Height " + dms[k].getHeight()); writer.write("\n"); writer.write("Bit Depth " + dms[k].getBitDepth()); writer.write("\n"); writer.write("Refresh Rate " + dms[k].getRefreshRate()); writer.write("\n"); } for(int i = 0;i < gc.length;i++) { Rectangle rect = gc[i].getBounds(); buffercap = gc[i].getBufferCapabilities(); imagecap = gc[i].getImageCapabilities(); writer.write("\n\n"); writer.write("Graphics Configuration " + i); writer.write("\n\n"); writer.write("Configuration Width " + rect.width); writer.write("\n"); writer.write("Configuration Height " + rect.height); writer.write("\n"); writer.write("Configuration x " + rect.x); writer.write("\n"); writer.write("Configuration y " + rect.y); rect = ge.getMaximumWindowBounds(); writer.write("Max Window Configuraiton\n\n"); writer.write("\n"); writer.write("Max Window Width " + rect.width); writer.write("\n"); writer.write("Max Window Height " + rect.height); writer.write("\n\n"); writer.write("Buffer Capabilities"); writer.write("\n"); writer.write("FullScreen Required " + buffercap.isFullScreenRequired()); writer.write("\n"); writer.write("MultiBuffer Support " + buffercap.isMultiBufferAvailable()); writer.write("\n"); writer.write("Page Flipping Support " + buffercap.isPageFlipping()); writer.write("\n\n"); writer.write("Image Capabilities"); writer.write("\n"); writer.write("Acceration Support " + imagecap.isAccelerated()); writer.write("\n"); writer.write("Volatile Image Support " + imagecap.isTrueVolatile()); writer.write("\n\n"); } writer.close(); } catch(Exception e) { e.printStackTrace(); } } public void init() { frame = new JFrame(); frame.setSize(800,800); frame.setTitle("Game Application"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setIgnoreRepaint(true); frame.setUndecorated(true); c = frame.getContentPane(); c.setLayout(null); c.setBackground(new Color(0,0,0)); frame.setResizable(true); frame.setVisible(true); if(gd.isFullScreenSupported()) { gd.setFullScreenWindow(frame); } window = gd.getFullScreenWindow(); window.createBufferStrategy(2); bufstrat = window.getBufferStrategy(); t.start(); } public boolean renderBackOne() { if(back1 != null) { Graphics2D backg1 = back1.createGraphics(); backg1.setColor(new Color(255,255,255)); backg1.fillRect(x,100,100,100); return true; } else { return false; } } public boolean renderBackTwo() { if(back2 != null) { Graphics2D backg2 = back2.createGraphics(); backg2.setColor(new Color(255,255,255)); backg2.fillRect(x,100,100,100); return true; } else { return false; } } public void update() { if(!bufstrat.contentsLost()) { bufstrat.show(); } } public void render() { Graphics2D g2 = (Graphics2D)bufstrat.getDrawGraphics(); g2.setColor(new Color(255,255,255)); if(g2 != null) { if(renderBackOne()) { g2.drawImage(back1,new AffineTransformOp(g2.getTransform(),g2.getRenderingHints()),0,0); } else { g2.drawImage(back2,new AffineTransformOp(g2.getTransform(),g2.getRenderingHints()),0,0); } } } public void run() { try { for(;;) { Thread.sleep(750); update(); render(); x++; } } catch(Exception e) { e.printStackTrace(); } } public static void main(String args[]) { GameEngine gameengine = new GameEngine(); } } [Message sent by forum member 'xeondeveloper' (xeondeveloper)] http://forums.java.net/jive/thread.jspa?messageID=108465 =========================================================================== To unsubscribe, send email to [EMAIL PROTECTED] and include in the body of the message "signoff JAVA2D-INTEREST". For general help, send email to [EMAIL PROTECTED] and include in the body of the message "help".
=========================================================================== To unsubscribe, send email to [EMAIL PROTECTED] and include in the body of the message "signoff JAVA2D-INTEREST". For general help, send email to [EMAIL PROTECTED] and include in the body of the message "help".