#version 410 uniform sampler2D fontTexture; uniform sampler2D atlasTexture; uniform vec2 atlasSize; in vec4 colorV; in vec4 highlightColorV; in vec2 textureUvV; // 0..1 across the terminal window out vec4 fragColor; vec3 mf(vec3 x) { return x - floor(x); } void main (void) { fragColor = vec4(1,1,1,1); // return; vec2 uv = textureUvV.xy; // atlasTexture has the character data as ascii/255 in red, atlasSize grid // uv.y = 1.0 - uv.y; uv *= atlasSize; vec2 charPart = fract(uv); uv = (floor(uv) + vec2(0.5, 0.5)) / atlasSize; // charF == ascii char 0x00 to 0xff. vec4 termPixel = texture(atlasTexture, uv); int byteR = int(termPixel.r * 255.0); int byteG = int(termPixel.g * 255.0); int byteB = int(termPixel.b * 255.0); int byteA = int(termPixel.a * 255.0); float charF = 256 * byteG + byteR; int charColorRrrGggBb = byteA; int flags = byteB; vec4 charColor = vec4(float(charColorRrrGggBb >> 5) / 7.0, float((charColorRrrGggBb >> 2) & 7) / 7.0, float(charColorRrrGggBb & 3) / 3.0, 1.0); if((flags & 2) != 0) { // double the font size (show appropriate quarter-char in this cell) uv = textureUvV.xy; //uv.y = 1.0 - uv.y; uv *= (atlasSize / 2.0); charPart = fract(uv); // TODO: Understand why this hack? I added it on 2016-11-04 but not sure why it became relevant. It makes no sense. // Saw bug with half-split big chars. Swapped the left-right halves. charPart.x = fract(charPart.x + 0.5); } // let bit indicate highlighting vec4 backGround = colorV; // blue transparency if((flags & 1) != 0) backGround = highlightColorV; // or yellowish if high bit set // textureFont is a 16 x 64 of char pictures, 0x00..0xff four times. float characterColumns = 32.0; float characterRows = 32.0; float characterFirst = 0; charF -= characterFirst; if(charF < 1.0) discard; float charLeft = mod(charF, characterColumns) / characterColumns; float charWidth = 1.0 / characterColumns; float charTop = floor(charF / characterColumns) / characterRows; float charHeight = 1.0 / characterRows; charPart = clamp(charPart, 1.0/16.0, 15.0/16.0); vec2 charSpot = vec2(charLeft, charTop) + charPart * vec2(charWidth, charHeight); float charVal = texture(fontTexture, charSpot).r; // pixel from character charVal = pow(charVal, 0.25); vec4 c = vec4(charVal, charVal, charVal, charVal); // color is white, premul c *= charColor; // c = max(c, backGround); c = mix(backGround, c, charVal); c.a = 1.0; c.a = colorV.a; fragColor = c; }