Pārlūkot izejas kodu

Add textColor support for h2d.Text using alpha texture

Pascal Peridont 9 gadi atpakaļ
vecāks
revīzija
ac16fb33cd
2 mainītis faili ar 26 papildinājumiem un 0 dzēšanām
  1. 10 0
      h2d/Text.hx
  2. 16 0
      h3d/shader/WhiteAlpha.hx

+ 10 - 0
h2d/Text.hx

@@ -27,6 +27,10 @@ class Text extends Drawable {
 	var calcWidth:Int;
 	var calcHeight:Int;
 	var calcSizeHeight:Int;
+	
+	#if lime
+	var waShader : h3d.shader.WhiteAlpha;
+	#end
 
 	public function new( font : Font, ?parent ) {
 		super(parent);
@@ -41,6 +45,12 @@ class Text extends Drawable {
 	function set_font(font) {
 		if( this.font == font ) return font;
 		this.font = font;
+		#if lime
+		if( font.tile.getTexture().format == ALPHA )
+			if( waShader == null ) addShader( waShader = new h3d.shader.WhiteAlpha() );
+		else
+			if( waShader != null ) removeShader( waShader );
+		#end
 		if( glyphs != null ) glyphs.remove();
 		glyphs = new TileGroup(font == null ? null : font.tile, this);
 		glyphs.visible = false;

+ 16 - 0
h3d/shader/WhiteAlpha.hx

@@ -0,0 +1,16 @@
+package h3d.shader;
+
+class WhiteAlpha extends hxsl.Shader {
+
+	static var SRC = {
+
+		var textureColor : Vec4;
+
+		function fragment() {
+			textureColor.rgb = vec3(1.0);
+		}
+
+	};
+
+
+}