diff options
author | Kenneth Russel <[email protected]> | 2007-01-07 01:40:19 +0000 |
---|---|---|
committer | Kenneth Russel <[email protected]> | 2007-01-07 01:40:19 +0000 |
commit | 73f676f55b23e12c75b2e56f5484c4280fc68aef (patch) | |
tree | 2906309a1e300efac1a54c0748c388ffbed996ad /src/classes/com/sun/opengl/util | |
parent | a4b0f29682539a6e3211d38bed5a17d12941f9b2 (diff) |
Added new FlyingText demo to illustrate more advanced usage of the
TextRenderer class; displays dynamically rotated, translated and
colored text. Changed how setSmoothing() is handled by the
TextureRenderer and stopped disabling smoothing in the TextRenderer.
For the time being, not exposing this flag in that class to keep the
API simple. Changed TextRenderer to also push/pop the texture matrix.
git-svn-id: file:///usr/local/projects/SUN/JOGL/git-svn/svn-server-sync/jogl/trunk@1073 232f8b59-042b-4e1e-8c03-345bb8c30851
Diffstat (limited to 'src/classes/com/sun/opengl/util')
-rwxr-xr-x | src/classes/com/sun/opengl/util/j2d/TextRenderer.java | 14 | ||||
-rwxr-xr-x | src/classes/com/sun/opengl/util/j2d/TextureRenderer.java | 35 |
2 files changed, 34 insertions, 15 deletions
diff --git a/src/classes/com/sun/opengl/util/j2d/TextRenderer.java b/src/classes/com/sun/opengl/util/j2d/TextRenderer.java index e97c31173..027f857fe 100755 --- a/src/classes/com/sun/opengl/util/j2d/TextRenderer.java +++ b/src/classes/com/sun/opengl/util/j2d/TextRenderer.java @@ -365,6 +365,19 @@ public class TextRenderer { } } + /** Disposes of all resources this TextRenderer is using. It is not + valid to use the TextRenderer after this method is called. + + @throws GLException If an OpenGL context is not current when this method is called + */ + public void dispose() throws GLException { + packer.dispose(); + packer = null; + cachedBackingStore = null; + cachedGraphics = null; + cachedFontRenderContext = null; + } + //---------------------------------------------------------------------- // Internals only below this point // @@ -466,7 +479,6 @@ public class TextRenderer { // store (i.e., non-default Paint, foreground color, etc.), but // for now, let's just be more efficient TextureRenderer renderer = TextureRenderer.createAlphaOnlyRenderer(w, h); - renderer.setSmoothing(false); return renderer; } diff --git a/src/classes/com/sun/opengl/util/j2d/TextureRenderer.java b/src/classes/com/sun/opengl/util/j2d/TextureRenderer.java index 360a82b25..976806db3 100755 --- a/src/classes/com/sun/opengl/util/j2d/TextureRenderer.java +++ b/src/classes/com/sun/opengl/util/j2d/TextureRenderer.java @@ -74,6 +74,7 @@ public class TextureRenderer { // Whether smoothing is enabled for the OpenGL texture (switching // between GL_LINEAR and GL_NEAREST filtering) private boolean smoothing = true; + private boolean smoothingChanged; // The backing store itself private BufferedImage image; @@ -179,24 +180,15 @@ public class TextureRenderer { /** Sets whether smoothing is enabled for the OpenGL texture; if so, uses GL_LINEAR interpolation for the minification and - magnification filters. Defaults to true. + magnification filters. Defaults to true. Changes to this setting + will not take effect until the next call to {@link + #beginOrthoRendering beginOrthoRendering}. @param smoothing whether smoothing is enabled for the OpenGL texture - @throws GLException If an OpenGL context is not current when this method is called */ - public void setSmoothing(boolean smoothing) throws GLException { + public void setSmoothing(boolean smoothing) { this.smoothing = smoothing; - // This can be set lazily - if (texture != null) { - GL gl = GLU.getCurrentGL(); - if (smoothing) { - texture.setTexParameteri(GL.GL_TEXTURE_MIN_FILTER, GL.GL_LINEAR); - texture.setTexParameteri(GL.GL_TEXTURE_MAG_FILTER, GL.GL_LINEAR); - } else { - texture.setTexParameteri(GL.GL_TEXTURE_MIN_FILTER, GL.GL_NEAREST); - texture.setTexParameteri(GL.GL_TEXTURE_MAG_FILTER, GL.GL_NEAREST); - } - } + smoothingChanged = true; } /** Returns whether smoothing is enabled for the OpenGL texture; see @@ -308,12 +300,25 @@ public class TextureRenderer { gl.glMatrixMode(GL.GL_MODELVIEW); gl.glPushMatrix(); gl.glLoadIdentity(); + gl.glMatrixMode(GL.GL_TEXTURE); + gl.glPushMatrix(); + gl.glLoadIdentity(); gl.glEnable(GL.GL_BLEND); gl.glBlendFunc(GL.GL_ONE, GL.GL_ONE_MINUS_SRC_ALPHA); Texture texture = getTexture(); texture.enable(); texture.bind(); gl.glTexEnvi(GL.GL_TEXTURE_ENV, GL.GL_TEXTURE_ENV_MODE, GL.GL_REPLACE); + if (smoothingChanged) { + smoothingChanged = false; + if (smoothing) { + texture.setTexParameteri(GL.GL_TEXTURE_MIN_FILTER, GL.GL_LINEAR); + texture.setTexParameteri(GL.GL_TEXTURE_MAG_FILTER, GL.GL_LINEAR); + } else { + texture.setTexParameteri(GL.GL_TEXTURE_MIN_FILTER, GL.GL_NEAREST); + texture.setTexParameteri(GL.GL_TEXTURE_MAG_FILTER, GL.GL_NEAREST); + } + } } /** Draws an orthographically projected rectangle containing all of @@ -388,6 +393,8 @@ public class TextureRenderer { gl.glPopMatrix(); gl.glMatrixMode(GL.GL_MODELVIEW); gl.glPopMatrix(); + gl.glMatrixMode(GL.GL_TEXTURE); + gl.glPopMatrix(); gl.glPopAttrib(); } |