Get text rendering working.

It comes out as a funky green (that's not in the quake palette!!!), but
it's mostly readable.
This commit is contained in:
Bill Currie 2011-12-26 10:16:16 +09:00
parent 4131a5998c
commit 7bd5ab882c
5 changed files with 24 additions and 6 deletions

View file

@ -190,13 +190,18 @@ Draw_Init (void)
qfglBindTexture (GL_TEXTURE_2D, char_texture);
qfglTexImage2D (GL_TEXTURE_2D, 0, GL_LUMINANCE,
128, 128, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, draw_chars);
qfglTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
qfglTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
qfglTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
qfglTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
qfglGenerateMipmap (GL_TEXTURE_2D);
}
static inline void
queue_character (int x, int y, byte chr)
{
unsigned short *v;
int i;
unsigned i, c;
const int size = 5 * 2 * 4;
char_queue->size += size;
@ -205,8 +210,9 @@ queue_character (int x, int y, byte chr)
for (i = 0; i < 4; i++) {
*v++ = x;
*v++ = y;
*v++ = i & 1;
*v++ = (i >> 1) & 1;
c = i ^ (i >> 1);
*v++ = c & 1;
*v++ = (c >> 1) & 1;
*v++ = chr;
}
}
@ -219,12 +225,15 @@ flush_text (void)
qfglEnableVertexAttribArray (dchar.location);
qfglUniformMatrix4fv (matrix.location, 1, false, proj_matrix);
qfglUniform1i (charmap.location, 0);
qfglActiveTexture(GL_TEXTURE0 + 0);
qfglEnable (GL_TEXTURE_2D);
qfglBindTexture(GL_TEXTURE_2D, char_texture);
qfglUniform1i (palette.location, 1);
qfglActiveTexture(GL_TEXTURE0 + 1);
qfglEnable (GL_TEXTURE_2D);
qfglBindTexture(GL_TEXTURE_2D, glsl_palette);
qfglVertexAttribPointer (vertex.location, 4, GL_UNSIGNED_SHORT, 0, 10,

View file

@ -101,6 +101,8 @@ SCR_UpdateScreen (double realtime, SCR_Func *scr_funcs)
if (!scr_initialized)
return;
qfglClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
begun = 1;
if (oldfov != scr_fov->value) {

View file

@ -9,5 +9,7 @@ main (void)
float pix;
pix = texture2D (charmap, st).r;
if (pix == 1.0)
discard;
gl_FragColor = texture2D (palette, vec2 (pix, 0.5));
}

View file

@ -26,7 +26,7 @@ main (void)
{
float row, col;
vec2 pos, corner, uv;
const vec2 inset = vec2 (0.25, 0.25);
const vec2 inset = vec2 (0.03125, 0.03125);
const vec2 size = vec2 (0.0625, 0.0625);
row = floor (char / 16.0);
@ -34,8 +34,8 @@ main (void)
pos = vertex.xy;
corner = vertex.zw;
uv = vec2 (row, col) + inset * (1.0 - 2.0 * corner) + 8.0 * corner;
uv = vec2 (col, row) + inset * (1.0 - 2.0 * corner) + corner;
uv *= size;
gl_Position = mvp_mat * vec4 (pos + corner * 8.0, 0.0, 1.0);
st = uv + corner;
st = uv;
}

View file

@ -113,6 +113,11 @@ VID_SetPalette (unsigned char *palette)
qfglBindTexture (GL_TEXTURE_2D, glsl_palette);
qfglTexImage2D (GL_TEXTURE_2D, 0, GL_RGBA, 256, 1, 0,
GL_RGBA, GL_UNSIGNED_BYTE, pal);
qfglTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
qfglTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
qfglTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
qfglTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
qfglGenerateMipmap (GL_TEXTURE_2D);
free (pal);
}