diff options
author | Kenneth Russel <[email protected]> | 2008-02-18 07:58:12 +0000 |
---|---|---|
committer | Kenneth Russel <[email protected]> | 2008-02-18 07:58:12 +0000 |
commit | 91ad31541956e490331b0b111e8676cae5dcfbc5 (patch) | |
tree | 0ffa28310115a352606d28e5255856d51e4c8a7b /test | |
parent | 6f53c43238e16a426e394970aa0fbf377a51b62d (diff) |
Fixed Issue 344: Serious TextRenderer problems involving large fonts & unicode characters
The glyph-based rendering algorithm for the TextRenderer was
performing rendering in two steps: glyph preparation and upload, and
rendering. This structure doesn't work in the context of the
RectanglePacker, which can reorganize the backing store during any
upload.
Restructured the glyph cache in the TextRenderer in terms of flyweight
Glyph objects which know how to upload and render themselves. During
any upload, the outstanding glyphs not yet rendered to the screen may
thereby be flushed. Improved the code path which falls back to the
string-by-string algorithm for complex Unicode characters so that
incoming strings can be segmented into multiple parts which are
rendered either using the glyph cache or the string-by-string
algorithm.
Also tinkered with the bounds of glyphs and strings on the backing
store to try to more definitively eliminate bleed-over between
adjacent characters on the backing store, and to ensure that all of
the pixels of glyphs are drawn. Some heuristics are unfortunately
involved but the new code appears to work well with both very large
and very small fonts.
Added a few more test cases for the TextRenderer based on the bug
report. Tested with the previous test cases as well.
git-svn-id: file:///usr/local/projects/SUN/JOGL/git-svn/svn-server-sync/jogl/trunk@1533 232f8b59-042b-4e1e-8c03-345bb8c30851
Diffstat (limited to 'test')
-rwxr-xr-x | test/Issue344Base.java | 107 | ||||
-rwxr-xr-x | test/Issue344Test1.java | 10 | ||||
-rwxr-xr-x | test/Issue344Test2.java | 10 | ||||
-rwxr-xr-x | test/Issue344Test3.java | 10 |
4 files changed, 137 insertions, 0 deletions
diff --git a/test/Issue344Base.java b/test/Issue344Base.java new file mode 100755 index 000000000..548e3ec21 --- /dev/null +++ b/test/Issue344Base.java @@ -0,0 +1,107 @@ +import java.awt.BorderLayout; +import java.awt.Color; +import java.awt.Font; +import java.awt.Frame; +import java.awt.event.*; +import java.awt.geom.*; + +import javax.media.opengl.*; +import javax.media.opengl.glu.*; +import com.sun.opengl.util.*; +import com.sun.opengl.util.j2d.*; + +/** Test Code adapted from TextCube.java (in JOGL demos) + * + * @author spiraljetty + * @author kbr + */ + +public abstract class Issue344Base implements GLEventListener +{ + GLU glu = new GLU(); + TextRenderer renderer; + + float textScaleFactor; + Font font; + boolean useMipMaps; + + protected Issue344Base() { + font = new Font("default", Font.PLAIN, 200); + useMipMaps = true; //false + } + + protected abstract String getText(); + + protected void run(String[] args) { + Frame frame = new Frame(getClass().getName()); + frame.setLayout(new BorderLayout()); + + GLCanvas canvas = new GLCanvas(); + canvas.addGLEventListener(this); + frame.add(canvas, BorderLayout.CENTER); + + frame.setSize(512, 512); + frame.addWindowListener(new WindowAdapter() { + public void windowClosing(WindowEvent e) { + new Thread(new Runnable() { + public void run() { + System.exit(0); + } + }).start(); + } + }); + frame.show(); + } + + public void init(GLAutoDrawable drawable) + { + GL gl = drawable.getGL(); + + gl.glEnable(GL.GL_DEPTH_TEST); + + renderer = new TextRenderer(font, useMipMaps); + + Rectangle2D bounds = renderer.getBounds(getText()); + float w = (float) bounds.getWidth(); + float h = (float) bounds.getHeight(); + textScaleFactor = 2.0f / (w * 1.1f); + gl.setSwapInterval(0); + } + + public void display(GLAutoDrawable drawable) + { + GL gl = drawable.getGL(); + gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); + + gl.glMatrixMode(GL.GL_MODELVIEW); + gl.glLoadIdentity(); + glu.gluLookAt(0, 0, 10, + 0, 0, 0, + 0, 1, 0); + + renderer.begin3DRendering(); + Rectangle2D bounds = renderer.getBounds(getText()); + float w = (float) bounds.getWidth(); + float h = (float) bounds.getHeight(); + renderer.draw3D(getText(), + w / -2.0f * textScaleFactor, + h / -2.0f * textScaleFactor, + 3f, + textScaleFactor); + + renderer.end3DRendering(); + } + + public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) + { + GL gl = drawable.getGL(); + gl.glMatrixMode(GL.GL_PROJECTION); + gl.glLoadIdentity(); + glu.gluPerspective(15, (float) width / (float) height, 5, 15); + } + + public void displayChanged(GLAutoDrawable drawable, boolean modeChanged, + boolean deviceChanged) + { + } +} diff --git a/test/Issue344Test1.java b/test/Issue344Test1.java new file mode 100755 index 000000000..c0608ed6e --- /dev/null +++ b/test/Issue344Test1.java @@ -0,0 +1,10 @@ +public class Issue344Test1 extends Issue344Base { + protected String getText() { + // test 1 - weird artifacts appear with a large font & long string + return "abcdefghijklmnopqrstuvwxyz1234567890"; + } + + public static void main(String[] args) { + new Issue344Test1().run(args); + } +} diff --git a/test/Issue344Test2.java b/test/Issue344Test2.java new file mode 100755 index 000000000..b0900438c --- /dev/null +++ b/test/Issue344Test2.java @@ -0,0 +1,10 @@ +public class Issue344Test2 extends Issue344Base { + protected String getText() { + // test 2 - unicode hangs program with a large font & long string + return "\u201Cabcdefghijklmnopqrstuvwxyz\u201D"; + } + + public static void main(String[] args) { + new Issue344Test2().run(args); + } +} diff --git a/test/Issue344Test3.java b/test/Issue344Test3.java new file mode 100755 index 000000000..381bf0a1c --- /dev/null +++ b/test/Issue344Test3.java @@ -0,0 +1,10 @@ +public class Issue344Test3 extends Issue344Base { + protected String getText() { + // test 3 - slight rendering artifacts around very large letters + return "abcde"; + } + + public static void main(String[] args) { + new Issue344Test3().run(args); + } +} |