#version 410 uniform sampler2D fontTexture; uniform sampler2D termTexture; uniform vec2 termSize; uniform float textConsoleAlpha = 1.0; in vec3 colV; in vec2 uvV; // 0..1 across the terminal window in float alphaV; out vec4 fragColor; vec3 mf(vec3 x) { return x - floor(x); } void main (void) { vec2 uv = uvV.xy; // termTexture has the character data as ascii/255 in red, termSize grid uv.y = 1.0 - uv.y; uv *= termSize; vec2 charPart = fract(uv); uv = (floor(uv) + vec2(0.5, 0.5)) / termSize; // charF == ascii char 0x00 to 0xff. vec4 termPixel = texture(termTexture, uv); float charF = termPixel.r * 255.0; int charColorRrrGggBb = int(termPixel.g * 255); vec4 charColor = vec4(float(charColorRrrGggBb >> 5) / 7.0, float((charColorRrrGggBb >> 2) & 7) / 7.0, float(charColorRrrGggBb & 3) / 3.0, 1.0); int flags = int(termPixel.b * 255); if((flags & 2) != 0) { // double the font size (show appropriate quarter-char in this cell) uv = uvV.xy; uv.y = 1.0 - uv.y; uv *= (termSize / 2.0); charPart = fract(uv); } // let hight-bit indicate highlighting vec4 backGround = vec4(0.1, 0.1, 0.5, 0.5); // blue transparency if((flags & 1) != 0) backGround = vec4(0.6, 0.6, 0.2, 0.6); // or yellowish if high bit set // textureFont is a 16 x 6 of char pictures, 0x20..0x7f float characterColumns = 16.0; float characterRows = 64.0; float characterFirst = 0; charF -= characterFirst; float charLeft = mod(charF, characterColumns) / characterColumns; float charWidth = 1.0 / characterColumns; float charTop = floor(charF / 16.0) / characterRows; // float charTop = float(floor(charF / 16.0) - 2.0) / 6.0; // float charTop = float(floor(charF / 16.0)) / 64.0; 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); if(charF < 1.0) discard; c.a = alphaV; fragColor = c; }