diff --git a/libs/video/renderer/glsl/Makefile.am b/libs/video/renderer/glsl/Makefile.am index 1fbcbe691..67342f345 100644 --- a/libs/video/renderer/glsl/Makefile.am +++ b/libs/video/renderer/glsl/Makefile.am @@ -2,16 +2,26 @@ AUTOMAKE_OPTIONS= foreign AM_CFLAGS= @PREFER_PIC@ INCLUDES= -I$(top_srcdir)/include $(GLX_CFLAGS) +shader_src= quaketxt.frag quaketxt.vert +shader_gen= quaketxt.fc quaketxt.vc if BUILD_GL noinst_LTLIBRARIES= libglsl.la +BUILT_SOURCES= $(shader_gen) else noinst_LTLIBRARIES= +BUILT_SOURCES= endif +SUFFICES=.frag .vert .fc .vc +.frag.fc: + sed -e 's/^/"/' -e 's/$$/\\n"/' $< > $@ +.vert.vc: + sed -e 's/^/"/' -e 's/$$/\\n"/' $< > $@ + glsl_src = \ glsl_draw.c glsl_main.c libglsl_la_SOURCES= $(glsl_src) -EXTRA_DIST = $(glsl_src) +EXTRA_DIST = $(glsl_src) $(shader_src) diff --git a/libs/video/renderer/glsl/glsl_draw.c b/libs/video/renderer/glsl/glsl_draw.c index bef15d8ef..7f7e6469a 100644 --- a/libs/video/renderer/glsl/glsl_draw.c +++ b/libs/video/renderer/glsl/glsl_draw.c @@ -35,6 +35,14 @@ static __attribute__ ((used)) const char rcsid[] = "$Id$"; #include "QF/draw.h" +static const char quaketext_vert[] = +#include "quaketxt.vc" +; + +static const char quaketext_frag[] = +#include "quaketxt.fc" +; + VISIBLE byte *draw_chars; VISIBLE qpic_t * diff --git a/libs/video/renderer/glsl/quaketxt.frag b/libs/video/renderer/glsl/quaketxt.frag new file mode 100644 index 000000000..00dd1c5e0 --- /dev/null +++ b/libs/video/renderer/glsl/quaketxt.frag @@ -0,0 +1,13 @@ +precision mediump float; +uniform sampler2D charmap; +uniform sampler2D palette; +varying sv; + +void +main (void) +{ + int pix; + + pix = texture2D (charmap, sv, 0); + gl_FragColor = texture2D (palette, vec2 (pix, 0.5), 0); +} diff --git a/libs/video/renderer/glsl/quaketxt.vert b/libs/video/renderer/glsl/quaketxt.vert new file mode 100644 index 000000000..fc46a632a --- /dev/null +++ b/libs/video/renderer/glsl/quaketxt.vert @@ -0,0 +1,40 @@ +/** Vertex position. + + x, y, cx, cy + + \a vertex provides the onscreen location at which to draw the character + (\a x, \a y) and which corner of the character cell this vertex + represents (\a cx, \a cy). \a cx and \a cy must be either 0 or 1, or + wierd things will happen with the character cell. +*/ +attribute vec4 vertex; + +/** The character to draw. + + The quake character map supports only 256 characters, 0-255. Any other + value will give interesting results. +*/ +attribute int char; + +/** Coordinate in character map texture. +*/ +varying vec2 st; + +void +main (void) +{ + int row, col; + vec2 pos, corner, uv; + const vec2 inset = (0.25, 0.25); + const vec2 size = (0.0625, 0.0625); + + row = floor (char / 16); + col = mod (char, 16); + + pos = vertex.xy; + corner = vertex.zw; + uv = vec2 (row, col) + inset * (1 - 2 * corner) + 8 * corner; + uv *= size; + gl_Position = mvp_mat * vec4 (pos + corner * 8, 0, 1); + st = uv + corner +}