summaryrefslogtreecommitdiffstats
path: root/src/classes/com/sun/opengl/util/j2d
diff options
context:
space:
mode:
authorKenneth Russel <[email protected]>2007-02-27 22:05:56 +0000
committerKenneth Russel <[email protected]>2007-02-27 22:05:56 +0000
commit5e381f7ba415b92247742bd32c8650d0a778f07f (patch)
tree461cb857ad7d49efb84b82574ea8907a24417709 /src/classes/com/sun/opengl/util/j2d
parentf024046a2eadf8cc695ac74181893baa8913245c (diff)
Fixed Issue 278: Fatal error when rendering text
Added code to restore current text drawing color when backing store is resized. Fixed NullPointerException in RectanglePacker during deletion if no backing store was allocated. git-svn-id: file:///usr/local/projects/SUN/JOGL/git-svn/svn-server-sync/jogl/trunk@1156 232f8b59-042b-4e1e-8c03-345bb8c30851
Diffstat (limited to 'src/classes/com/sun/opengl/util/j2d')
-rwxr-xr-xsrc/classes/com/sun/opengl/util/j2d/TextRenderer.java40
1 files changed, 40 insertions, 0 deletions
diff --git a/src/classes/com/sun/opengl/util/j2d/TextRenderer.java b/src/classes/com/sun/opengl/util/j2d/TextRenderer.java
index 0d3ab73d9..a14918583 100755
--- a/src/classes/com/sun/opengl/util/j2d/TextRenderer.java
+++ b/src/classes/com/sun/opengl/util/j2d/TextRenderer.java
@@ -88,6 +88,12 @@ import com.sun.opengl.util.*;
renderer.endRendering();
</PRE>
+ Unless you are sharing textures and display lists between OpenGL
+ contexts, you do not need to call the {@link #dispose dispose}
+ method of the TextRenderer; the OpenGL resources it uses
+ internally will be cleaned up automatically when the OpenGL
+ context is destroyed. <P>
+
Internally, the renderer uses a rectangle packing algorithm to
pack multiple full Strings' rendering results (which are variable
size) onto a larger OpenGL texture. The internal backing store is
@@ -162,6 +168,14 @@ public class TextRenderer {
private boolean isOrthoMode;
private int beginRenderingWidth;
private int beginRenderingHeight;
+ // For resetting the color after disposal of the old backing store
+ private boolean haveCachedColor;
+ private float cachedR;
+ private float cachedG;
+ private float cachedB;
+ private float cachedA;
+ private Color cachedColor;
+ private boolean needToResetColor;
// For debugging only
private Frame dbgFrame;
@@ -356,6 +370,8 @@ public class TextRenderer {
*/
public void setColor(Color color) throws GLException {
getBackingStore().setColor(color);
+ haveCachedColor = true;
+ cachedColor = color;
}
/** Changes the current color of this TextRenderer to the supplied
@@ -375,6 +391,12 @@ public class TextRenderer {
*/
public void setColor(float r, float g, float b, float a) throws GLException {
getBackingStore().setColor(r, g, b, a);
+ haveCachedColor = true;
+ cachedR = r;
+ cachedG = g;
+ cachedB = b;
+ cachedA = a;
+ cachedColor = null;
}
/** Draws the supplied String at the desired location using the
@@ -576,6 +598,15 @@ public class TextRenderer {
packer.setMaxSize(sz[0], sz[0]);
haveMaxSize = true;
}
+
+ if (needToResetColor && haveCachedColor) {
+ if (cachedColor == null) {
+ getBackingStore().setColor(cachedR, cachedG, cachedB, cachedA);
+ } else {
+ getBackingStore().setColor(cachedColor);
+ }
+ needToResetColor = false;
+ }
}
private void endRendering(boolean ortho) throws GLException {
@@ -788,6 +819,15 @@ public class TextRenderer {
} else {
((TextureRenderer) newBackingStore).begin3DRendering();
}
+ if (haveCachedColor) {
+ if (cachedColor == null) {
+ ((TextureRenderer) newBackingStore).setColor(cachedR, cachedG, cachedB, cachedA);
+ } else {
+ ((TextureRenderer) newBackingStore).setColor(cachedColor);
+ }
+ }
+ } else {
+ needToResetColor = true;
}
}
}