From 73f676f55b23e12c75b2e56f5484c4280fc68aef Mon Sep 17 00:00:00 2001 From: Kenneth Russel Date: Sun, 7 Jan 2007 01:40:19 +0000 Subject: 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 --- .../com/sun/opengl/util/j2d/TextRenderer.java | 14 ++++++++- .../com/sun/opengl/util/j2d/TextureRenderer.java | 35 +++++++++++++--------- 2 files changed, 34 insertions(+), 15 deletions(-) (limited to 'src/classes/com') 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(); } -- cgit v1.2.3