graphics

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

commit 08888d85f037d7bfe0d64c3130ecb8c336531cd5
parent 8485186a28217f2b38b2fd849ef5e0d09136f09d
Author: Brian Swetland <swetland@frotz.net>
Date:   Sat, 22 Jun 2013 23:05:57 -0700

texturefont: fix texture coordinates

Diffstat:
Mcommon/assets/texturefont.glsl | 17++++++++++-------
Mcommon/texturefont.cc | 4+++-
Mcommon/texturefont.h | 1+
3 files changed, 14 insertions(+), 8 deletions(-)

diff --git a/common/assets/texturefont.glsl b/common/assets/texturefont.glsl @@ -3,6 +3,7 @@ layout(std140) uniform udata0 { mat4 MVP; + vec2 adj; float dim; }; @@ -37,24 +38,26 @@ out vec4 color; void main() { vec4 p = gl_in[0].gl_Position; + vec2 sz = size[0]; + vec2 tsz = sz - vec2(1.0,1.0); - gl_Position = MVP * vec4(p.x, p.y - size[0].y, 0.0, 1.0); - s0tc = tex[0] / dim; + gl_Position = MVP * vec4(p.x, p.y - sz.y, 0.0, 1.0); + s0tc = tex[0] / dim + adj; color = vcolor[0]; EmitVertex(); - gl_Position = MVP * vec4(p.x + size[0].x, p.y - size[0].y, 0.0, 1.0); - s0tc = (tex[0] + vec2(size[0].x,0)) / dim; + gl_Position = MVP * vec4(p.x + sz.x, p.y - sz.y, 0.0, 1.0); + s0tc = (tex[0] + vec2(tsz.x,0)) / dim + adj; color = vcolor[0]; EmitVertex(); gl_Position = MVP * vec4(p.x, p.y, 0.0, 1.0); - s0tc = (tex[0] + vec2(0,size[0].y)) / dim; + s0tc = (tex[0] + vec2(0,tsz.y)) / dim + adj; color = vcolor[0]; EmitVertex(); - gl_Position = MVP * vec4(p.x + size[0].x, p.y, 0.0, 1.0); - s0tc = (tex[0] + size[0]) / dim; + gl_Position = MVP * vec4(p.x + sz.x, p.y, 0.0, 1.0); + s0tc = (tex[0] + tsz) / dim + adj; color = vcolor[0]; EmitVertex(); diff --git a/common/texturefont.cc b/common/texturefont.cc @@ -67,8 +67,10 @@ int TextureFont::init(App *app, const char *fontname) { if (pgm.load("texturefont.vs", "texturefont.gs", "texturefont.fs")) goto fail; - u.mvp.setOrtho(0, app->getWidth() - 1, app->getHeight() - 1, 0, -1, 1); + u.mvp.setOrtho(0, app->getWidth(), app->getHeight(), 0, -1, 1); u.dim = glyphs.width; + u.adj[0] = 0.5 / float(glyphs.width); + u.adj[1] = 0.5 / float(glyphs.width); vtx.load(data, sizeof(CharData) * max); ubuf.load(&u, sizeof(u)); diff --git a/common/texturefont.h b/common/texturefont.h @@ -65,6 +65,7 @@ private: struct { mat4 mvp; + float adj[2]; float dim; } u;