summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2016-02-03 14:19:09 +0100
committerMatthias Schiffer <mschiffer@universe-factory.net>2016-02-03 14:19:09 +0100
commitd5375d5308b3483f5dc8da89943d5a98f67818d5 (patch)
tree1bda267b42eeb530ca5916f8ed9348b5b41be6d2
parent22e600bde83f04fd4f140bcf2c7f7b90d5920e55 (diff)
downloadglslview-d5375d5308b3483f5dc8da89943d5a98f67818d5.tar
glslview-d5375d5308b3483f5dc8da89943d5a98f67818d5.zip
Get rid of extra_load(), rename parameters
-rw-r--r--common.c17
-rw-r--r--common.h6
-rw-r--r--examples/symmetry.frag12
-rw-r--r--glslview.c31
-rw-r--r--glslwrite.c3
5 files changed, 33 insertions, 36 deletions
diff --git a/common.c b/common.c
index 25fc56a..e9258c1 100644
--- a/common.c
+++ b/common.c
@@ -36,9 +36,18 @@
char *filename;
float current_time = 0;
+GLint param0 = 0;
+GLint param1 = 0;
+GLint param2 = 0;
+
+
static GLint time_loc;
static GLint res_loc;
+static GLint param0_loc;
+static GLint param1_loc;
+static GLint param2_loc;
+
static char * readfile(const char *name) {
FILE *f = fopen(name, "r");
@@ -114,7 +123,9 @@ void load(void) {
time_loc = glGetUniformLocation(program, "time");
res_loc = glGetUniformLocation(program, "res");
- extra_load(program);
+ param0_loc = glGetUniformLocation(program, "param0");
+ param1_loc = glGetUniformLocation(program, "param1");
+ param2_loc = glGetUniformLocation(program, "param2");
glUseProgram(program);
@@ -135,6 +146,10 @@ void render(int width, int height) {
glUniform1f(time_loc, current_time);
glUniform2f(res_loc, width, height);
+ glUniform1i(param0_loc, param0);
+ glUniform1i(param1_loc, param1);
+ glUniform1i(param2_loc, param2);
+
glBegin(GL_QUADS);
glVertex2f(-1, -1);
glVertex2f(1, -1);
diff --git a/common.h b/common.h
index dc52ef5..7cbf34d 100644
--- a/common.h
+++ b/common.h
@@ -34,9 +34,11 @@
extern char *filename;
extern float current_time;
+extern GLint param0;
+extern GLint param1;
+extern GLint param2;
+
void load(void);
void init(void);
void render(int width, int height);
-
-void extra_load(GLuint program);
diff --git a/examples/symmetry.frag b/examples/symmetry.frag
index 0e237cc..90bd71a 100644
--- a/examples/symmetry.frag
+++ b/examples/symmetry.frag
@@ -5,9 +5,9 @@ out vec4 fragColor;
uniform vec2 res;
uniform float time;
-uniform int param_k;
-uniform int param_l;
-uniform int param_m;
+uniform int param0;
+uniform int param1;
+uniform int param2;
const float sharpness = 300;
@@ -35,10 +35,10 @@ void main(void) {
float scene = 0;
- int n = param_k + 32;
- float k = param_l;
+ int n = param0 + 32;
+ float k = param1;
for (int i = 0; i < n; i++) {
- float c = square(vec2(0.5, 0) * rot(PI/2*(4.0*i/n)) * vec2(1, 1), 0.3 + 0.02 * param_m, -PI/2*(k*i/n + time/1500), p * (1 + 0.03*param_m));
+ float c = square(vec2(0.5, 0) * rot(PI/2*(4.0*i/n)) * vec2(1, 1), 0.3 + 0.02 * param2, -PI/2*(k*i/n + time/1500), p * (1 + 0.03*param2));
scene = abs(scene - c);
}
diff --git a/glslview.c b/glslview.c
index c9a9839..42c9e93 100644
--- a/glslview.c
+++ b/glslview.c
@@ -43,14 +43,6 @@
static float speed = 1.0;
static unsigned previous_ticks = 0;
-static GLint param_k = 0;
-static GLint param_l = 0;
-static GLint param_m = 0;
-
-static GLint param_k_loc;
-static GLint param_l_loc;
-static GLint param_m_loc;
-
#ifdef USE_INOTIFY
@@ -100,20 +92,11 @@ static void check_reload(void) {}
#endif
-void extra_load(GLuint program) {
- param_k_loc = glGetUniformLocation(program, "param_k");
- param_l_loc = glGetUniformLocation(program, "param_l");
- param_m_loc = glGetUniformLocation(program, "param_m");
-}
-
static void update(void) {
unsigned ticks = SDL_GetTicks();
current_time += speed * (ticks - previous_ticks);
previous_ticks = ticks;
- glUniform1i(param_k_loc, param_k);
- glUniform1i(param_l_loc, param_l);
- glUniform1i(param_m_loc, param_m);
}
static void handle_input(const char *input) {
@@ -129,7 +112,7 @@ static void handle_input(const char *input) {
break;
case 'R':
- param_k = param_l = param_m = 0;
+ param0 = param1 = param2 = 0;
break;
case '+':
@@ -191,27 +174,27 @@ int main(int argc, char *argv[]) {
case SDL_KEYDOWN:
switch (e.key.keysym.sym) {
case SDLK_PAGEDOWN:
- param_k++;
+ param0++;
break;
case SDLK_PAGEUP:
- param_k--;
+ param0--;
break;
case SDLK_RIGHT:
- param_l++;
+ param1++;
break;
case SDLK_LEFT:
- param_l--;
+ param1--;
break;
case SDLK_DOWN:
- param_m++;
+ param2++;
break;
case SDLK_UP:
- param_m--;
+ param2--;
break;
case SDLK_ESCAPE:
diff --git a/glslwrite.c b/glslwrite.c
index e9f746a..2913ae8 100644
--- a/glslwrite.c
+++ b/glslwrite.c
@@ -36,9 +36,6 @@
#include <SDL2/SDL_opengl.h>
-void extra_load(GLuint program) {
-}
-
static void savePNG(int width, int height, const char *output_dir) {
uint8_t pixels[width*height*4];
glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8, pixels);