From d032f000a796aab8654fa13bcb84f2393f16cb65 Mon Sep 17 00:00:00 2001 From: John Tsiombikas Date: Sun, 7 Aug 2016 01:12:43 +0300 Subject: [PATCH] distance field fonts and bevel test in the font shader --- src/app.cc | 23 +++++++++++++++++------ src/fs.cc | 25 ++++++++++++++++++++++--- 2 files changed, 39 insertions(+), 9 deletions(-) diff --git a/src/app.cc b/src/app.cc index 6ed9b8e..f5b9894 100644 --- a/src/app.cc +++ b/src/app.cc @@ -26,6 +26,8 @@ static float cam_height = 1.65; static bool bnstate[16]; static int prev_x, prev_y; +static float fov = 60.0; + bool app_init(int argc, char **argv) { if(!init_options(argc, argv, "vrfileman.conf")) { @@ -120,6 +122,11 @@ void app_draw() // regular monoscopic mode glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + Mat4 mat; + mat.perspective(deg_to_rad(fov), win_aspect, 0.1, 200.0); + glMatrixMode(GL_PROJECTION); + glLoadMatrixf(mat[0]); + view_matrix = Mat4::identity; view_matrix.pre_rotate_x(deg_to_rad(cam_phi)); view_matrix.pre_rotate_y(deg_to_rad(cam_theta)); @@ -146,12 +153,6 @@ void app_reshape(int x, int y) { glViewport(0, 0, x, y); - Mat4 mat; - mat.perspective(deg_to_rad(60), win_aspect, 0.1, 200.0); - - glMatrixMode(GL_PROJECTION); - glLoadMatrixf(mat[0]); - if(opt.vr) { goatvr_set_fb_size(x, y, 1.0); } @@ -181,6 +182,16 @@ void app_keyboard(int key, bool pressed) goatvr_recenter(); } break; + + case '-': + fov += 1.0; + if(fov > 160.0) fov = 160.0; + break; + + case '=': + fov -= 1.0; + if(fov < 0.0) fov = 0.0; + break; } } } diff --git a/src/fs.cc b/src/fs.cc index d6b5eeb..57f5170 100644 --- a/src/fs.cc +++ b/src/fs.cc @@ -14,6 +14,7 @@ #include "opengl.h" #include "app.h" #include "drawtext.h" +#include "sdr.h" static IconRenderer *iconrend; @@ -23,6 +24,7 @@ static int start_child; static dtx_font *fat_font; #define FAT_FONT_SZ 32 +static unsigned int font_sdr; bool init_fs(const char *path) @@ -32,10 +34,25 @@ bool init_fs(const char *path) return false; } - if(!(fat_font = dtx_open_font("data/fat.font", FAT_FONT_SZ))) { - fprintf(stderr, "failed to open font file data/fat.font\n"); + if(!(fat_font = dtx_open_font_glyphmap("data/fat.glyphmap")) || + dtx_get_glyphmap_ptsize(dtx_get_glyphmap(fat_font, 0)) != FAT_FONT_SZ) { + + dtx_set(DTX_PADDING, 64); + + if(!(fat_font = dtx_open_font("data/fat.font", 0))) { + fprintf(stderr, "failed to open font file data/fat.font\n"); + return false; + } + dtx_prepare_range(fat_font, FAT_FONT_SZ * 8, 32, 127); + dtx_calc_font_distfield(fat_font, 1, 8); + dtx_save_glyphmap("data/fat.glyphmap", dtx_get_glyphmap(fat_font, 0)); + dtx_use_font(fat_font, FAT_FONT_SZ); + } + + if(!(font_sdr = create_program_load("sdr/dfont.v.glsl", "sdr/dfont.p.glsl"))) { return false; } + set_uniform_float(font_sdr, "smoothness", 0.01); if(!(cur_node = get_fsnode(path))) { return false; @@ -87,7 +104,6 @@ void draw_fs() base_xform.rotate(0, 0, time_sec * 0.5); base_xform.translate(0, 1.65, 0); - glUseProgram(0); glDisable(GL_TEXTURE_2D); int nchildren = (int)cur_node->children.size(); @@ -104,6 +120,8 @@ void draw_fs() continue; } + glUseProgram(0); + float angle = icon_angle(col, ncols, max_icon_angle); Mat4 xform = base_xform; @@ -123,6 +141,7 @@ void draw_fs() xform.rotate_y(angle); glMultMatrixf(xform[0]); + glUseProgram(font_sdr); dtx_string(node->path.get_name()); glPopMatrix(); -- 1.7.10.4