diff options
author | Kenneth Russel <[email protected]> | 2007-02-27 23:11:44 +0000 |
---|---|---|
committer | Kenneth Russel <[email protected]> | 2007-02-27 23:11:44 +0000 |
commit | b0ce4e37b8638b8941e8adae4fde1c0cb9a19a22 (patch) | |
tree | 94cc41ade48ee49e96317bf7a96f8c6dd0a27916 /src | |
parent | 852c2ae4d31ccab56dce74b431fcd1df02be309c (diff) |
Made disabling of the depth test optional in TextRenderer and
TextureRenderer's orthographic rendering methods based on feedback
from Dave Collins from NASA World Wind project
git-svn-id: file:///usr/local/projects/SUN/JOGL/git-svn/svn-server-sync/jogl/trunk@1160 232f8b59-042b-4e1e-8c03-345bb8c30851
Diffstat (limited to 'src')
-rwxr-xr-x | src/classes/com/sun/opengl/util/j2d/TextRenderer.java | 38 | ||||
-rwxr-xr-x | src/classes/com/sun/opengl/util/j2d/TextureRenderer.java | 37 |
2 files changed, 63 insertions, 12 deletions
diff --git a/src/classes/com/sun/opengl/util/j2d/TextRenderer.java b/src/classes/com/sun/opengl/util/j2d/TextRenderer.java index a14918583..e07935690 100755 --- a/src/classes/com/sun/opengl/util/j2d/TextRenderer.java +++ b/src/classes/com/sun/opengl/util/j2d/TextRenderer.java @@ -168,6 +168,7 @@ public class TextRenderer { private boolean isOrthoMode; private int beginRenderingWidth; private int beginRenderingHeight; + private boolean beginRenderingDepthTestDisabled; // For resetting the color after disposal of the old backing store private boolean haveCachedColor; private float cachedR; @@ -336,14 +337,36 @@ public class TextRenderer { coordinate. Binds and enables the internal OpenGL texture object, sets the texture environment mode to GL_MODULATE, and changes the current color to the last color set with this - TextRenderer via {@link #setColor setColor}. + TextRenderer via {@link #setColor setColor}. This method + disables the depth test and is equivalent to + beginRendering(width, height, true). @param width the width of the current on-screen OpenGL drawable @param height the height of the current on-screen OpenGL drawable @throws GLException If an OpenGL context is not current when this method is called */ public void beginRendering(int width, int height) throws GLException { - beginRendering(true, width, height); + beginRendering(width, height, true); + } + + /** Begins rendering with this {@link TextRenderer TextRenderer} + into the current OpenGL drawable, pushing the projection and + modelview matrices and some state bits and setting up a + two-dimensional orthographic projection with (0, 0) as the + lower-left coordinate and (width, height) as the upper-right + coordinate. Binds and enables the internal OpenGL texture + object, sets the texture environment mode to GL_MODULATE, and + changes the current color to the last color set with this + TextRenderer via {@link #setColor setColor}. Disables the depth + test if the disableDepthTest argument is true. + + @param width the width of the current on-screen OpenGL drawable + @param height the height of the current on-screen OpenGL drawable + @param disableDepthTest whether to disable the depth test + @throws GLException If an OpenGL context is not current when this method is called + */ + public void beginRendering(int width, int height, boolean disableDepthTest) throws GLException { + beginRendering(true, width, height, disableDepthTest); } /** Begins rendering of 2D text in 3D with this {@link TextRenderer @@ -359,7 +382,7 @@ public class TextRenderer { @throws GLException If an OpenGL context is not current when this method is called */ public void begin3DRendering() throws GLException { - beginRendering(false, 0, 0); + beginRendering(false, 0, 0, false); } /** Changes the current color of this TextRenderer to the supplied @@ -574,7 +597,7 @@ public class TextRenderer { return cachedGraphics; } - private void beginRendering(boolean ortho, int width, int height) { + private void beginRendering(boolean ortho, int width, int height, boolean disableDepthTestForOrtho) { if (DEBUG && !debugged) { debug(); } @@ -583,8 +606,9 @@ public class TextRenderer { isOrthoMode = ortho; beginRenderingWidth = width; beginRenderingHeight = height; + beginRenderingDepthTestDisabled = disableDepthTestForOrtho; if (ortho) { - getBackingStore().beginOrthoRendering(width, height); + getBackingStore().beginOrthoRendering(width, height, disableDepthTestForOrtho); } else { getBackingStore().begin3DRendering(); } @@ -815,7 +839,9 @@ public class TextRenderer { // Re-enter the begin / end pair if necessary if (inBeginEndPair) { if (isOrthoMode) { - ((TextureRenderer) newBackingStore).beginOrthoRendering(beginRenderingWidth, beginRenderingHeight); + ((TextureRenderer) newBackingStore).beginOrthoRendering(beginRenderingWidth, + beginRenderingHeight, + beginRenderingDepthTestDisabled); } else { ((TextureRenderer) newBackingStore).begin3DRendering(); } diff --git a/src/classes/com/sun/opengl/util/j2d/TextureRenderer.java b/src/classes/com/sun/opengl/util/j2d/TextureRenderer.java index 062717d1d..82ebdc5a1 100755 --- a/src/classes/com/sun/opengl/util/j2d/TextureRenderer.java +++ b/src/classes/com/sun/opengl/util/j2d/TextureRenderer.java @@ -287,8 +287,9 @@ public class TextureRenderer { enables the texture in this renderer; and sets up the viewing matrices for orthographic rendering where the coordinates go from (0, 0) at the lower left to (width, height) at the upper - right. {@link #endOrthoRendering} must be used in conjunction - with this method to restore all OpenGL states. + right. Equivalent to beginOrthoRendering(width, height, true). + {@link #endOrthoRendering} must be used in conjunction with this + method to restore all OpenGL states. @param width the width of the current on-screen OpenGL drawable @param height the height of the current on-screen OpenGL drawable @@ -296,7 +297,29 @@ public class TextureRenderer { @throws GLException If an OpenGL context is not current when this method is called */ public void beginOrthoRendering(int width, int height) throws GLException { - beginRendering(true, width, height); + beginOrthoRendering(width, height, true); + } + + /** Convenience method which assists in rendering portions of the + OpenGL texture to the screen, if the application intends to draw + them as a flat overlay on to the screen. Pushes OpenGL state + bits (GL_ENABLE_BIT, GL_DEPTH_BUFFER_BIT and GL_TRANSFORM_BIT); + disables the depth test (if the "disableDepthTest" argument is + true), back-face culling, and lighting; enables the texture in + this renderer; and sets up the viewing matrices for orthographic + rendering where the coordinates go from (0, 0) at the lower left + to (width, height) at the upper right. {@link + #endOrthoRendering} must be used in conjunction with this method + to restore all OpenGL states. + + @param width the width of the current on-screen OpenGL drawable + @param height the height of the current on-screen OpenGL drawable + @param disableDepthTest whether the depth test should be disabled + + @throws GLException If an OpenGL context is not current when this method is called + */ + public void beginOrthoRendering(int width, int height, boolean disableDepthTest) throws GLException { + beginRendering(true, width, height, disableDepthTest); } /** Convenience method which assists in rendering portions of the @@ -313,7 +336,7 @@ public class TextureRenderer { @throws GLException If an OpenGL context is not current when this method is called */ public void begin3DRendering() throws GLException { - beginRendering(false, 0, 0); + beginRendering(false, 0, 0, false); } /** Changes the color of the polygons, and therefore the drawn @@ -481,7 +504,7 @@ public class TextureRenderer { // Internals only below this point // - private void beginRendering(boolean ortho, int width, int height) { + private void beginRendering(boolean ortho, int width, int height, boolean disableDepthTestForOrtho) { GL gl = GLU.getCurrentGL(); int attribBits = GL.GL_ENABLE_BIT | GL.GL_TEXTURE_BIT | GL.GL_COLOR_BUFFER_BIT | @@ -489,7 +512,9 @@ public class TextureRenderer { gl.glPushAttrib(attribBits); gl.glDisable(GL.GL_LIGHTING); if (ortho) { - gl.glDisable(GL.GL_DEPTH_TEST); + if (disableDepthTestForOrtho) { + gl.glDisable(GL.GL_DEPTH_TEST); + } gl.glDisable(GL.GL_CULL_FACE); gl.glMatrixMode(GL.GL_PROJECTION); gl.glPushMatrix(); |