mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2025-01-18 15:01:41 +00:00
Add support for vertex colors.
As I need to control the alpha, they're sent as rgba rather than quake palette indices. Text works well. All other 2d stuff does not :(.
This commit is contained in:
parent
b96ca6f0e0
commit
151cc05882
6 changed files with 49 additions and 10 deletions
|
@ -1,3 +1,5 @@
|
|||
#include "QF/mathlib.h"
|
||||
|
||||
extern struct cvar_s *easter_eggs;
|
||||
extern void r_easter_eggs_f (struct cvar_s *var);
|
||||
extern void r_particles_style_f (struct cvar_s *var);
|
||||
|
@ -9,6 +11,7 @@ extern struct cvar_s *cl_crossy;
|
|||
extern struct cvar_s *cl_verstring;
|
||||
extern struct cvar_s *crosshair;
|
||||
extern struct cvar_s *crosshaircolor;
|
||||
extern quat_t crosshair_color;
|
||||
|
||||
extern struct cvar_s *d_mipcap;
|
||||
extern struct cvar_s *d_mipscale;
|
||||
|
|
|
@ -82,6 +82,7 @@ static struct {
|
|||
shaderparam_t palette;
|
||||
shaderparam_t matrix;
|
||||
shaderparam_t vertex;
|
||||
shaderparam_t color;
|
||||
shaderparam_t dchar;
|
||||
} quake_text = {
|
||||
0,
|
||||
|
@ -89,6 +90,7 @@ static struct {
|
|||
{"palette", 1},
|
||||
{"mvp_mat", 1},
|
||||
{"vertex", 0},
|
||||
{"vcolor", 0},
|
||||
{"char", 0},
|
||||
};
|
||||
|
||||
|
@ -98,12 +100,14 @@ static struct {
|
|||
shaderparam_t palette;
|
||||
shaderparam_t matrix;
|
||||
shaderparam_t vertex;
|
||||
shaderparam_t color;
|
||||
} quake_icon = {
|
||||
0,
|
||||
{"texture", 1},
|
||||
{"palette", 1},
|
||||
{"mvp_mat", 1},
|
||||
{"vertex", 0},
|
||||
{"vcolor", 0},
|
||||
};
|
||||
|
||||
VISIBLE byte *draw_chars;
|
||||
|
@ -171,7 +175,8 @@ make_quad (qpic_t *pic, int x, int y, int srcx, int srcy,
|
|||
}
|
||||
|
||||
static void
|
||||
draw_pic (int x, int y, qpic_t *pic, int srcx, int srcy, int width, int height)
|
||||
draw_pic (int x, int y, qpic_t *pic, int srcx, int srcy, int width, int height,
|
||||
float *color)
|
||||
{
|
||||
glpic_t *gl;
|
||||
float verts[6][4];
|
||||
|
@ -194,6 +199,8 @@ draw_pic (int x, int y, qpic_t *pic, int srcx, int srcy, int width, int height)
|
|||
qfglEnable (GL_TEXTURE_2D);
|
||||
qfglBindTexture (GL_TEXTURE_2D, glsl_palette);
|
||||
|
||||
qfglVertexAttrib4fv (quake_icon.color.location, color);
|
||||
|
||||
qfglVertexAttribPointer (quake_icon.vertex.location, 4, GL_FLOAT,
|
||||
0, 0, verts);
|
||||
|
||||
|
@ -245,6 +252,7 @@ Draw_Init (void)
|
|||
GL_ResolveShaderParam (quake_text.program, &quake_text.palette);
|
||||
GL_ResolveShaderParam (quake_text.program, &quake_text.matrix);
|
||||
GL_ResolveShaderParam (quake_text.program, &quake_text.vertex);
|
||||
GL_ResolveShaderParam (quake_text.program, &quake_text.color);
|
||||
GL_ResolveShaderParam (quake_text.program, &quake_text.dchar);
|
||||
|
||||
vert = GL_CompileShader ("quakeico.vert", quakeicon_vert, GL_VERTEX_SHADER);
|
||||
|
@ -253,6 +261,7 @@ Draw_Init (void)
|
|||
GL_ResolveShaderParam (quake_icon.program, &quake_icon.palette);
|
||||
GL_ResolveShaderParam (quake_icon.program, &quake_icon.matrix);
|
||||
GL_ResolveShaderParam (quake_icon.program, &quake_icon.vertex);
|
||||
GL_ResolveShaderParam (quake_icon.program, &quake_icon.color);
|
||||
|
||||
draw_chars = W_GetLumpName ("conchars");
|
||||
for (i = 0; i < 256 * 64; i++)
|
||||
|
@ -314,6 +323,8 @@ flush_text (void)
|
|||
qfglEnable (GL_TEXTURE_2D);
|
||||
qfglBindTexture (GL_TEXTURE_2D, glsl_palette);
|
||||
|
||||
qfglVertexAttrib4f (quake_text.color.location, 1, 1, 1, 1);
|
||||
|
||||
qfglVertexAttribPointer (quake_text.vertex.location, 4, GL_UNSIGNED_SHORT,
|
||||
0, 10, char_queue->str);
|
||||
qfglVertexAttribPointer (quake_text.dchar.location, 1, GL_UNSIGNED_SHORT,
|
||||
|
@ -402,7 +413,7 @@ static void
|
|||
crosshair_2 (int x, int y)
|
||||
{
|
||||
draw_pic (x, y, crosshair_pic,
|
||||
0, 0, CROSSHAIR_WIDTH, CROSSHAIR_HEIGHT);
|
||||
0, 0, CROSSHAIR_WIDTH, CROSSHAIR_HEIGHT, crosshair_color);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -410,7 +421,7 @@ crosshair_3 (int x, int y)
|
|||
{
|
||||
draw_pic (x, y, crosshair_pic,
|
||||
CROSSHAIR_WIDTH, 0,
|
||||
CROSSHAIR_WIDTH, CROSSHAIR_HEIGHT);
|
||||
CROSSHAIR_WIDTH, CROSSHAIR_HEIGHT, crosshair_color);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -418,7 +429,7 @@ crosshair_4 (int x, int y)
|
|||
{
|
||||
draw_pic (x, y, crosshair_pic,
|
||||
0, CROSSHAIR_HEIGHT,
|
||||
CROSSHAIR_WIDTH, CROSSHAIR_HEIGHT);
|
||||
CROSSHAIR_WIDTH, CROSSHAIR_HEIGHT, crosshair_color);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -426,7 +437,7 @@ crosshair_5 (int x, int y)
|
|||
{
|
||||
draw_pic (x, y, crosshair_pic,
|
||||
CROSSHAIR_WIDTH, CROSSHAIR_HEIGHT,
|
||||
CROSSHAIR_WIDTH, CROSSHAIR_HEIGHT);
|
||||
CROSSHAIR_WIDTH, CROSSHAIR_HEIGHT, crosshair_color);
|
||||
}
|
||||
|
||||
static void (*crosshair_func[]) (int x, int y) = {
|
||||
|
@ -467,14 +478,16 @@ Draw_CrosshairAt (int ch, int x, int y)
|
|||
VISIBLE void
|
||||
Draw_Pic (int x, int y, qpic_t *pic)
|
||||
{
|
||||
draw_pic (x, y, pic, 0, 0, pic->width, pic->height);
|
||||
static quat_t color = { 1, 1, 1, 1};
|
||||
draw_pic (x, y, pic, 0, 0, pic->width, pic->height, color);
|
||||
}
|
||||
|
||||
VISIBLE void
|
||||
Draw_SubPic (int x, int y, qpic_t *pic, int srcx, int srcy, int width,
|
||||
int height)
|
||||
{
|
||||
draw_pic (x, y, pic, srcx, srcy, width, height);
|
||||
static quat_t color = { 1, 1, 1, 1};
|
||||
draw_pic (x, y, pic, srcx, srcy, width, height, color);
|
||||
}
|
||||
|
||||
VISIBLE void
|
||||
|
@ -505,6 +518,9 @@ Draw_ConsoleBackground (int lines, byte alpha)
|
|||
qfglEnable (GL_TEXTURE_2D);
|
||||
qfglBindTexture (GL_TEXTURE_2D, glsl_palette);
|
||||
|
||||
qfglVertexAttrib4f (quake_icon.color.location,
|
||||
1, 1, 1, bound (0, alpha, 255) / 255.0);
|
||||
|
||||
qfglVertexAttribPointer (quake_icon.vertex.location, 4, GL_FLOAT,
|
||||
0, 0, verts);
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
//precision mediump float;
|
||||
uniform sampler2D texture;
|
||||
uniform sampler2D palette;
|
||||
varying vec4 color;
|
||||
varying vec2 st;
|
||||
|
||||
void
|
||||
|
@ -11,5 +12,5 @@ main (void)
|
|||
pix = texture2D (texture, st).r;
|
||||
if (pix == 1.0)
|
||||
discard;
|
||||
gl_FragColor = texture2D (palette, vec2 (pix, 0.5));
|
||||
gl_FragColor = texture2D (palette, vec2 (pix, 0.5)) * color;
|
||||
}
|
||||
|
|
|
@ -7,7 +7,9 @@ uniform mat4 mvp_mat;
|
|||
(\a x, \a y) and texture coordinate for the icon (\a s=z, \a t=w).
|
||||
*/
|
||||
attribute vec4 vertex;
|
||||
attribute vec4 vcolor;
|
||||
|
||||
varying vec4 color;
|
||||
varying vec2 st;
|
||||
|
||||
void
|
||||
|
@ -15,4 +17,5 @@ main (void)
|
|||
{
|
||||
gl_Position = mvp_mat * vec4 (vertex.xy, 0.0, 1.0);
|
||||
st = vertex.zw;
|
||||
color = vcolor;
|
||||
}
|
||||
|
|
|
@ -10,6 +10,12 @@ uniform mat4 mvp_mat;
|
|||
*/
|
||||
attribute vec4 vertex;
|
||||
|
||||
/** Vectex color.
|
||||
|
||||
r, g, b, a
|
||||
*/
|
||||
attribute vec4 vcolor;
|
||||
|
||||
/** The character to draw.
|
||||
|
||||
The quake character map supports only 256 characters, 0-255. Any other
|
||||
|
@ -19,6 +25,7 @@ attribute float char;
|
|||
|
||||
/** Coordinate in character map texture.
|
||||
*/
|
||||
varying vec4 color;
|
||||
varying vec2 st;
|
||||
|
||||
void
|
||||
|
@ -38,4 +45,5 @@ main (void)
|
|||
uv *= size;
|
||||
gl_Position = mvp_mat * vec4 (pos + corner * 8.0, 0.0, 1.0);
|
||||
st = uv;
|
||||
color = vcolor;
|
||||
}
|
||||
|
|
|
@ -140,7 +140,15 @@ void (*r_viewsize_callback)(cvar_t *var);
|
|||
int r_viewsize;
|
||||
|
||||
float cl_wateralpha;
|
||||
quat_t crosshair_color;
|
||||
|
||||
static void
|
||||
crosshaircolor_f (cvar_t *var)
|
||||
{
|
||||
byte *color;
|
||||
color = (byte *) &d_8to24table[bound (0, var->int_val, 255)];
|
||||
QuatScale (color, 1.0 / 255, crosshair_color);
|
||||
}
|
||||
|
||||
static void
|
||||
r_particles_f (cvar_t *var)
|
||||
|
@ -241,8 +249,8 @@ R_Init_Cvars (void)
|
|||
NULL, "Client version string");
|
||||
crosshair = Cvar_Get ("crosshair", "0", CVAR_ARCHIVE, NULL, "Crosshair "
|
||||
"type. 0 off, 1 old white, 2 new with colors");
|
||||
crosshaircolor = Cvar_Get ("crosshaircolor", "79", CVAR_ARCHIVE, NULL,
|
||||
"Color of the new crosshair");
|
||||
crosshaircolor = Cvar_Get ("crosshaircolor", "79", CVAR_ARCHIVE,
|
||||
crosshaircolor_f, "Color of the new crosshair");
|
||||
d_mipcap = Cvar_Get ("d_mipcap", "0", CVAR_NONE, NULL,
|
||||
"Detail level. 0 is highest, 3 is lowest.");
|
||||
d_mipscale = Cvar_Get ("d_mipscale", "1", CVAR_NONE, NULL, "Detail level "
|
||||
|
|
Loading…
Reference in a new issue