animated font shader
This commit is contained in:
parent
405d6b95a1
commit
92bf7722b3
@ -31,6 +31,8 @@ extern "C" {
|
||||
uint uniform_trans,
|
||||
uint uniform_texture_trans,
|
||||
uint uniform_texture0,
|
||||
uint uniform_base_color,
|
||||
uint uniform_time,
|
||||
struct game_state * state);
|
||||
|
||||
void render_background(struct mesh plane_mesh,
|
||||
|
||||
@ -160,6 +160,8 @@ int main()
|
||||
uint font__uniform_trans = glGetUniformLocation(font_program, "trans");
|
||||
uint font__uniform_texture_trans = glGetUniformLocation(font_program, "texture_trans");
|
||||
uint font__uniform_texture0 = glGetUniformLocation(font_program, "texture0");
|
||||
uint font__uniform_base_color = glGetUniformLocation(font_program, "base_color");
|
||||
uint font__uniform_time = glGetUniformLocation(font_program, "time");
|
||||
printf("attrib_t %d\n", font__attrib_texture);
|
||||
|
||||
// background
|
||||
@ -325,7 +327,8 @@ int main()
|
||||
paddle__uniform_time,
|
||||
&state);
|
||||
|
||||
glDisable(GL_BLEND);
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
glDepthFunc(GL_ALWAYS);
|
||||
glUseProgram(font_program);
|
||||
render_font(plane_mesh,
|
||||
@ -334,6 +337,8 @@ int main()
|
||||
font__uniform_trans,
|
||||
font__uniform_texture_trans,
|
||||
font__uniform_texture0,
|
||||
font__uniform_base_color,
|
||||
font__uniform_time,
|
||||
&state);
|
||||
|
||||
glfwSwapBuffers(window);
|
||||
|
||||
@ -271,6 +271,8 @@ void render_font(struct mesh plane_mesh,
|
||||
uint uniform_trans,
|
||||
uint uniform_texture_trans,
|
||||
uint uniform_texture0,
|
||||
uint uniform_base_color,
|
||||
uint uniform_time,
|
||||
struct game_state * state)
|
||||
{
|
||||
glBindBuffer(GL_ARRAY_BUFFER, plane_mesh.vtx);
|
||||
@ -302,7 +304,20 @@ void render_font(struct mesh plane_mesh,
|
||||
glUniform1i(uniform_texture0, 0);
|
||||
|
||||
char dst[64];
|
||||
int len = unparse_double(state->remaining, 4, 3, dst);
|
||||
|
||||
double remaining = state->remaining;
|
||||
if (remaining < 0.0)
|
||||
remaining = 0.0;
|
||||
int len = unparse_double(remaining, 4, 1, dst);
|
||||
|
||||
vec3 base_color = vec3(1, 1, 1);
|
||||
if (remaining == 0) {
|
||||
base_color = vec3(abs(sin(state->time * 2)) * 0.6 + 0.4, 0.1, 0.1);
|
||||
//base_color = vec3(1, 0.1, 0.1);
|
||||
}
|
||||
|
||||
glUniform1f(uniform_time, state->time);
|
||||
glUniform3fv(uniform_base_color, 1, &base_color[0]);
|
||||
|
||||
int advance = 0;
|
||||
for (int i = 0; i < len; i++) {
|
||||
|
||||
@ -2,7 +2,11 @@
|
||||
|
||||
uniform sampler2D texture0;
|
||||
|
||||
uniform vec3 base_color;
|
||||
uniform float time;
|
||||
|
||||
varying vec2 fp_texture;
|
||||
varying vec2 fp_position;
|
||||
|
||||
void main()
|
||||
{
|
||||
@ -13,6 +17,17 @@ void main()
|
||||
|
||||
float i = c.x == 0 ? 0.0 : 1.0;
|
||||
|
||||
gl_FragColor = vec4(i, i, i, 1.0);
|
||||
//gl_FragColor = vec4(fp_texture.xy, 1, 1.0);
|
||||
vec2 uv = fp_position;
|
||||
/*
|
||||
float d = sin(uv.x * 0.1 + time * 0.1) / 0.1;
|
||||
d = abs(d);
|
||||
d = 0.01 / d;
|
||||
*/
|
||||
|
||||
float red_alpha = (1.0 - length(uv) + sin(time * 3) * abs(sin(time + uv.x * 2 + uv.y * 2)));
|
||||
|
||||
float alpha = (base_color.y == 1.0) ? 1.0 : red_alpha;
|
||||
gl_FragColor = vec4(base_color * (i + alpha), 1.0);
|
||||
//gl_FragColor = vec4(d, d, d, 1);
|
||||
//gl_FragColor = vec4(fp_position.xy, 0, 1.0);
|
||||
}
|
||||
|
||||
@ -4,7 +4,7 @@ attribute vec3 position;
|
||||
attribute vec2 _texture;
|
||||
|
||||
varying vec2 fp_texture;
|
||||
varying vec2 fp_texture_trans;
|
||||
varying vec2 fp_position;
|
||||
|
||||
uniform vec4 trans[4];
|
||||
uniform vec4 texture_trans[4];
|
||||
@ -31,6 +31,7 @@ void main()
|
||||
vec4 tt = transform4t(vec4(_texture, 0, 1));
|
||||
|
||||
fp_texture = tt.xy;
|
||||
fp_position = position.xz;
|
||||
|
||||
gl_Position = pos;
|
||||
}
|
||||
|
||||
@ -160,6 +160,10 @@ void update(struct game_state * state, double time)
|
||||
update_ball(state, state->balls[i], time);
|
||||
}
|
||||
|
||||
if (state->balls_launched == 0) {
|
||||
state->start_time = time;
|
||||
}
|
||||
|
||||
state->time = time;
|
||||
state->remaining = 20.0 - (time - state->start_time);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user