summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rwxr-xr-xsrc/demos/j2d/TestOverlay.java19
-rwxr-xr-xsrc/demos/j2d/TestTextRenderer.java2
-rwxr-xr-xsrc/demos/j2d/TestTextureRenderer.java1
3 files changed, 13 insertions, 9 deletions
diff --git a/src/demos/j2d/TestOverlay.java b/src/demos/j2d/TestOverlay.java
index 5faa0d5..adc8ba7 100755
--- a/src/demos/j2d/TestOverlay.java
+++ b/src/demos/j2d/TestOverlay.java
@@ -103,6 +103,8 @@ public class TestOverlay implements GLEventListener {
private int frameCount;
private DecimalFormat format = new DecimalFormat("####.00");
+ private Rectangle fpsBounds;
+
public void init(GLAutoDrawable drawable) {
GL gl = drawable.getGL();
gl.setSwapInterval(0);
@@ -134,23 +136,20 @@ public class TestOverlay implements GLEventListener {
FontRenderContext frc = g2d.getFontRenderContext();
String fpsString = "FPS: " + format.format(fps);
GlyphVector gv = font.createGlyphVector(frc, TEST_STRING);
- int x = drawable.getWidth() - 200;
+ fpsBounds = gv.getPixelBounds(frc, 0, 0);
+ int x = drawable.getWidth() - fpsBounds.width - 20;
int y = drawable.getHeight() - 20;
- Rectangle fpsBounds = gv.getPixelBounds(frc, x, y);
g2d.setFont(font);
g2d.setComposite(AlphaComposite.Src);
g2d.setColor(TRANSPARENT_BLACK);
- g2d.fillRect(fpsBounds.x, fpsBounds.y, fpsBounds.width, fpsBounds.height);
+ g2d.fillRect(x + fpsBounds.x, y + fpsBounds.y, fpsBounds.width, fpsBounds.height);
g2d.setColor(Color.WHITE);
g2d.drawString(fpsString, x, y);
- overlay.sync(fpsBounds.x, fpsBounds.y, fpsBounds.width, fpsBounds.height);
+ overlay.sync(x + fpsBounds.x, y + fpsBounds.y, fpsBounds.width, fpsBounds.height);
}
time.update();
- // Move down the text bounds
- lastTextBounds = textBounds;
-
g2d.setFont(font);
g2d.setComposite(AlphaComposite.Src);
if (overlay.contentsLost()) {
@@ -191,7 +190,11 @@ public class TestOverlay implements GLEventListener {
if (lastTextBounds != null) {
union.add(lastTextBounds);
}
- overlay.sync(union.x, union.y, union.width, union.height);
+ // Put a little slop around this text due to apparent rounding errors
+ overlay.sync(union.x, union.y, union.width + 10, union.height + 10);
+
+ // Move down the text bounds
+ lastTextBounds = textBounds;
// Draw the overlay
overlay.drawAll();
diff --git a/src/demos/j2d/TestTextRenderer.java b/src/demos/j2d/TestTextRenderer.java
index 853009c..0356606 100755
--- a/src/demos/j2d/TestTextRenderer.java
+++ b/src/demos/j2d/TestTextRenderer.java
@@ -134,7 +134,7 @@ public class TestTextRenderer implements GLEventListener {
fpsText = "FPS: " + format.format(fps);
if (fpsWidth == 0) {
// Place it at a fixed offset wrt the lower right corner
- fpsWidth = (int) renderer.getBounds("FPS: 1000.00").getWidth();
+ fpsWidth = (int) renderer.getBounds("FPS: 10000.00").getWidth();
}
}
diff --git a/src/demos/j2d/TestTextureRenderer.java b/src/demos/j2d/TestTextureRenderer.java
index 09f3fd8..596115e 100755
--- a/src/demos/j2d/TestTextureRenderer.java
+++ b/src/demos/j2d/TestTextureRenderer.java
@@ -151,6 +151,7 @@ public class TestTextureRenderer implements GLEventListener {
g2d.fillRect(fpsBounds.x, fpsBounds.y, fpsBounds.width, fpsBounds.height);
g2d.setColor(Color.WHITE);
g2d.drawString(fpsString, 10, 100);
+ renderer.sync(fpsBounds.x, fpsBounds.y, fpsBounds.width, fpsBounds.height);
}
time.update();