mirror of
https://github.com/nunuhara/xsystem4.git
synced 2026-10-13 01:38:19 +03:00
SDL_ttf isn't really designed to be used with OpenGL. It caches glyph bitmaps in memory, whereas we want to cache glyph textures on the GPU. By using FreeType directly we avoid creating and destroying a new texture every time a glyph is rendered. Additionally, all glyph textures (including fnl-derived glyphs) now use the GL_RED internal format instead of GL_RGBA.
48 lines
1.4 KiB
GLSL
48 lines
1.4 KiB
GLSL
/* Copyright (C) 2019 Nunuhara Cabbage <nunuhara@haniwa.technology>
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program; if not, see <http://gnu.org/licenses/>.
|
|
*/
|
|
|
|
uniform sampler2D tex;
|
|
uniform float threshold;
|
|
uniform vec4 color;
|
|
|
|
in vec2 tex_coord;
|
|
out vec4 frag_color;
|
|
|
|
void main() {
|
|
// the fractional part of threshold becomes a weight value for the
|
|
// edge pixels
|
|
int size = int(floor(threshold));
|
|
int cutoff = size + 1;
|
|
float edge_weight = fract(threshold);
|
|
vec2 tex_size = textureSize(tex, 0).xy;
|
|
|
|
float a_out = 0;
|
|
|
|
for (int x = -cutoff; x <= cutoff; x++) {
|
|
for (int y = -cutoff; y <= cutoff; y++) {
|
|
float d = distance(vec2(x, y), vec2(0, 0));
|
|
if (d > threshold)
|
|
continue;
|
|
float a = texture(tex, tex_coord + vec2(x, y) / tex_size).r;
|
|
if (d > size)
|
|
a *= edge_weight;
|
|
a_out += a;
|
|
}
|
|
}
|
|
|
|
frag_color = vec4(color.rgb, min(a_out, 1.0));
|
|
}
|