aboutsummaryrefslogtreecommitdiffstats
path: root/src/classes/com/sun
diff options
context:
space:
mode:
authorKenneth Russel <kbrussel@alum.mit.edu>2007-02-20 04:48:56 +0000
committerKenneth Russel <kbrussel@alum.mit.edu>2007-02-20 04:48:56 +0000
commitdeb9de3d099d492fd138c93894b8e69655668a9d (patch)
tree0d063d8b407f75a50c72fa148bc7348a10d2ffe6 /src/classes/com/sun
parent090105f0869fc5e5e8c70c05e582576073684e1a (diff)
Fixed Issue 272: Move setColor method from TextRenderer up to TextureRenderer
Moved setColor() implementation from TextRenderer to TextureRenderer and reimplemented TextRenderer's methods in terms of it. git-svn-id: file:///usr/local/projects/SUN/JOGL/git-svn/svn-server-sync/jogl/trunk@1143 232f8b59-042b-4e1e-8c03-345bb8c30851
Diffstat (limited to 'src/classes/com/sun')
-rwxr-xr-xsrc/classes/com/sun/opengl/util/j2d/TextRenderer.java31
-rwxr-xr-xsrc/classes/com/sun/opengl/util/j2d/TextureRenderer.java61
2 files changed, 64 insertions, 28 deletions
diff --git a/src/classes/com/sun/opengl/util/j2d/TextRenderer.java b/src/classes/com/sun/opengl/util/j2d/TextRenderer.java
index c4d2ee6df..88b8301dc 100755
--- a/src/classes/com/sun/opengl/util/j2d/TextRenderer.java
+++ b/src/classes/com/sun/opengl/util/j2d/TextRenderer.java
@@ -132,12 +132,6 @@ public class TextRenderer {
// force a compaction
private static final float MAX_VERTICAL_FRAGMENTATION = 0.7f;
- // Current text color
- private float r = 1.0f;
- private float g = 1.0f;
- private float b = 1.0f;
- private float a = 1.0f;
-
// Data associated with each rectangle of text
static class TextData {
private String str; // Back-pointer to String this TextData describes
@@ -343,7 +337,6 @@ public class TextRenderer {
beginRendering(false, 0, 0);
}
- private float[] compArray;
/** Changes the current color of this TextRenderer to the supplied
one. The default color is opaque white.
@@ -351,12 +344,7 @@ public class TextRenderer {
@throws GLException If an OpenGL context is not current when this method is called
*/
public void setColor(Color color) throws GLException {
- // Get color's RGBA components as floats in the range [0,1].
- if (compArray == null) {
- compArray = new float[4];
- }
- color.getRGBComponents(compArray);
- setColor(compArray[0], compArray[1], compArray[2], compArray[3]);
+ getBackingStore().setColor(color);
}
/** Changes the current color of this TextRenderer to the supplied
@@ -370,18 +358,12 @@ public class TextRenderer {
@param r the red component of the new color
@param g the green component of the new color
@param b the blue component of the new color
- @param alpha the alpha component of the new color, 0.0f =
- completely transparent, 1.0f = completely opaque
+ @param a the alpha component of the new color, 0.0f = completely
+ transparent, 1.0f = completely opaque
@throws GLException If an OpenGL context is not current when this method is called
*/
public void setColor(float r, float g, float b, float a) throws GLException {
- GL gl = GLU.getCurrentGL();
- this.r = r * a;
- this.g = g * a;
- this.b = b * a;
- this.a = a;
-
- gl.glColor4f(this.r, this.g, this.b, this.a);
+ getBackingStore().setColor(r, g, b, a);
}
/** Draws the supplied String at the desired location using the
@@ -576,11 +558,6 @@ public class TextRenderer {
packer.setMaxSize(sz[0], sz[0]);
haveMaxSize = true;
}
-
- // Change texture environment mode to MODULATE
- gl.glTexEnvi(GL.GL_TEXTURE_ENV, GL.GL_TEXTURE_ENV_MODE, GL.GL_MODULATE);
- // Change text color to last saved
- gl.glColor4f(r, g, b, a);
}
private void endRendering(boolean ortho) throws GLException {
diff --git a/src/classes/com/sun/opengl/util/j2d/TextureRenderer.java b/src/classes/com/sun/opengl/util/j2d/TextureRenderer.java
index 77ad92184..062717d1d 100755
--- a/src/classes/com/sun/opengl/util/j2d/TextureRenderer.java
+++ b/src/classes/com/sun/opengl/util/j2d/TextureRenderer.java
@@ -39,6 +39,7 @@
package com.sun.opengl.util.j2d;
+import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics2D;
import java.awt.Image;
@@ -85,6 +86,12 @@ public class TextureRenderer {
private GLU glu = new GLU();
+ // Current color
+ private float r = 1.0f;
+ private float g = 1.0f;
+ private float b = 1.0f;
+ private float a = 1.0f;
+
/** Creates a new renderer with backing store of the specified width
and height. If alpha is true, allocates an alpha channel in the
backing store image.
@@ -309,6 +316,56 @@ public class TextureRenderer {
beginRendering(false, 0, 0);
}
+ /** Changes the color of the polygons, and therefore the drawn
+ images, this TextureRenderer produces. Use of this method is
+ optional. The TextureRenderer uses the GL_MODULATE texture
+ environment mode, which causes the portions of the rendered
+ texture to be multiplied by the color of the rendered
+ polygons. The polygon color can be varied to achieve effects
+ like tinting of the overall output or fading in and out by
+ changing the alpha of the color. <P>
+
+ Each component ranges from 0.0f - 1.0f. The alpha component, if
+ used, does not need to be premultiplied into the color channels
+ as described in the documentation for {@link
+ com.sun.opengl.util.texture.Texture Texture}, although
+ premultiplied colors are used internally. The default color is
+ opaque white.
+
+ @param r the red component of the new color
+ @param g the green component of the new color
+ @param b the blue component of the new color
+ @param a the alpha component of the new color, 0.0f = completely
+ transparent, 1.0f = completely opaque
+ @throws GLException If an OpenGL context is not current when this method is called
+ */
+ public void setColor(float r, float g, float b, float a) throws GLException {
+ GL gl = GLU.getCurrentGL();
+ this.r = r * a;
+ this.g = g * a;
+ this.b = b * a;
+ this.a = a;
+
+ gl.glColor4f(this.r, this.g, this.b, this.a);
+ }
+
+ private float[] compArray;
+ /** Changes the current color of this TextureRenderer to the
+ supplied one. The default color is opaque white. See {@link
+ #setColor(float,float,float,float) setColor} for more details.
+
+ @param color the new color to use for rendering
+ @throws GLException If an OpenGL context is not current when this method is called
+ */
+ public void setColor(Color color) throws GLException {
+ // Get color's RGBA components as floats in the range [0,1].
+ if (compArray == null) {
+ compArray = new float[4];
+ }
+ color.getRGBComponents(compArray);
+ setColor(compArray[0], compArray[1], compArray[2], compArray[3]);
+ }
+
/** Draws an orthographically projected rectangle containing all of
the underlying texture to the specified location on the
screen. All (x, y) coordinates are specified relative to the
@@ -450,7 +507,9 @@ public class TextureRenderer {
Texture texture = getTexture();
texture.enable();
texture.bind();
- gl.glTexEnvi(GL.GL_TEXTURE_ENV, GL.GL_TEXTURE_ENV_MODE, GL.GL_REPLACE);
+ gl.glTexEnvi(GL.GL_TEXTURE_ENV, GL.GL_TEXTURE_ENV_MODE, GL.GL_MODULATE);
+ // Change polygon color to last saved
+ gl.glColor4f(r, g, b, a);
if (smoothingChanged) {
smoothingChanged = false;
if (smoothing) {