summaryrefslogtreecommitdiffstats
path: root/src/demos/j2d/TestTextRenderer.java
diff options
context:
space:
mode:
authorKenneth Russel <[email protected]>2007-01-20 19:33:48 +0000
committerKenneth Russel <[email protected]>2007-01-20 19:33:48 +0000
commitbcf613662e21968bc326d56a0c87dbc9377b545f (patch)
treea9eedcd2f9776ce56070a0f14aaa57ac8a305e12 /src/demos/j2d/TestTextRenderer.java
parent945861ed9d214eb166f134727278165fcaff1135 (diff)
Added 3D rendering methods to TextureRenderer and TextRenderer on
request of several people on javagaming.org forums. Refactored existing 2D rendering support in these classes in terms of the new 3D methods. Wrote new TextCube demo illustrating how to render 2D text in 3D using the TextRenderer. Factored out FPS counter rendering into new FPSCounter utility class and updated TestTextRenderer and FlyingText demos. git-svn-id: file:///usr/local/projects/SUN/JOGL/git-svn/../svn-server-sync/jogl-demos/trunk@201 3298f667-5e0e-4b4a-8ed4-a3559d26a5f4
Diffstat (limited to 'src/demos/j2d/TestTextRenderer.java')
-rwxr-xr-xsrc/demos/j2d/TestTextRenderer.java32
1 files changed, 5 insertions, 27 deletions
diff --git a/src/demos/j2d/TestTextRenderer.java b/src/demos/j2d/TestTextRenderer.java
index 0356606..281476f 100755
--- a/src/demos/j2d/TestTextRenderer.java
+++ b/src/demos/j2d/TestTextRenderer.java
@@ -94,11 +94,7 @@ public class TestTextRenderer implements GLEventListener {
private String TEST_STRING = "Java 2D Text";
private int textWidth;
private int textHeight;
- private String fpsText;
- private int fpsWidth;
- private long startTime;
- private int frameCount;
- private DecimalFormat format = new DecimalFormat("####.00");
+ private FPSCounter fps;
public void init(GLAutoDrawable drawable) {
GL gl = drawable.getGL();
@@ -118,26 +114,11 @@ public class TestTextRenderer implements GLEventListener {
Rectangle2D textBounds = renderer.getBounds(TEST_STRING);
textWidth = (int) textBounds.getWidth();
textHeight = (int) textBounds.getHeight();
+
+ fps = new FPSCounter(drawable, 36);
}
public void display(GLAutoDrawable drawable) {
- if (startTime == 0) {
- startTime = System.currentTimeMillis();
- }
-
- if (++frameCount == 100) {
- long endTime = System.currentTimeMillis();
- float fps = 100.0f / (float) (endTime - startTime) * 1000;
- frameCount = 0;
- startTime = System.currentTimeMillis();
-
- fpsText = "FPS: " + format.format(fps);
- if (fpsWidth == 0) {
- // Place it at a fixed offset wrt the lower right corner
- fpsWidth = (int) renderer.getBounds("FPS: 10000.00").getWidth();
- }
- }
-
time.update();
// Compute the next position of the text
@@ -162,11 +143,8 @@ public class TestTextRenderer implements GLEventListener {
// Draw text
renderer.draw(TEST_STRING, (int) position.x(), (int) position.y());
- if (fpsWidth != 0) {
- renderer.draw(fpsText,
- drawable.getWidth() - fpsWidth - 10,
- 20);
- }
+ // Draw FPS
+ fps.draw();
// Clean up rendering
renderer.endRendering();