diff options
author | Kenneth Russel <[email protected]> | 2007-02-27 22:05:56 +0000 |
---|---|---|
committer | Kenneth Russel <[email protected]> | 2007-02-27 22:05:56 +0000 |
commit | 5e381f7ba415b92247742bd32c8650d0a778f07f (patch) | |
tree | 461cb857ad7d49efb84b82574ea8907a24417709 /src/classes | |
parent | f024046a2eadf8cc695ac74181893baa8913245c (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')
-rwxr-xr-x | src/classes/com/sun/opengl/impl/packrect/RectanglePacker.java | 3 | ||||
-rwxr-xr-x | src/classes/com/sun/opengl/util/j2d/TextRenderer.java | 40 |
2 files changed, 42 insertions, 1 deletions
diff --git a/src/classes/com/sun/opengl/impl/packrect/RectanglePacker.java b/src/classes/com/sun/opengl/impl/packrect/RectanglePacker.java index 6057f7bb9..3a77b3bd1 100755 --- a/src/classes/com/sun/opengl/impl/packrect/RectanglePacker.java +++ b/src/classes/com/sun/opengl/impl/packrect/RectanglePacker.java @@ -287,7 +287,8 @@ public class RectanglePacker { BackingStoreManager. This RectanglePacker may no longer be used after calling this method. */ public void dispose() { - manager.deleteBackingStore(backingStore); + if (backingStore != null) + manager.deleteBackingStore(backingStore); backingStore = null; levels = null; } 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; } } } |