diff --git a/libs/video/renderer/glsl/glsl_draw.c b/libs/video/renderer/glsl/glsl_draw.c index 7f7e6469a..d829bb49e 100644 --- a/libs/video/renderer/glsl/glsl_draw.c +++ b/libs/video/renderer/glsl/glsl_draw.c @@ -34,6 +34,14 @@ static __attribute__ ((used)) const char rcsid[] = "$Id$"; #include "QF/draw.h" +#include "QF/dstring.h" +#include "QF/sys.h" + +#include "QF/GL/defines.h" +#include "QF/GL/funcs.h" +#include "QF/GL/qf_textures.h" + +#include "gl_draw.h" static const char quaketext_vert[] = #include "quaketxt.vc" @@ -44,6 +52,11 @@ static const char quaketext_frag[] = ; VISIBLE byte *draw_chars; +static dstring_t *char_queue; +static int char_texture; +static int qtxt_vert; +static int qtxt_frag; +//static int qtxt_prog; VISIBLE qpic_t * Draw_PicFromWad (const char *name) @@ -62,9 +75,74 @@ Draw_TextBox (int x, int y, int width, int lines, byte alpha) { } +static int +compile_shader (const char *name, const char *shader_src, int type) +{ + const char *src[1]; + int shader; + int compiled; + + src[0] = shader_src; + shader = qfglCreateShader (type); + qfglShaderSource (shader, 1, src, 0); + qfglCompileShader (shader); + qfglGetShaderiv (shader, GL_COMPILE_STATUS, &compiled); + if (!compiled) { + dstring_t *log = dstring_new (); + int size; + qfglGetShaderiv (shader, GL_INFO_LOG_LENGTH, &size); + log->size = size + 1; // for terminating null + dstring_adjust (log); + qfglGetShaderInfoLog (shader, log->size, 0, log->str); + qfglDeleteShader (shader); + Sys_Printf ("Shader (%s) compile error:\n----8<----\n%s----8<----\n", + name, log->str); + dstring_delete (log); + return 0; + } + return shader; +} + VISIBLE void Draw_Init (void) { + GLuint tnum; + int i; + + char_queue = dstring_new (); + qtxt_vert = compile_shader ("quaketxt.vert", quaketext_vert, + GL_VERTEX_SHADER); + qtxt_frag = compile_shader ("quaketxt.frag", quaketext_frag, + GL_FRAGMENT_SHADER); + + draw_chars = W_GetLumpName ("conchars"); + for (i = 0; i < 256 * 64; i++) + if (draw_chars[i] == 0) + draw_chars[i] = 255; // proper transparent color + + qfglGenTextures (1, &tnum); + char_texture = tnum; + qfglBindTexture (GL_TEXTURE_2D, char_texture); + qfglTexImage2D (GL_TEXTURE_2D, 0, GL_LUMINANCE, + 128, 128, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, draw_chars); +} + +static inline void +queue_character (int x, int y, byte chr) +{ + byte *v; + int i; + + char_queue->size += 5; + dstring_adjust (char_queue); + v = (byte *) char_queue->str + char_queue->size - 5; + for (i = 0; i < 4; i++) { + *v++ = x; + *v++ = y; + *v++ = i & 1; + *v++ = (i >> 1) & 1; + *v++ = chr; + } } VISIBLE void @@ -127,3 +205,9 @@ VISIBLE void Draw_FadeScreen (void) { } + +void +GL_FlushText (void) +{ + char_queue->size = 0; +} diff --git a/libs/video/renderer/glsl/glsl_main.c b/libs/video/renderer/glsl/glsl_main.c index 21c62d49b..ef2793652 100644 --- a/libs/video/renderer/glsl/glsl_main.c +++ b/libs/video/renderer/glsl/glsl_main.c @@ -48,6 +48,7 @@ static __attribute__ ((used)) const char rcsid[] = "$Id$"; #include "QF/GL/qf_textures.h" +#include "gl_draw.h" #include "r_cvar.h" #include "r_dynamic.h" #include "r_screen.h" @@ -118,6 +119,7 @@ R_ClearParticles (void) VISIBLE void SCR_UpdateScreen (double realtime, SCR_Func *scr_funcs) { + GL_FlushText (); } VISIBLE void diff --git a/libs/video/renderer/glsl/quaketxt.frag b/libs/video/renderer/glsl/quaketxt.frag index 00dd1c5e0..d80ed0858 100644 --- a/libs/video/renderer/glsl/quaketxt.frag +++ b/libs/video/renderer/glsl/quaketxt.frag @@ -1,13 +1,13 @@ -precision mediump float; +//precision mediump float; uniform sampler2D charmap; uniform sampler2D palette; -varying sv; +varying vec2 st; void main (void) { - int pix; + float pix; - pix = texture2D (charmap, sv, 0); - gl_FragColor = texture2D (palette, vec2 (pix, 0.5), 0); + pix = texture2D (charmap, st).r; + gl_FragColor = texture2D (palette, vec2 (pix, 0.5)); } diff --git a/libs/video/renderer/glsl/quaketxt.vert b/libs/video/renderer/glsl/quaketxt.vert index fc46a632a..dfa90f59b 100644 --- a/libs/video/renderer/glsl/quaketxt.vert +++ b/libs/video/renderer/glsl/quaketxt.vert @@ -1,3 +1,4 @@ +uniform mat4 mvp_mat; /** Vertex position. x, y, cx, cy @@ -14,7 +15,7 @@ attribute vec4 vertex; The quake character map supports only 256 characters, 0-255. Any other value will give interesting results. */ -attribute int char; +attribute float char; /** Coordinate in character map texture. */ @@ -23,18 +24,18 @@ varying vec2 st; void main (void) { - int row, col; + float row, col; vec2 pos, corner, uv; - const vec2 inset = (0.25, 0.25); - const vec2 size = (0.0625, 0.0625); + const vec2 inset = vec2 (0.25, 0.25); + const vec2 size = vec2 (0.0625, 0.0625); - row = floor (char / 16); - col = mod (char, 16); + row = floor (char / 16.0); + col = mod (char, 16.0); pos = vertex.xy; corner = vertex.zw; - uv = vec2 (row, col) + inset * (1 - 2 * corner) + 8 * corner; + uv = vec2 (row, col) + inset * (1.0 - 2.0 * corner) + 8.0 * corner; uv *= size; - gl_Position = mvp_mat * vec4 (pos + corner * 8, 0, 1); - st = uv + corner + gl_Position = mvp_mat * vec4 (pos + corner * 8.0, 0.0, 1.0); + st = uv + corner; }