command line argument to shader
This commit is contained in:
parent
864df46d69
commit
a32e44f45f
5 changed files with 24 additions and 11 deletions
|
|
@ -78,10 +78,7 @@ void main() {
|
||||||
// lerp index
|
// lerp index
|
||||||
float u = fade(tile_uv.x);
|
float u = fade(tile_uv.x);
|
||||||
float v = fade(tile_uv.y);
|
float v = fade(tile_uv.y);
|
||||||
//float u = tile_uv.x;
|
|
||||||
//float v = tile_uv.y;
|
|
||||||
float val = lerp(lerp(c_tl_dot, c_bl_dot, v), lerp(c_tr_dot, c_br_dot, v), u);
|
float val = lerp(lerp(c_tl_dot, c_bl_dot, v), lerp(c_tr_dot, c_br_dot, v), u);
|
||||||
float out_val = val /2.0 + 0.5;
|
float out_val = val /2.0 + 0.5;
|
||||||
//float out_val = rand(uv , vec2(1.0, 1.0));
|
|
||||||
color = vec4(out_val, out_val, out_val, 1.0);
|
color = vec4(out_val, out_val, out_val, 1.0);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
14
glonkers.c
14
glonkers.c
|
|
@ -1,7 +1,7 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <string.h>
|
|
||||||
#include <wayland-client.h>
|
#include <wayland-client.h>
|
||||||
#include <wayland-util.h>
|
#include <wayland-util.h>
|
||||||
#include <SDL3/SDL.h>
|
#include <SDL3/SDL.h>
|
||||||
|
|
@ -79,7 +79,7 @@ double time_since_start() {
|
||||||
(now.tv_nsec - program_start.tv_nsec) / 1e9;
|
(now.tv_nsec - program_start.tv_nsec) / 1e9;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main() {
|
int main(int argc, char *argv[]) {
|
||||||
init_timer();
|
init_timer();
|
||||||
|
|
||||||
printf("Good Morning 🍵\n");
|
printf("Good Morning 🍵\n");
|
||||||
|
|
@ -119,8 +119,16 @@ int main() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char *shader_path = NULL;
|
||||||
|
if (argc >= 2) {
|
||||||
|
shader_path = argv[1];
|
||||||
|
} else {
|
||||||
|
printf("need to supply path to shader\n");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
double time = time_since_start();
|
double time = time_since_start();
|
||||||
render(&renderer, w, h, time);
|
render(&renderer, w, h, time, shader_path);
|
||||||
|
|
||||||
SDL_GL_SwapWindow(window);
|
SDL_GL_SwapWindow(window);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
12
renderer.c
12
renderer.c
|
|
@ -1,5 +1,6 @@
|
||||||
#define GL_GLEXT_PROTOTYPES
|
#define GL_GLEXT_PROTOTYPES
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
#include <GL/gl.h>
|
#include <GL/gl.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include "renderer.h"
|
#include "renderer.h"
|
||||||
|
|
@ -106,8 +107,6 @@ Renderer new_renderer() {
|
||||||
|
|
||||||
glEnable(GL_DEPTH_TEST);
|
glEnable(GL_DEPTH_TEST);
|
||||||
|
|
||||||
GLuint shader = load_shader("fragment.glsl"); //create_shader(fragment_shader_source);
|
|
||||||
|
|
||||||
// buffers
|
// buffers
|
||||||
// Load the vertex data
|
// Load the vertex data
|
||||||
GLfloat vertices[] = {
|
GLfloat vertices[] = {
|
||||||
|
|
@ -139,11 +138,16 @@ Renderer new_renderer() {
|
||||||
(void *)0
|
(void *)0
|
||||||
);
|
);
|
||||||
|
|
||||||
Renderer renderer = { shader, vao };
|
Renderer renderer = { "", 0, vao };
|
||||||
return renderer;
|
return renderer;
|
||||||
}
|
}
|
||||||
|
|
||||||
void render(Renderer *state, int w, int h, double time) {
|
/// shader_path cannot be NULL.
|
||||||
|
void render(Renderer *state, int w, int h, double time, char *shader_path) {
|
||||||
|
if (strcmp(state->shader_path, shader_path)) {
|
||||||
|
state->shader = load_shader(shader_path);
|
||||||
|
}
|
||||||
|
|
||||||
checkGlError();
|
checkGlError();
|
||||||
|
|
||||||
// Rendorrrr
|
// Rendorrrr
|
||||||
|
|
|
||||||
|
|
@ -2,12 +2,13 @@
|
||||||
#define RENDERER_H
|
#define RENDERER_H
|
||||||
|
|
||||||
typedef struct Renderer {
|
typedef struct Renderer {
|
||||||
|
char *shader_path;
|
||||||
unsigned int shader;
|
unsigned int shader;
|
||||||
unsigned int vao;
|
unsigned int vao;
|
||||||
} Renderer;
|
} Renderer;
|
||||||
|
|
||||||
Renderer new_renderer();
|
Renderer new_renderer();
|
||||||
void render(Renderer *renderer, int w, int h, double time);
|
void render(Renderer *renderer, int w, int h, double time, char *shader_path);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
||||||
3
run.sh
Executable file
3
run.sh
Executable file
|
|
@ -0,0 +1,3 @@
|
||||||
|
make
|
||||||
|
./glonkers "$@"
|
||||||
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue