summaryrefslogtreecommitdiffstats
path: root/src/demos/j2d
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2014-05-27 04:25:26 +0200
committerSven Gothel <[email protected]>2014-05-27 04:25:26 +0200
commit6ee1f0641fbefbb309217401708e61d0c7f248e9 (patch)
tree2b0b47887ab4f80e4dec0ad00a4e1672349c9212 /src/demos/j2d
parente66c2c42d6f14181e0b81c83f47af620929ca291 (diff)
Adapt to JOGL HiDPI (Bug 741) changes up-to commit bcda2dad1a6569ffd4eba07b231d50fdafc60b7f
Diffstat (limited to 'src/demos/j2d')
-rwxr-xr-xsrc/demos/j2d/CustomText.java120
-rwxr-xr-xsrc/demos/j2d/FlyingText.java93
-rwxr-xr-xsrc/demos/j2d/TestOverlay.java67
-rwxr-xr-xsrc/demos/j2d/TestTextRenderer.java62
-rwxr-xr-xsrc/demos/j2d/TestTextureRenderer.java66
-rwxr-xr-xsrc/demos/j2d/TextFlow.java65
6 files changed, 272 insertions, 201 deletions
diff --git a/src/demos/j2d/CustomText.java b/src/demos/j2d/CustomText.java
index 8405b6e..d324a0e 100755
--- a/src/demos/j2d/CustomText.java
+++ b/src/demos/j2d/CustomText.java
@@ -1,21 +1,21 @@
/*
* Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
- *
+ *
* - Redistribution of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
- *
+ *
* - Redistribution in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- *
+ *
* Neither the name of Sun Microsystems, Inc. or the names of
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
- *
+ *
* This software is provided "AS IS," without a warranty of any kind. ALL
* EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
* INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
@@ -28,26 +28,19 @@
* DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
* ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
* SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
- *
+ *
* You acknowledge that this software is not designed or intended for use
* in the design, construction, operation or maintenance of any nuclear
* facility.
- *
+ *
* Sun gratefully acknowledges that this software was originally authored
* and developed by Kenneth Bradley Russell and Christopher John Kline.
*/
package demos.j2d;
-import com.jogamp.opengl.util.awt.TextRenderer;
-import com.jogamp.opengl.util.texture.Texture;
-import com.jogamp.opengl.util.texture.TextureCoords;
-import com.jogamp.opengl.util.texture.awt.AWTTextureIO;
-import demos.common.Demo;
-import demos.util.FPSCounter;
-import demos.util.SystemTime;
-import demos.util.Time;
import gleem.linalg.Vec2f;
+
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Container;
@@ -68,17 +61,28 @@ import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Random;
+
import javax.media.opengl.GL;
-import javax.media.opengl.GL2ES1;
import javax.media.opengl.GL2;
+import javax.media.opengl.GL2ES1;
import javax.media.opengl.GLAutoDrawable;
import javax.media.opengl.awt.GLCanvas;
import javax.media.opengl.glu.GLU;
-import com.jogamp.opengl.util.Animator;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
+import com.jogamp.opengl.util.Animator;
+import com.jogamp.opengl.util.awt.TextRenderer;
+import com.jogamp.opengl.util.texture.Texture;
+import com.jogamp.opengl.util.texture.TextureCoords;
+import com.jogamp.opengl.util.texture.awt.AWTTextureIO;
+
+import demos.common.Demo;
+import demos.util.FPSCounter;
+import demos.util.SystemTime;
+import demos.util.Time;
+
/** Illustrates more advanced use of the TextRenderer class; shows how
to do text filled with a linear Java 2D gradient. */
@@ -103,12 +107,14 @@ public class CustomText extends Demo {
final Animator animator = new Animator(canvas);
frame.addWindowListener(new WindowAdapter() {
- public void windowClosing(WindowEvent e) {
+ @Override
+ public void windowClosing(WindowEvent e) {
// Run this on another thread than the AWT event queue to
// make sure the call to Animator.stop() completes before
// exiting
new Thread(new Runnable() {
- public void run() {
+ @Override
+ public void run() {
animator.stop();
System.exit(0);
}
@@ -135,12 +141,12 @@ public class CustomText extends Demo {
String text;
}
- private List<TextInfo> textInfo = new ArrayList<TextInfo>();
+ private final List<TextInfo> textInfo = new ArrayList<TextInfo>();
private Time time;
private Texture backgroundTexture;
private TextRenderer renderer;
- private Random random = new Random();
- private GLU glu = new GLU();
+ private final Random random = new Random();
+ private final GLU glu = new GLU();
private int width;
private int height;
@@ -153,14 +159,16 @@ public class CustomText extends Demo {
JPanel panel = new JPanel();
JButton button = new JButton("Less Text");
button.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
+ @Override
+ public void actionPerformed(ActionEvent e) {
lessText();
}
});
panel.add(button);
button = new JButton("More Text");
button.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
+ @Override
+ public void actionPerformed(ActionEvent e) {
moreText();
}
});
@@ -188,7 +196,8 @@ public class CustomText extends Demo {
}
}
- public void init(GLAutoDrawable drawable) {
+ @Override
+public void init(GLAutoDrawable drawable) {
GL gl = drawable.getGL();
// Create the background texture
@@ -214,8 +223,8 @@ public class CustomText extends Demo {
// Create the FPS counter
fps = new FPSCounter(drawable, 36);
- width = drawable.getWidth();
- height = drawable.getWidth();
+ width = drawable.getSurfaceWidth();
+ height = drawable.getSurfaceWidth();
// Compute maximum width of text we're going to draw to avoid
// popping in/out at edges
@@ -237,10 +246,12 @@ public class CustomText extends Demo {
gl.setSwapInterval(0);
}
- public void dispose(GLAutoDrawable drawable) {
+ @Override
+public void dispose(GLAutoDrawable drawable) {
}
- public void display(GLAutoDrawable drawable) {
+ @Override
+public void display(GLAutoDrawable drawable) {
time.update();
// Update velocities and positions of all text
@@ -270,14 +281,14 @@ public class CustomText extends Demo {
// Use maxTextWidth to avoid popping in/out at edges
// Would be better to do oriented bounding rectangle computation
if (info.position.x() < -maxTextWidth) {
- info.position.setX(info.position.x() + drawable.getWidth() + 2 * maxTextWidth);
- } else if (info.position.x() > drawable.getWidth() + maxTextWidth) {
- info.position.setX(info.position.x() - drawable.getWidth() - 2 * maxTextWidth);
+ info.position.setX(info.position.x() + drawable.getSurfaceWidth() + 2 * maxTextWidth);
+ } else if (info.position.x() > drawable.getSurfaceWidth() + maxTextWidth) {
+ info.position.setX(info.position.x() - drawable.getSurfaceWidth() - 2 * maxTextWidth);
}
if (info.position.y() < -maxTextWidth) {
- info.position.setY(info.position.y() + drawable.getHeight() + 2 * maxTextWidth);
- } else if (info.position.y() > drawable.getHeight() + maxTextWidth) {
- info.position.setY(info.position.y() - drawable.getHeight() - 2 * maxTextWidth);
+ info.position.setY(info.position.y() + drawable.getSurfaceHeight() + 2 * maxTextWidth);
+ } else if (info.position.y() > drawable.getSurfaceHeight() + maxTextWidth) {
+ info.position.setY(info.position.y() - drawable.getSurfaceHeight() - 2 * maxTextWidth);
}
}
@@ -285,7 +296,7 @@ public class CustomText extends Demo {
gl.glClear(GL.GL_COLOR_BUFFER_BIT);
gl.glMatrixMode(GL2ES1.GL_PROJECTION);
gl.glLoadIdentity();
- glu.gluOrtho2D(0, drawable.getWidth(), 0, drawable.getHeight());
+ glu.gluOrtho2D(0, drawable.getSurfaceWidth(), 0, drawable.getSurfaceHeight());
gl.glMatrixMode(GL2ES1.GL_MODELVIEW);
gl.glLoadIdentity();
@@ -293,8 +304,8 @@ public class CustomText extends Demo {
backgroundTexture.enable(gl);
backgroundTexture.bind(gl);
TextureCoords coords = backgroundTexture.getImageTexCoords();
- int w = drawable.getWidth();
- int h = drawable.getHeight();
+ int w = drawable.getSurfaceWidth();
+ int h = drawable.getSurfaceHeight();
float fw = w / 100.0f;
float fh = h / 100.0f;
gl.glTexEnvi(GL2.GL_TEXTURE_ENV, GL2.GL_TEXTURE_ENV_MODE, GL2.GL_REPLACE);
@@ -311,7 +322,7 @@ public class CustomText extends Demo {
backgroundTexture.disable(gl);
// Render all text
- renderer.beginRendering(drawable.getWidth(), drawable.getHeight());
+ renderer.beginRendering(drawable.getSurfaceWidth(), drawable.getSurfaceHeight());
// Note we're doing some slightly fancy stuff to position the text.
// We tell the text renderer to render the text at the origin, and
@@ -336,7 +347,8 @@ public class CustomText extends Demo {
fps.draw();
}
- public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {
+ @Override
+public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {
this.width = width;
this.height = height;
}
@@ -387,10 +399,10 @@ public class CustomText extends Demo {
private static final Color DROP_SHADOW_COLOR = new Color(0, 0, 0, 0.5f);
class CustomRenderDelegate implements TextRenderer.RenderDelegate {
- private float gradientSize;
- private int dropShadowDepth;
- private Color color1;
- private Color color2;
+ private final float gradientSize;
+ private final int dropShadowDepth;
+ private final Color color1;
+ private final Color color2;
CustomRenderDelegate(float gradientSize, int dropShadowDepth, Color color1, Color color2) {
@@ -400,31 +412,36 @@ public class CustomText extends Demo {
this.color2 = color2;
}
- public boolean intensityOnly() {
+ @Override
+ public boolean intensityOnly() {
return false;
}
- public Rectangle2D getBounds(CharSequence str,
+ @Override
+ public Rectangle2D getBounds(CharSequence str,
Font font,
FontRenderContext frc) {
return getBounds(str.toString(), font, frc);
}
- public Rectangle2D getBounds(String str,
+ @Override
+ public Rectangle2D getBounds(String str,
Font font,
FontRenderContext frc) {
return getBounds(font.createGlyphVector(frc, str), frc);
}
- public Rectangle2D getBounds(GlyphVector gv, FontRenderContext frc) {
+ @Override
+ public Rectangle2D getBounds(GlyphVector gv, FontRenderContext frc) {
Rectangle2D stringBounds = gv.getPixelBounds(frc, 0, 0);
return new Rectangle2D.Double(stringBounds.getX(),
stringBounds.getY(),
stringBounds.getWidth() + dropShadowDepth,
stringBounds.getHeight() + dropShadowDepth);
}
-
- public void drawGlyphVector(Graphics2D graphics, GlyphVector str, int x, int y) {
+
+ @Override
+ public void drawGlyphVector(Graphics2D graphics, GlyphVector str, int x, int y) {
graphics.setColor(DROP_SHADOW_COLOR);
graphics.drawGlyphVector(str, x + dropShadowDepth, y + dropShadowDepth);
graphics.setColor(Color.WHITE);
@@ -434,7 +451,8 @@ public class CustomText extends Demo {
graphics.drawGlyphVector(str, x, y);
}
- public void draw(Graphics2D graphics, String str, int x, int y) {
+ @Override
+ public void draw(Graphics2D graphics, String str, int x, int y) {
graphics.setColor(DROP_SHADOW_COLOR);
graphics.drawString(str, x + dropShadowDepth, y + dropShadowDepth);
graphics.setColor(Color.WHITE);
diff --git a/src/demos/j2d/FlyingText.java b/src/demos/j2d/FlyingText.java
index 949a231..de4df71 100755
--- a/src/demos/j2d/FlyingText.java
+++ b/src/demos/j2d/FlyingText.java
@@ -1,21 +1,21 @@
/*
* Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
- *
+ *
* - Redistribution of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
- *
+ *
* - Redistribution in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- *
+ *
* Neither the name of Sun Microsystems, Inc. or the names of
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
- *
+ *
* This software is provided "AS IS," without a warranty of any kind. ALL
* EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
* INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
@@ -28,26 +28,19 @@
* DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
* ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
* SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
- *
+ *
* You acknowledge that this software is not designed or intended for use
* in the design, construction, operation or maintenance of any nuclear
* facility.
- *
+ *
* Sun gratefully acknowledges that this software was originally authored
* and developed by Kenneth Bradley Russell and Christopher John Kline.
*/
package demos.j2d;
-import com.jogamp.opengl.util.awt.TextRenderer;
-import com.jogamp.opengl.util.texture.Texture;
-import com.jogamp.opengl.util.texture.TextureCoords;
-import com.jogamp.opengl.util.texture.awt.AWTTextureIO;
-import demos.common.Demo;
-import demos.util.FPSCounter;
-import demos.util.SystemTime;
-import demos.util.Time;
import gleem.linalg.Vec2f;
+
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Container;
@@ -64,12 +57,12 @@ import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Random;
+
import javax.media.opengl.GL;
import javax.media.opengl.GL2;
import javax.media.opengl.GLAutoDrawable;
import javax.media.opengl.awt.GLCanvas;
import javax.media.opengl.glu.GLU;
-import com.jogamp.opengl.util.Animator;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
@@ -77,6 +70,17 @@ import javax.swing.JSlider;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
+import com.jogamp.opengl.util.Animator;
+import com.jogamp.opengl.util.awt.TextRenderer;
+import com.jogamp.opengl.util.texture.Texture;
+import com.jogamp.opengl.util.texture.TextureCoords;
+import com.jogamp.opengl.util.texture.awt.AWTTextureIO;
+
+import demos.common.Demo;
+import demos.util.FPSCounter;
+import demos.util.SystemTime;
+import demos.util.Time;
+
/** Illustrates more advanced use of the TextRenderer class; shows how
@@ -103,12 +107,14 @@ public class FlyingText extends Demo {
final Animator animator = new Animator(canvas);
frame.addWindowListener(new WindowAdapter() {
- public void windowClosing(WindowEvent e) {
+ @Override
+ public void windowClosing(WindowEvent e) {
// Run this on another thread than the AWT event queue to
// make sure the call to Animator.stop() completes before
// exiting
new Thread(new Runnable() {
- public void run() {
+ @Override
+ public void run() {
animator.stop();
System.exit(0);
}
@@ -147,13 +153,13 @@ public class FlyingText extends Demo {
String text;
}
- private List<TextInfo> textInfo = new ArrayList<TextInfo>();
+ private final List<TextInfo> textInfo = new ArrayList<TextInfo>();
private int dropShadowDistance = DEFAULT_DROP_SHADOW_DIST;
private Time time;
private Texture backgroundTexture;
private TextRenderer renderer;
- private Random random = new Random();
- private GLU glu = new GLU();
+ private final Random random = new Random();
+ private final GLU glu = new GLU();
private int width;
private int height;
@@ -166,7 +172,8 @@ public class FlyingText extends Demo {
JPanel panel = new JPanel();
JButton button = new JButton("Less Text");
button.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
+ @Override
+ public void actionPerformed(ActionEvent e) {
lessText();
}
});
@@ -176,14 +183,16 @@ public class FlyingText extends Demo {
getMaxDropShadowDistance(),
getDropShadowDistance());
slider.addChangeListener(new ChangeListener() {
- public void stateChanged(ChangeEvent e) {
+ @Override
+ public void stateChanged(ChangeEvent e) {
setDropShadowDistance(slider.getValue());
}
});
panel.add(slider);
button = new JButton("More Text");
button.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
+ @Override
+ public void actionPerformed(ActionEvent e) {
moreText();
}
});
@@ -227,7 +236,8 @@ public class FlyingText extends Demo {
dropShadowDistance = dist;
}
- public void init(GLAutoDrawable drawable) {
+ @Override
+public void init(GLAutoDrawable drawable) {
GL gl = drawable.getGL();
// Create the background texture
BufferedImage bgImage = new BufferedImage(2, 2, BufferedImage.TYPE_BYTE_GRAY);
@@ -251,8 +261,8 @@ public class FlyingText extends Demo {
// Create the FPS counter
fps = new FPSCounter(drawable, 36);
- width = drawable.getWidth();
- height = drawable.getWidth();
+ width = drawable.getSurfaceWidth();
+ height = drawable.getSurfaceHeight();
// Compute maximum width of text we're going to draw to avoid
// popping in/out at edges
@@ -274,14 +284,16 @@ public class FlyingText extends Demo {
gl.setSwapInterval(0);
}
- public void dispose(GLAutoDrawable drawable) {
+ @Override
+public void dispose(GLAutoDrawable drawable) {
backgroundTexture = null;
renderer = null;
fps = null;
time = null;
}
- public void display(GLAutoDrawable drawable) {
+ @Override
+public void display(GLAutoDrawable drawable) {
time.update();
// Update velocities and positions of all text
@@ -323,14 +335,14 @@ public class FlyingText extends Demo {
// Use maxTextWidth to avoid popping in/out at edges
// Would be better to do oriented bounding rectangle computation
if (info.position.x() < -maxTextWidth) {
- info.position.setX(info.position.x() + drawable.getWidth() + 2 * maxTextWidth);
- } else if (info.position.x() > drawable.getWidth() + maxTextWidth) {
- info.position.setX(info.position.x() - drawable.getWidth() - 2 * maxTextWidth);
+ info.position.setX(info.position.x() + drawable.getSurfaceWidth() + 2 * maxTextWidth);
+ } else if (info.position.x() > drawable.getSurfaceWidth() + maxTextWidth) {
+ info.position.setX(info.position.x() - drawable.getSurfaceWidth() - 2 * maxTextWidth);
}
if (info.position.y() < -maxTextWidth) {
- info.position.setY(info.position.y() + drawable.getHeight() + 2 * maxTextWidth);
- } else if (info.position.y() > drawable.getHeight() + maxTextWidth) {
- info.position.setY(info.position.y() - drawable.getHeight() - 2 * maxTextWidth);
+ info.position.setY(info.position.y() + drawable.getSurfaceHeight() + 2 * maxTextWidth);
+ } else if (info.position.y() > drawable.getSurfaceHeight() + maxTextWidth) {
+ info.position.setY(info.position.y() - drawable.getSurfaceHeight() - 2 * maxTextWidth);
}
}
@@ -338,7 +350,7 @@ public class FlyingText extends Demo {
gl.glClear(GL2.GL_COLOR_BUFFER_BIT);
gl.glMatrixMode(GL2.GL_PROJECTION);
gl.glLoadIdentity();
- glu.gluOrtho2D(0, drawable.getWidth(), 0, drawable.getHeight());
+ glu.gluOrtho2D(0, drawable.getSurfaceWidth(), 0, drawable.getSurfaceHeight());
gl.glMatrixMode(GL2.GL_MODELVIEW);
gl.glLoadIdentity();
@@ -346,8 +358,8 @@ public class FlyingText extends Demo {
backgroundTexture.enable(gl);
backgroundTexture.bind(gl);
TextureCoords coords = backgroundTexture.getImageTexCoords();
- int w = drawable.getWidth();
- int h = drawable.getHeight();
+ int w = drawable.getSurfaceWidth();
+ int h = drawable.getSurfaceHeight();
float fw = w / 100.0f;
float fh = h / 100.0f;
gl.glTexEnvi(GL2.GL_TEXTURE_ENV, GL2.GL_TEXTURE_ENV_MODE, GL2.GL_REPLACE);
@@ -364,7 +376,7 @@ public class FlyingText extends Demo {
backgroundTexture.disable(gl);
// Render all text
- renderer.beginRendering(drawable.getWidth(), drawable.getHeight());
+ renderer.beginRendering(drawable.getSurfaceWidth(), drawable.getSurfaceHeight());
// Note we're doing some slightly fancy stuff to position the text.
// We tell the text renderer to render the text at the origin, and
@@ -406,7 +418,8 @@ public class FlyingText extends Demo {
fps.draw();
}
- public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {
+ @Override
+public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {
this.width = width;
this.height = height;
}
diff --git a/src/demos/j2d/TestOverlay.java b/src/demos/j2d/TestOverlay.java
index 13cb39e..bc2bcef 100755
--- a/src/demos/j2d/TestOverlay.java
+++ b/src/demos/j2d/TestOverlay.java
@@ -1,21 +1,21 @@
/*
* Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
- *
+ *
* - Redistribution of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
- *
+ *
* - Redistribution in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- *
+ *
* Neither the name of Sun Microsystems, Inc. or the names of
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
- *
+ *
* This software is provided "AS IS," without a warranty of any kind. ALL
* EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
* INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
@@ -28,21 +28,19 @@
* DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
* ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
* SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
- *
+ *
* You acknowledge that this software is not designed or intended for use
* in the design, construction, operation or maintenance of any nuclear
* facility.
- *
+ *
* Sun gratefully acknowledges that this software was originally authored
* and developed by Kenneth Bradley Russell and Christopher John Kline.
*/
package demos.j2d;
-import com.jogamp.opengl.util.awt.Overlay;
-import demos.gears.Gears;
-import demos.util.*;
-import gleem.linalg.*;
+import gleem.linalg.Vec2f;
+
import java.awt.AlphaComposite;
import java.awt.Color;
import java.awt.Font;
@@ -54,12 +52,19 @@ import java.awt.event.WindowEvent;
import java.awt.font.FontRenderContext;
import java.awt.font.GlyphVector;
import java.text.DecimalFormat;
+
import javax.media.opengl.GL;
import javax.media.opengl.GLAutoDrawable;
import javax.media.opengl.GLCapabilities;
import javax.media.opengl.GLEventListener;
import javax.media.opengl.awt.GLCanvas;
+
import com.jogamp.opengl.util.Animator;
+import com.jogamp.opengl.util.awt.Overlay;
+
+import demos.gears.Gears;
+import demos.util.SystemTime;
+import demos.util.Time;
/** A simple test of the Overlay utility class. Draws gears underneath
with moving Java 2D-rendered text on top. */
@@ -76,12 +81,14 @@ public class TestOverlay implements GLEventListener {
frame.setSize(512, 512);
final Animator animator = new Animator(canvas);
frame.addWindowListener(new WindowAdapter() {
- public void windowClosing(WindowEvent e) {
+ @Override
+ public void windowClosing(WindowEvent e) {
// Run this on another thread than the AWT event queue to
// make sure the call to Animator.stop() completes before
// exiting
new Thread(new Runnable() {
- public void run() {
+ @Override
+ public void run() {
animator.stop();
System.exit(0);
}
@@ -95,21 +102,22 @@ public class TestOverlay implements GLEventListener {
private Overlay overlay;
private Time time;
private Font font;
- private Color TRANSPARENT_BLACK = new Color(0.0f, 0.0f, 0.0f, 0.0f);
+ private final Color TRANSPARENT_BLACK = new Color(0.0f, 0.0f, 0.0f, 0.0f);
private FontRenderContext frc;
private GlyphVector gv;
- private Vec2f velocity = new Vec2f(100.0f, 150.0f);
+ private final Vec2f velocity = new Vec2f(100.0f, 150.0f);
private Vec2f position;
private Rectangle textBounds;
private Rectangle lastTextBounds;
- private String TEST_STRING = "Java 2D Text";
+ private final String TEST_STRING = "Java 2D Text";
private long startTime;
private int frameCount;
- private DecimalFormat format = new DecimalFormat("####.00");
+ private final DecimalFormat format = new DecimalFormat("####.00");
private Rectangle fpsBounds;
- public void init(GLAutoDrawable drawable) {
+ @Override
+public void init(GLAutoDrawable drawable) {
GL gl = drawable.getGL();
gl.setSwapInterval(0);
@@ -118,20 +126,22 @@ public class TestOverlay implements GLEventListener {
((SystemTime) time).rebase();
// Start the text half way up the left side
- position = new Vec2f(0.0f, drawable.getHeight() / 2);
+ position = new Vec2f(0.0f, drawable.getSurfaceHeight() / 2);
// Create the font, render context, and glyph vector
font = new Font("SansSerif", Font.BOLD, 36);
}
- public void dispose(GLAutoDrawable drawable) {
+ @Override
+public void dispose(GLAutoDrawable drawable) {
font = null;
overlay = null;
time = null;
position = null;
}
- public void display(GLAutoDrawable drawable) {
+ @Override
+public void display(GLAutoDrawable drawable) {
if (startTime == 0) {
startTime = System.currentTimeMillis();
}
@@ -140,7 +150,7 @@ public class TestOverlay implements GLEventListener {
if (++frameCount == 30) {
long endTime = System.currentTimeMillis();
- float fps = 30.0f / (float) (endTime - startTime) * 1000;
+ float fps = 30.0f / (endTime - startTime) * 1000;
frameCount = 0;
startTime = System.currentTimeMillis();
@@ -148,8 +158,8 @@ public class TestOverlay implements GLEventListener {
String fpsString = "FPS: " + format.format(fps);
GlyphVector gv = font.createGlyphVector(frc, TEST_STRING);
fpsBounds = gv.getPixelBounds(frc, 0, 0);
- int x = drawable.getWidth() - fpsBounds.width - 20;
- int y = drawable.getHeight() - 20;
+ int x = drawable.getSurfaceWidth() - fpsBounds.width - 20;
+ int y = drawable.getSurfaceHeight() - 20;
g2d.setFont(font);
g2d.setComposite(AlphaComposite.Src);
g2d.setColor(TRANSPARENT_BLACK);
@@ -174,12 +184,12 @@ public class TestOverlay implements GLEventListener {
textBounds = gv.getPixelBounds(frc, position.x(), position.y());
if (textBounds.getMinX() < 0) {
velocity.setX(Math.abs(velocity.x()));
- } else if (textBounds.getMaxX() > drawable.getWidth()) {
+ } else if (textBounds.getMaxX() > drawable.getSurfaceWidth()) {
velocity.setX(-1.0f * Math.abs(velocity.x()));
}
if (textBounds.getMinY() < 0) {
velocity.setY(Math.abs(velocity.y()));
- } else if (textBounds.getMaxY() > drawable.getHeight()) {
+ } else if (textBounds.getMaxY() > drawable.getSurfaceHeight()) {
velocity.setY(-1.0f * Math.abs(velocity.y()));
}
@@ -190,7 +200,7 @@ public class TestOverlay implements GLEventListener {
(int) (lastTextBounds.getWidth() + 1), (int) (lastTextBounds.getHeight() + 1));
} else if (overlay.contentsLost()) {
g2d.setColor(TRANSPARENT_BLACK);
- g2d.fillRect(0, 0, drawable.getWidth(), drawable.getHeight());
+ g2d.fillRect(0, 0, drawable.getSurfaceWidth(), drawable.getSurfaceHeight());
}
g2d.setColor(Color.WHITE);
g2d.drawString(TEST_STRING, position.x(), position.y());
@@ -213,6 +223,7 @@ public class TestOverlay implements GLEventListener {
}
// Unused methods
- public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {}
+ @Override
+public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {}
public void displayChanged(GLAutoDrawable drawable, boolean modeChanged, boolean deviceChanged) {}
}
diff --git a/src/demos/j2d/TestTextRenderer.java b/src/demos/j2d/TestTextRenderer.java
index 4779522..0898ceb 100755
--- a/src/demos/j2d/TestTextRenderer.java
+++ b/src/demos/j2d/TestTextRenderer.java
@@ -1,21 +1,21 @@
/*
* Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
- *
+ *
* - Redistribution of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
- *
+ *
* - Redistribution in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- *
+ *
* Neither the name of Sun Microsystems, Inc. or the names of
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
- *
+ *
* This software is provided "AS IS," without a warranty of any kind. ALL
* EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
* INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
@@ -28,34 +28,38 @@
* DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
* ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
* SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
- *
+ *
* You acknowledge that this software is not designed or intended for use
* in the design, construction, operation or maintenance of any nuclear
* facility.
- *
+ *
* Sun gratefully acknowledges that this software was originally authored
* and developed by Kenneth Bradley Russell and Christopher John Kline.
*/
package demos.j2d;
-import com.jogamp.opengl.util.awt.TextRenderer;
-import demos.gears.Gears;
-import demos.util.FPSCounter;
-import demos.util.SystemTime;
-import demos.util.Time;
import gleem.linalg.Vec2f;
+
import java.awt.Font;
import java.awt.Frame;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.geom.Rectangle2D;
+
import javax.media.opengl.GL;
import javax.media.opengl.GLAutoDrawable;
import javax.media.opengl.GLCapabilities;
import javax.media.opengl.GLEventListener;
import javax.media.opengl.awt.GLCanvas;
+
import com.jogamp.opengl.util.Animator;
+import com.jogamp.opengl.util.awt.TextRenderer;
+
+import demos.gears.Gears;
+import demos.util.FPSCounter;
+import demos.util.SystemTime;
+import demos.util.Time;
@@ -74,12 +78,14 @@ public class TestTextRenderer implements GLEventListener {
frame.setSize(512, 512);
final Animator animator = new Animator(canvas);
frame.addWindowListener(new WindowAdapter() {
- public void windowClosing(WindowEvent e) {
+ @Override
+ public void windowClosing(WindowEvent e) {
// Run this on another thread than the AWT event queue to
// make sure the call to Animator.stop() completes before
// exiting
new Thread(new Runnable() {
- public void run() {
+ @Override
+ public void run() {
animator.stop();
System.exit(0);
}
@@ -94,14 +100,15 @@ public class TestTextRenderer implements GLEventListener {
private TextRenderer renderer;
private Time time;
// private Font font;
- private Vec2f velocity = new Vec2f(100.0f, 150.0f);
+ private final Vec2f velocity = new Vec2f(100.0f, 150.0f);
private Vec2f position;
- private String TEST_STRING = "Java 2D Text";
+ private final String TEST_STRING = "Java 2D Text";
private int textWidth;
private int textHeight;
private FPSCounter fps;
- public void init(GLAutoDrawable drawable) {
+ @Override
+public void init(GLAutoDrawable drawable) {
GL gl = drawable.getGL();
// Don't artificially slow us down, at least on platforms where we
@@ -115,7 +122,7 @@ public class TestTextRenderer implements GLEventListener {
((SystemTime) time).rebase();
// Start the text half way up the left side
- position = new Vec2f(0.0f, drawable.getHeight() / 2);
+ position = new Vec2f(0.0f, drawable.getSurfaceHeight() / 2);
Rectangle2D textBounds = renderer.getBounds(TEST_STRING);
textWidth = (int) textBounds.getWidth();
textHeight = (int) textBounds.getHeight();
@@ -123,13 +130,15 @@ public class TestTextRenderer implements GLEventListener {
fps = new FPSCounter(drawable, 36);
}
- public void dispose(GLAutoDrawable drawable) {
+ @Override
+public void dispose(GLAutoDrawable drawable) {
renderer = null;
position = null;
time = null;
}
- public void display(GLAutoDrawable drawable) {
+ @Override
+public void display(GLAutoDrawable drawable) {
time.update();
// Compute the next position of the text
@@ -137,17 +146,17 @@ public class TestTextRenderer implements GLEventListener {
// Figure out whether we have to switch directions
if (position.x() < 0) {
velocity.setX(Math.abs(velocity.x()));
- } else if (position.x() + textWidth > drawable.getWidth()) {
+ } else if (position.x() + textWidth > drawable.getSurfaceWidth()) {
velocity.setX(-1.0f * Math.abs(velocity.x()));
- }
+ }
if (position.y() < 0) {
velocity.setY(Math.abs(velocity.y()));
- } else if (position.y() + textHeight > drawable.getHeight()) {
+ } else if (position.y() + textHeight > drawable.getSurfaceHeight()) {
velocity.setY(-1.0f * Math.abs(velocity.y()));
- }
+ }
// Prepare to draw text
- renderer.beginRendering(drawable.getWidth(), drawable.getHeight());
+ renderer.beginRendering(drawable.getSurfaceWidth(), drawable.getSurfaceHeight());
// Draw text
renderer.draw(TEST_STRING, (int) position.x(), (int) position.y());
@@ -160,6 +169,7 @@ public class TestTextRenderer implements GLEventListener {
}
// Unused methods
- public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {}
+ @Override
+public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {}
public void displayChanged(GLAutoDrawable drawable, boolean modeChanged, boolean deviceChanged) {}
}
diff --git a/src/demos/j2d/TestTextureRenderer.java b/src/demos/j2d/TestTextureRenderer.java
index a217c7b..ccf3dbf 100755
--- a/src/demos/j2d/TestTextureRenderer.java
+++ b/src/demos/j2d/TestTextureRenderer.java
@@ -1,21 +1,21 @@
/*
* Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
- *
+ *
* - Redistribution of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
- *
+ *
* - Redistribution in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- *
+ *
* Neither the name of Sun Microsystems, Inc. or the names of
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
- *
+ *
* This software is provided "AS IS," without a warranty of any kind. ALL
* EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
* INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
@@ -28,22 +28,19 @@
* DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
* ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
* SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
- *
+ *
* You acknowledge that this software is not designed or intended for use
* in the design, construction, operation or maintenance of any nuclear
* facility.
- *
+ *
* Sun gratefully acknowledges that this software was originally authored
* and developed by Kenneth Bradley Russell and Christopher John Kline.
*/
package demos.j2d;
-import com.jogamp.opengl.util.awt.TextureRenderer;
-import demos.gears.Gears;
-import demos.util.SystemTime;
-import demos.util.Time;
import gleem.linalg.Vec2f;
+
import java.awt.AlphaComposite;
import java.awt.Color;
import java.awt.Font;
@@ -55,13 +52,20 @@ import java.awt.event.WindowEvent;
import java.awt.font.FontRenderContext;
import java.awt.font.GlyphVector;
import java.text.DecimalFormat;
+
import javax.media.opengl.GL;
import javax.media.opengl.GLAutoDrawable;
import javax.media.opengl.GLCapabilities;
import javax.media.opengl.GLEventListener;
import javax.media.opengl.GLProfile;
import javax.media.opengl.awt.GLCanvas;
+
import com.jogamp.opengl.util.Animator;
+import com.jogamp.opengl.util.awt.TextureRenderer;
+
+import demos.gears.Gears;
+import demos.util.SystemTime;
+import demos.util.Time;
@@ -81,12 +85,14 @@ public class TestTextureRenderer implements GLEventListener {
frame.setSize(512, 512);
final Animator animator = new Animator(canvas);
frame.addWindowListener(new WindowAdapter() {
- public void windowClosing(WindowEvent e) {
+ @Override
+ public void windowClosing(WindowEvent e) {
// Run this on another thread than the AWT event queue to
// make sure the call to Animator.stop() completes before
// exiting
new Thread(new Runnable() {
- public void run() {
+ @Override
+ public void run() {
animator.stop();
System.exit(0);
}
@@ -100,17 +106,18 @@ public class TestTextureRenderer implements GLEventListener {
private TextureRenderer renderer;
private Time time;
private Font font;
- private Color TRANSPARENT_BLACK = new Color(0.0f, 0.0f, 0.0f, 0.0f);
- private Vec2f velocity = new Vec2f(100.0f, 150.0f);
+ private final Color TRANSPARENT_BLACK = new Color(0.0f, 0.0f, 0.0f, 0.0f);
+ private final Vec2f velocity = new Vec2f(100.0f, 150.0f);
private Vec2f position;
private Rectangle textBounds;
private Rectangle fpsBounds;
- private String TEST_STRING = "Java 2D Text";
+ private final String TEST_STRING = "Java 2D Text";
private long startTime;
private int frameCount;
- private DecimalFormat format = new DecimalFormat("####.00");
+ private final DecimalFormat format = new DecimalFormat("####.00");
- public void init(GLAutoDrawable drawable) {
+ @Override
+public void init(GLAutoDrawable drawable) {
GL gl = drawable.getGL();
gl.setSwapInterval(0);
@@ -119,7 +126,7 @@ public class TestTextureRenderer implements GLEventListener {
((SystemTime) time).rebase();
// Start the text half way up the left side
- position = new Vec2f(0.0f, drawable.getHeight() / 2);
+ position = new Vec2f(0.0f, drawable.getSurfaceHeight() / 2);
// Create the font, render context, and glyph vector
font = new Font("SansSerif", Font.BOLD, 36);
@@ -136,21 +143,23 @@ public class TestTextureRenderer implements GLEventListener {
renderer.markDirty(textBounds.x, textBounds.y, textBounds.width, textBounds.height);
}
- public void dispose(GLAutoDrawable drawable) {
+ @Override
+public void dispose(GLAutoDrawable drawable) {
renderer = null;
textBounds = null;
position = null;
time = null;
}
- public void display(GLAutoDrawable drawable) {
+ @Override
+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;
+ float fps = 100.0f / (endTime - startTime) * 1000;
frameCount = 0;
startTime = System.currentTimeMillis();
@@ -177,17 +186,17 @@ public class TestTextureRenderer implements GLEventListener {
textBounds.width, textBounds.height);
if (tmpBounds.getMinX() < 0) {
velocity.setX(Math.abs(velocity.x()));
- } else if (tmpBounds.getMaxX() > drawable.getWidth()) {
+ } else if (tmpBounds.getMaxX() > drawable.getSurfaceWidth()) {
velocity.setX(-1.0f * Math.abs(velocity.x()));
}
if (tmpBounds.getMinY() < 0) {
velocity.setY(Math.abs(velocity.y()));
- } else if (tmpBounds.getMaxY() > drawable.getHeight()) {
+ } else if (tmpBounds.getMaxY() > drawable.getSurfaceHeight()) {
velocity.setY(-1.0f * Math.abs(velocity.y()));
}
// Prepare to draw from the renderer's texture
- renderer.beginOrthoRendering(drawable.getWidth(), drawable.getHeight());
+ renderer.beginOrthoRendering(drawable.getSurfaceWidth(), drawable.getSurfaceHeight());
// Draw from the renderer's texture
renderer.drawOrthoRect((int) position.x(), (int) position.y(),
@@ -198,19 +207,20 @@ public class TestTextureRenderer implements GLEventListener {
// If we have the FPS, draw it
if (fpsBounds != null) {
- renderer.drawOrthoRect(drawable.getWidth() - fpsBounds.width,
+ renderer.drawOrthoRect(drawable.getSurfaceWidth() - fpsBounds.width,
20,
fpsBounds.x,
renderer.getHeight() - fpsBounds.y - fpsBounds.height,
fpsBounds.width,
fpsBounds.height);
}
-
+
// Clean up rendering
renderer.endOrthoRendering();
}
// Unused methods
- public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {}
+ @Override
+public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {}
public void displayChanged(GLAutoDrawable drawable, boolean modeChanged, boolean deviceChanged) {}
}
diff --git a/src/demos/j2d/TextFlow.java b/src/demos/j2d/TextFlow.java
index 395554b..39283b3 100755
--- a/src/demos/j2d/TextFlow.java
+++ b/src/demos/j2d/TextFlow.java
@@ -1,21 +1,21 @@
/*
* Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
- *
+ *
* - Redistribution of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
- *
+ *
* - Redistribution in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- *
+ *
* Neither the name of Sun Microsystems, Inc. or the names of
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
- *
+ *
* This software is provided "AS IS," without a warranty of any kind. ALL
* EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
* INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
@@ -28,21 +28,17 @@
* DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
* ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
* SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
- *
+ *
* You acknowledge that this software is not designed or intended for use
* in the design, construction, operation or maintenance of any nuclear
* facility.
- *
+ *
* Sun gratefully acknowledges that this software was originally authored
* and developed by Kenneth Bradley Russell and Christopher John Kline.
*/
package demos.j2d;
-import com.jogamp.opengl.util.awt.TextRenderer;
-import demos.common.Demo;
-import demos.util.SystemTime;
-import demos.util.Time;
import java.awt.BorderLayout;
import java.awt.Font;
import java.awt.Frame;
@@ -57,12 +53,19 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+
import javax.media.opengl.GL;
+import javax.media.opengl.GLAutoDrawable;
import javax.media.opengl.GLCapabilities;
import javax.media.opengl.GLProfile;
-import javax.media.opengl.GLAutoDrawable;
import javax.media.opengl.awt.GLCanvas;
+
import com.jogamp.opengl.util.Animator;
+import com.jogamp.opengl.util.awt.TextRenderer;
+
+import demos.common.Demo;
+import demos.util.SystemTime;
+import demos.util.Time;
/** Illustrates both the TextRenderer's capability for handling
@@ -87,12 +90,14 @@ public class TextFlow extends Demo {
frame.setSize(512, 512);
final Animator animator = new Animator(canvas);
frame.addWindowListener(new WindowAdapter() {
- public void windowClosing(WindowEvent e) {
+ @Override
+ public void windowClosing(WindowEvent e) {
// Run this on another thread than the AWT event queue to
// make sure the call to Animator.stop() completes before
// exiting
new Thread(new Runnable() {
- public void run() {
+ @Override
+ public void run() {
animator.stop();
System.exit(0);
}
@@ -103,15 +108,15 @@ public class TextFlow extends Demo {
animator.start();
}
- private List<String> lines = new ArrayList<String>();
+ private final List<String> lines = new ArrayList<String>();
private Time time;
private TextRenderer renderer;
private int curParagraph;
- private float x = 30;
+ private final float x = 30;
private float y;
- private float velocity = 100; // pixels/sec
+ private final float velocity = 100; // pixels/sec
private int lineSpacing;
- private int EXTRA_LINE_SPACING = 5;
+ private final int EXTRA_LINE_SPACING = 5;
private void reflow(float width) {
lines.clear();
@@ -140,40 +145,43 @@ public class TextFlow extends Demo {
}
lineSpacing = (int) ((float) lineSpacing / (float) numLines) + EXTRA_LINE_SPACING;
}
-
- public void init(GLAutoDrawable drawable) {
+
+ @Override
+public void init(GLAutoDrawable drawable) {
renderer = new TextRenderer(new Font("SansSerif", Font.PLAIN, 36), true, false);
time = new SystemTime();
((SystemTime) time).rebase();
}
- public void dispose(GLAutoDrawable drawable) {
+ @Override
+public void dispose(GLAutoDrawable drawable) {
renderer = null;
time = null;
}
- public void display(GLAutoDrawable drawable) {
+ @Override
+public void display(GLAutoDrawable drawable) {
time.update();
GL gl = drawable.getGL();
gl.glClear(GL.GL_COLOR_BUFFER_BIT);
-
+
float deltaT = (float) time.deltaT();
y += velocity * deltaT;
// Draw text starting at the specified paragraph
int paragraph = 0;
float curY = y;
- renderer.beginRendering(drawable.getWidth(), drawable.getHeight());
+ renderer.beginRendering(drawable.getSurfaceWidth(), drawable.getSurfaceHeight());
boolean renderedOne = false;
for (int i = 0; i < lines.size(); i++) {
- String line = (String) lines.get(i);
+ String line = lines.get(i);
if (line == null) {
++paragraph;
if (paragraph >= curParagraph) {
// If this paragraph has scrolled off the top of the screen,
// don't draw it the next frame
- if (paragraph > curParagraph && curY > drawable.getHeight()) {
+ if (paragraph > curParagraph && curY > drawable.getSurfaceHeight()) {
++curParagraph;
y = curY;
}
@@ -182,7 +190,7 @@ public class TextFlow extends Demo {
} else {
if (paragraph >= curParagraph) {
curY -= lineSpacing;
- if (curY < drawable.getHeight() + lineSpacing) {
+ if (curY < drawable.getSurfaceHeight() + lineSpacing) {
renderer.draw(line, (int) x, (int) curY);
renderedOne = true;
}
@@ -201,7 +209,8 @@ public class TextFlow extends Demo {
}
}
- public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {
+ @Override
+public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {
reflow(Math.max(100, width - 60));
}