[egl] alert: fix fuzzy font bug and make alerts a little more plesant

This commit is contained in:
Geoffrey McRae 2019-05-23 19:58:12 +10:00
parent ee5d6c7c3e
commit dba9764c5e
5 changed files with 23 additions and 13 deletions

View File

@ -1 +1 @@
a12-223-g1492196bbf+1 a12-224-gee5d6c7c3e+1

View File

@ -48,7 +48,8 @@ struct EGL_Alert
LG_FontBitmap * bmp; LG_FontBitmap * bmp;
bool ready; bool ready;
float width, height; float width , height ;
float bgWidth, bgHeight;
float r, g, b, a; float r, g, b, a;
// uniforms // uniforms
@ -179,8 +180,13 @@ void egl_alert_render(EGL_Alert * alert, const float scaleX, const float scaleY)
egl_texture_update(alert->texture, alert->bmp->pixels); egl_texture_update(alert->texture, alert->bmp->pixels);
alert->width = alert->bmp->width; alert->width = alert->bgWidth = alert->bmp->width;
alert->height = alert->bmp->height; alert->height = alert->bgHeight = alert->bmp->height;
if (alert->bgWidth < 200)
alert->bgWidth = 200;
alert->bgHeight += 4;
alert->ready = true; alert->ready = true;
alert->font->release(alert->fontObj, alert->bmp); alert->font->release(alert->fontObj, alert->bmp);
@ -197,15 +203,15 @@ void egl_alert_render(EGL_Alert * alert, const float scaleX, const float scaleY)
// render the background first // render the background first
egl_shader_use(alert->shaderBG); egl_shader_use(alert->shaderBG);
glUniform2f(alert->uScreenBG, scaleX , scaleY ); glUniform2f(alert->uScreenBG, scaleX , scaleY );
glUniform2f(alert->uSizeBG , alert->width, alert->height); glUniform2i(alert->uSizeBG , alert->bgWidth, alert->bgHeight);
glUniform4f(alert->uColorBG , alert->r, alert->g, alert->b, alert->a); glUniform4f(alert->uColorBG , alert->r, alert->g, alert->b, alert->a);
egl_model_render(alert->model); egl_model_render(alert->model);
// render the texture over the background // render the texture over the background
egl_shader_use(alert->shader); egl_shader_use(alert->shader);
glUniform2f(alert->uScreen, scaleX , scaleY ); glUniform2f(alert->uScreen, scaleX , scaleY );
glUniform2f(alert->uSize , alert->width, alert->height); glUniform2i(alert->uSize , alert->width, alert->height);
egl_model_render(alert->model); egl_model_render(alert->model);
glDisable(GL_BLEND); glDisable(GL_BLEND);

View File

@ -156,7 +156,7 @@ bool egl_create(void ** opaque, const LG_RendererParams params)
this->screenScaleY = 1.0f; this->screenScaleY = 1.0f;
this->font = LG_Fonts[0]; this->font = LG_Fonts[0];
if (!this->font->create(&this->fontObj, NULL, 14)) if (!this->font->create(&this->fontObj, NULL, 16))
{ {
DEBUG_ERROR("Failed to create a font instance"); DEBUG_ERROR("Failed to create a font instance");
return false; return false;

View File

@ -1,11 +1,12 @@
#version 300 es #version 300 es
in highp vec2 uv; in highp vec2 uv;
in highp vec2 sz;
out highp vec4 color; out highp vec4 color;
uniform sampler2D sampler1; uniform sampler2D sampler1;
void main() void main()
{ {
color = texture(sampler1, uv); color = texelFetch(sampler1, ivec2(uv * sz), 0);
} }

View File

@ -3,18 +3,21 @@
layout(location = 0) in vec3 vertexPosition_modelspace; layout(location = 0) in vec3 vertexPosition_modelspace;
layout(location = 1) in vec2 vertexUV; layout(location = 1) in vec2 vertexUV;
uniform vec2 screen; uniform vec2 screen;
uniform vec2 size; uniform ivec2 size;
uniform vec4 color; uniform vec4 color;
out highp vec2 uv; out highp vec2 uv;
out highp vec2 sz;
out highp vec4 c; out highp vec4 c;
void main() void main()
{ {
sz = vec2(size) + 0.5;
gl_Position.xyz = vertexPosition_modelspace; gl_Position.xyz = vertexPosition_modelspace;
gl_Position.w = 1.0; gl_Position.w = 1.0;
gl_Position.xy *= screen.xy * size.xy; gl_Position.xy *= screen.xy * sz;
uv = vertexUV; uv = vertexUV;
c = color; c = color;