Hi there,
I'm working on a 2D platformer game in Java. I'm writing everything from scratch using basic Swing and AWT components.
I'm making good progress on things (collision detection with platforms, level rendering, level scrolling, etc.). However, I've stopped feature development until I can get an issue resolved: jittering/screen tearing.
I've extracted the basic rendering technique from my code base and have been able to (visually) reproduce the error with just a little bit of code.
In my project, I'm using an RK4 integration technique (describe by http://gafferongames...gration-basics/) in the main game loop. For this example, however, I've simplified the update loop to a simple 10 millisecond SwingTimer.
Main.java: https://gist.github.com/3389133
GameWindow.java: https://gist.github.com/3389137
GameCanvas.java: https://gist.github.com/3389138
GameKernel.java: https://gist.github.com/3389139
This example just makes an orange rectangle (the "player") move back and forth across the screen. Even with this simple example, I can see the screen tearing.
I've been reading tons about double buffering techniques (including several forum threads and this series of articles: http://docs.oracle.c.../doublebuf.html). What I've implemented in the code above seems to be the simplest possible way to achieve hardware-accelerated double-buffered rendering. (At least, I'm assuming this taking advantage of hardware acceleration; I'm pretty newb when it comes to graphics programming.) I've tried other more sophisticated approaches suggested in the Java documentation of BufferStrategy (http://docs.oracle.c...erStrategy.html). I've followed this almost to the letter, and even added a call to Toolkit.sync() (a suggestion from a thread I read). Here's basically what I have in my game right now: https://gist.github.com/3389202
Unfortunately, all of this fancy code doesn't seem to affect any change (good or bad), compared to the simple double buffering technique I pasted above. At this point, I'm kind of doing things in "cargo cult" fashion: thrashing around until _something_ works.
I could use some help. Can anyone tell me what I'm doing wrong? Or perhaps the better question to ask first is, can anyone reproduce this screen tearing issue with the code I posted above (so I can rule out the possibility of this just being an issue with my machine)?
Platform info:
Mid 2010 MacBook Pro
OS X 10.7.4
JDK 1.6.0_33
NVIDIA GeForce GT 330M 256mb
1680 x 1050 display
Any tips are appreciated. Cheers!
-Thok
Show differencesHistory of post edits
#1thok
Posted 18 August 2012 - 01:29 PM
Hi there,
I'm working on a 2D platformer game in Java. I'm writing everything from scratch using basic Swing and AWT components.
I'm making good progress on things (collision detection with platforms, level rendering, level scrolling, etc.). However, I've stopped feature development until I can get an issue resolved: jittering/screen tearing.
I've extracted the basic rendering technique from my code base and have been able to (visually) reproduce the error with just a little bit of code.
In my project, I'm using an RK4 integration technique (describe by http://gafferongames...gration-basics/) in the main game loop. For this example, however, I've simplified the update loop to a simple 10 millisecond SwingTimer.
Main.java: https://gist.github.com/3389133
GameWindow.java: https://gist.github.com/3389137
GameCanvas.java: https://gist.github.com/3389138
GameKernel.java: https://gist.github.com/3389139
This example just makes an orange rectangle (the "player") move back and forth across the screen. Even with this simple example, I can see the screen tearing.
I've been reading tons about double buffering techniques (including several forum threads and this series of articles: http://docs.oracle.c.../doublebuf.html). What I've implemented in the code above seems to be the simplest possible way to achieve hardware-accelerated double-buffered rendering. (At least, I'm assuming this taking advantage of hardware acceleration; I'm pretty newb when it comes to graphics programming.) I've tried other more sophisticated approaches suggested in the Java documentation of BufferStrategy (http://docs.oracle.c...erStrategy.html). I've followed this almost to the letter, and even added a call to Toolkit.sync() (a suggestion from a thread I read). Here's basically what I have in my game right now: https://gist.github.com/3389202
Unfortunately, all of this fancy code doesn't seem to affect any change (good or bad), compared to the simple double buffering technique I pasted above. At this point, I'm kind of doing things in "cargo cult" fashion: thrashing around until _something_ works.
I could use some help. Can anyone tell me what I'm doing wrong? Or perhaps the better question to ask first is, can anyone reproduce this screen tearing issue with the code I posted above (so I can rule out the possibility of this just being an issue with my machine)?
Platform info:
Mid 2010 MacBook Pro
OS X 10.7.4
JDK 1.6.0_33
NVIDIA GeForce GT 330M 256mb
1680 x 1050 display
Any tip are appreciated. Cheers!
-Thok
I'm working on a 2D platformer game in Java. I'm writing everything from scratch using basic Swing and AWT components.
I'm making good progress on things (collision detection with platforms, level rendering, level scrolling, etc.). However, I've stopped feature development until I can get an issue resolved: jittering/screen tearing.
I've extracted the basic rendering technique from my code base and have been able to (visually) reproduce the error with just a little bit of code.
In my project, I'm using an RK4 integration technique (describe by http://gafferongames...gration-basics/) in the main game loop. For this example, however, I've simplified the update loop to a simple 10 millisecond SwingTimer.
Main.java: https://gist.github.com/3389133
GameWindow.java: https://gist.github.com/3389137
GameCanvas.java: https://gist.github.com/3389138
GameKernel.java: https://gist.github.com/3389139
This example just makes an orange rectangle (the "player") move back and forth across the screen. Even with this simple example, I can see the screen tearing.
I've been reading tons about double buffering techniques (including several forum threads and this series of articles: http://docs.oracle.c.../doublebuf.html). What I've implemented in the code above seems to be the simplest possible way to achieve hardware-accelerated double-buffered rendering. (At least, I'm assuming this taking advantage of hardware acceleration; I'm pretty newb when it comes to graphics programming.) I've tried other more sophisticated approaches suggested in the Java documentation of BufferStrategy (http://docs.oracle.c...erStrategy.html). I've followed this almost to the letter, and even added a call to Toolkit.sync() (a suggestion from a thread I read). Here's basically what I have in my game right now: https://gist.github.com/3389202
Unfortunately, all of this fancy code doesn't seem to affect any change (good or bad), compared to the simple double buffering technique I pasted above. At this point, I'm kind of doing things in "cargo cult" fashion: thrashing around until _something_ works.
I could use some help. Can anyone tell me what I'm doing wrong? Or perhaps the better question to ask first is, can anyone reproduce this screen tearing issue with the code I posted above (so I can rule out the possibility of this just being an issue with my machine)?
Platform info:
Mid 2010 MacBook Pro
OS X 10.7.4
JDK 1.6.0_33
NVIDIA GeForce GT 330M 256mb
1680 x 1050 display
Any tip are appreciated. Cheers!
-Thok