summaryrefslogtreecommitdiffstats
path: root/src/demos/j2d/FlyingText.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/FlyingText.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/FlyingText.java')
-rwxr-xr-xsrc/demos/j2d/FlyingText.java32
1 files changed, 4 insertions, 28 deletions
diff --git a/src/demos/j2d/FlyingText.java b/src/demos/j2d/FlyingText.java
index 49e723b..83bc77d 100755
--- a/src/demos/j2d/FlyingText.java
+++ b/src/demos/j2d/FlyingText.java
@@ -136,13 +136,7 @@ public class FlyingText extends Demo {
private int maxTextWidth;
- // FPS computation and rendering
- private TextRenderer fpsRenderer;
- private int fpsWidth;
- private int frameCount;
- private long startTime;
- private DecimalFormat format = new DecimalFormat("####.00");
- private String fpsText;
+ private FPSCounter fps;
public Container buildGUI() {
// Create gui
@@ -230,9 +224,8 @@ public class FlyingText extends Demo {
// Create the text renderer
renderer = new TextRenderer(new Font("Serif", Font.PLAIN, 72), true, true);
- // Use a different font for the FPS
- fpsRenderer = new TextRenderer(new Font("SansSerif", Font.BOLD, 36), true, true);
- fpsWidth = (int) fpsRenderer.getBounds("FPS: 1000.00").getWidth();
+ // Create the FPS counter
+ fps = new FPSCounter(drawable, 36);
width = drawable.getWidth();
height = drawable.getWidth();
@@ -259,19 +252,6 @@ public class FlyingText extends Demo {
}
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);
- }
-
time.update();
// Update velocities and positions of all text
@@ -389,11 +369,7 @@ public class FlyingText extends Demo {
renderer.endRendering();
// Use the FPS renderer last to render the FPS
- if (fpsText != null) {
- fpsRenderer.beginRendering(drawable.getWidth(), drawable.getHeight());
- fpsRenderer.draw(fpsText, drawable.getWidth() - fpsWidth - 20, 20);
- fpsRenderer.endRendering();
- }
+ fps.draw();
}
public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {