source: trunk/tools/neercs/video/text.lolfx @ 2090

Last change on this file since 2090 was 2090, checked in by sam, 7 years ago

neercs: added a better check for forkpty(), and moved the GL_POINTS
size and texture logic to the vertex shader.

File size: 1.9 KB
Line 
1[vert.glsl]
2
3#version 130
4
5#define HAVE_UINT 1
6
7attribute vec2 in_Position;
8#if HAVE_UINT
9attribute uint in_Char, in_Attr;
10#else
11attribute vec4 in_Char, in_Attr;
12#endif
13
14varying vec4 pass_Foreground;
15varying vec4 pass_Background;
16varying vec2 pass_UV;
17
18uniform float u_PointSize;
19uniform mat4 u_Transform;
20
21void main()
22{
23#if HAVE_UINT
24    float u = float(in_Char & 0xfu) / 32.0 + 0.0;
25    float v = float((in_Char >> 4u) & 0xfu) / 32.0 + 0.5;
26#else
27    float u = mod(in_Char.x, 16.0) / 32.0 + 0.0;
28    float v = floor(in_Char.x / 16.0) / 32.0 + 0.5;
29#endif
30    pass_UV = vec2(u, v);
31
32#if HAVE_UINT
33    float A = float(in_Attr >> 29u) / 7.0;
34    float B = float((in_Attr >> 25u) & 0xfu) / 15.0;
35    float C = float((in_Attr >> 21u) & 0xfu) / 15.0;
36    float D = float((in_Attr >> 18u) & 0x7u) / 7.0;
37
38    float E = float((in_Attr >> 15u) & 0x7u) / 7.0;
39    float F = float((in_Attr >> 11u) & 0xfu) / 15.0;
40    float G = float((in_Attr >> 7u) & 0xfu) / 15.0;
41    float H = float((in_Attr >> 4u) & 0x7u) / 7.0;
42#else
43    float A = 0.0;
44    float B = 0.0;
45    float C = 0.0;
46    float D = 0.0;
47
48    float E = 0.0;
49    float F = mod(floor(in_Attr.y / 8.0), 16.0) / 15.0;
50    float G = (mod(in_Attr.y, 8.0) * 2.0 + floor(in_Attr.x / 128.0)) / 15.0;
51    float H = mod(floor(in_Attr.x / 16.0), 8.0) / 7.0;
52#endif
53
54    pass_Background = vec4(B + 0.0625, C + 0.125, D + 0.125, 1.0 - A);
55    pass_Foreground = vec4(F, G, H, 1.0 - E);
56    if (B + C + D < 0.01) A = 1.0;
57    if (F + G + H < 0.01) E = 1.0;
58
59    // This only works with glEnable(GL_VERTEX_PROGRAM_POINT_SIZE);
60    gl_PointSize = u_PointSize;
61
62    gl_Position = u_Transform * vec4(in_Position, 0.0, 1.0);
63}
64
65[frag.glsl]
66
67#version 130
68
69varying vec4 pass_Foreground;
70varying vec4 pass_Background;
71varying vec2 pass_UV;
72
73uniform sampler2D u_Texture;
74
75void main(void)
76{
77    vec2 c = gl_PointCoord * (1.0 / 32.0) + pass_UV;
78    float t = texture2D(u_Texture, c).x;
79    gl_FragColor = mix(pass_Background, pass_Foreground, t);
80}
Note: See TracBrowser for help on using the repository browser.