added iTime uniform

master
bx 2022-03-21 22:01:49 +00:00
parent f850e3f082
commit c5ee25113f
1 changed files with 4 additions and 1 deletions

View File

@ -59,10 +59,12 @@ void init(Sdfps* s) { /* TODO: Error checks */
/* viewport resolution (in pixels), z = 1 */
"uniform vec3 iResolution;\n"
/* playback time in seconds */
"uniform float iTime;\n"
"out vec4 out_color;\n"
"void main() {\n"
"vec2 xy = gl_FragCoord.xy;\n"
"vec2 xy = gl_FragCoord.xy + vec2(sin(iTime), cos(iTime));\n"
"out_color = vec4(sin(xy.x), sin(xy.y), sin(xy.x) + sin(xy.y), 1);\n"
"if(xy.x > iResolution.x / 2.0) out_color = out_color.zxyw;\n"
"}\n");
@ -120,6 +122,7 @@ void render(Sdfps *s) {
GLuint iResolution = glGetUniformLocation(s -> shader_program, "iResolution");
// TODO: error check?
glUniform3f(iResolution, (f32) fb_w, (f32) fb_h, 1.0f);
glUniform1f(glGetUniformLocation(s -> shader_program, "iTime"), 0.001f * (f32) SDL_GetTicks());
glClearColor(0.1f, 0.25f, 0.24f, 1);
glClear(GL_COLOR_BUFFER_BIT);