mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2024-11-10 15:22:04 +00:00
Start work on outputting text.
The shaders now compile. No linking is done yet. Char quads are generated, but not sent to the card.
This commit is contained in:
parent
70abd33a25
commit
7d653f3676
4 changed files with 101 additions and 14 deletions
|
@ -34,6 +34,14 @@
|
||||||
static __attribute__ ((used)) const char rcsid[] = "$Id$";
|
static __attribute__ ((used)) const char rcsid[] = "$Id$";
|
||||||
|
|
||||||
#include "QF/draw.h"
|
#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[] =
|
static const char quaketext_vert[] =
|
||||||
#include "quaketxt.vc"
|
#include "quaketxt.vc"
|
||||||
|
@ -44,6 +52,11 @@ static const char quaketext_frag[] =
|
||||||
;
|
;
|
||||||
|
|
||||||
VISIBLE byte *draw_chars;
|
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 *
|
VISIBLE qpic_t *
|
||||||
Draw_PicFromWad (const char *name)
|
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
|
VISIBLE void
|
||||||
Draw_Init (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
|
VISIBLE void
|
||||||
|
@ -127,3 +205,9 @@ VISIBLE void
|
||||||
Draw_FadeScreen (void)
|
Draw_FadeScreen (void)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
GL_FlushText (void)
|
||||||
|
{
|
||||||
|
char_queue->size = 0;
|
||||||
|
}
|
||||||
|
|
|
@ -48,6 +48,7 @@ static __attribute__ ((used)) const char rcsid[] = "$Id$";
|
||||||
|
|
||||||
#include "QF/GL/qf_textures.h"
|
#include "QF/GL/qf_textures.h"
|
||||||
|
|
||||||
|
#include "gl_draw.h"
|
||||||
#include "r_cvar.h"
|
#include "r_cvar.h"
|
||||||
#include "r_dynamic.h"
|
#include "r_dynamic.h"
|
||||||
#include "r_screen.h"
|
#include "r_screen.h"
|
||||||
|
@ -118,6 +119,7 @@ R_ClearParticles (void)
|
||||||
VISIBLE void
|
VISIBLE void
|
||||||
SCR_UpdateScreen (double realtime, SCR_Func *scr_funcs)
|
SCR_UpdateScreen (double realtime, SCR_Func *scr_funcs)
|
||||||
{
|
{
|
||||||
|
GL_FlushText ();
|
||||||
}
|
}
|
||||||
|
|
||||||
VISIBLE void
|
VISIBLE void
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
precision mediump float;
|
//precision mediump float;
|
||||||
uniform sampler2D charmap;
|
uniform sampler2D charmap;
|
||||||
uniform sampler2D palette;
|
uniform sampler2D palette;
|
||||||
varying sv;
|
varying vec2 st;
|
||||||
|
|
||||||
void
|
void
|
||||||
main (void)
|
main (void)
|
||||||
{
|
{
|
||||||
int pix;
|
float pix;
|
||||||
|
|
||||||
pix = texture2D (charmap, sv, 0);
|
pix = texture2D (charmap, st).r;
|
||||||
gl_FragColor = texture2D (palette, vec2 (pix, 0.5), 0);
|
gl_FragColor = texture2D (palette, vec2 (pix, 0.5));
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
uniform mat4 mvp_mat;
|
||||||
/** Vertex position.
|
/** Vertex position.
|
||||||
|
|
||||||
x, y, cx, cy
|
x, y, cx, cy
|
||||||
|
@ -14,7 +15,7 @@ attribute vec4 vertex;
|
||||||
The quake character map supports only 256 characters, 0-255. Any other
|
The quake character map supports only 256 characters, 0-255. Any other
|
||||||
value will give interesting results.
|
value will give interesting results.
|
||||||
*/
|
*/
|
||||||
attribute int char;
|
attribute float char;
|
||||||
|
|
||||||
/** Coordinate in character map texture.
|
/** Coordinate in character map texture.
|
||||||
*/
|
*/
|
||||||
|
@ -23,18 +24,18 @@ varying vec2 st;
|
||||||
void
|
void
|
||||||
main (void)
|
main (void)
|
||||||
{
|
{
|
||||||
int row, col;
|
float row, col;
|
||||||
vec2 pos, corner, uv;
|
vec2 pos, corner, uv;
|
||||||
const vec2 inset = (0.25, 0.25);
|
const vec2 inset = vec2 (0.25, 0.25);
|
||||||
const vec2 size = (0.0625, 0.0625);
|
const vec2 size = vec2 (0.0625, 0.0625);
|
||||||
|
|
||||||
row = floor (char / 16);
|
row = floor (char / 16.0);
|
||||||
col = mod (char, 16);
|
col = mod (char, 16.0);
|
||||||
|
|
||||||
pos = vertex.xy;
|
pos = vertex.xy;
|
||||||
corner = vertex.zw;
|
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;
|
uv *= size;
|
||||||
gl_Position = mvp_mat * vec4 (pos + corner * 8, 0, 1);
|
gl_Position = mvp_mat * vec4 (pos + corner * 8.0, 0.0, 1.0);
|
||||||
st = uv + corner
|
st = uv + corner;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue