TextureAttribute's combine mode

Hi!

I need to display text mapped onto shapes. I have a texture that represents the characters. This texture is of type RGBA; it is mostly transparent and the characters are painted in white.
I want to be able to paint the text with various foreground and background colors, with the same texture.
I think the TextureAttribute’s combine modes can serve this purpose, in particular the COMBINE_INTERPOLATE mode, which is defined as:
C’ = C0 C2 + C1 (1 - C2)
I could have C0 as the foreground color, C1 as the background, and C2 would be my texture’s alpha channel
The source for C0 would be the constant (texture blend) color, C1 would be the objects color.
So I wrote the following code:
TextureAttributes theTextureAttributes = new TextureAttributes ();

        theTextureAttributes.setTextureMode(TextureAttributes.COMBINE);
        theTextureAttributes.setCombineRgbMode(TextureAttributes.COMBINE_INTERPOLATE);
        
        theTextureAttributes.setCombineRgbSource(0, TextureAttributes.COMBINE_CONSTANT_COLOR);
        theTextureAttributes.setCombineRgbSource(1, TextureAttributes.COMBINE_OBJECT_COLOR);
        theTextureAttributes.setCombineRgbSource(2, TextureAttributes.COMBINE_TEXTURE_COLOR);
        
        theTextureAttributes.setCombineRgbFunction(0, TextureAttributes.COMBINE_SRC_COLOR);
        theTextureAttributes.setCombineRgbFunction(1, TextureAttributes.COMBINE_SRC_COLOR);
        theTextureAttributes.setCombineRgbFunction(2, TextureAttributes.COMBINE_SRC_ALPHA);
        
        theTextureAttributes.setTextureBlendColor(new Color4f (0f, 0f, 1f, 1f));

With this code I get the following exception:
java.lang.Error: Unrecognized combine source : 2
at com.xith3d.render.jogl.TextureShaderPeer.setCombineSource(TextureShaderPeer.java:418)
at com.xith3d.render.jogl.TextureShaderPeer.setTextureAttributes(TextureShaderPeer.java:544)
at com.xith3d.render.jogl.TextureShaderPeer.setTextureState(TextureShaderPeer.java:603)
at com.xith3d.render.jogl.TextureShaderPeer.shade(TextureShaderPeer.java:625)
at com.xith3d.render.CanvasPeerBase.setState(CanvasPeerBase.java:119)
at com.xith3d.render.CanvasPeerBase.render(CanvasPeerBase.java:98)
at com.xith3d.render.jogl.CanvasPeerImpl.drawBin(CanvasPeerImpl.java:678)
at com.xith3d.render.jogl.CanvasPeerImpl.display(CanvasPeerImpl.java:848)
at net.java.games.jogl.impl.GLDrawableHelper.display(GLDrawableHelper.java:74)
at net.java.games.jogl.GLCanvas$DisplayAction.run(GLCanvas.java:194)
at net.java.games.jogl.impl.GLContext.invokeGL(GLContext.java:192)
at net.java.games.jogl.GLCanvas.displayImpl(GLCanvas.java:182)
at net.java.games.jogl.GLCanvas.display(GLCanvas.java:82)
at com.xith3d.render.jogl.CanvasPeerImpl.render(CanvasPeerImpl.java:949)
at com.xith3d.scenegraph.View.renderOnce(View.java:735)
at com.xith3d.scenegraph.View.renderOnce(View.java:668)
at Main.main(Main.java:79)

If I invert foreground and background (-> the first source is object color), I get no exception but the only rendered color is the object’s color.

Am I doing something wrong? Is COMBINE mode fully supported?

I will check… I may not have done that mode. If not, it will be easy to add.

Okay i’ll stay tuned. I’ll be off for two weeks now anyway.

gpothier,

would be great if you can file an issue for that (simple test case will be even better).

Yuri

Done. Issue #62