aboutsummaryrefslogtreecommitdiff
path: root/src/shader.c
diff options
context:
space:
mode:
authorCharles <sircharlesaze@gmail.com>2020-05-20 07:41:03 +0200
committerCharles <sircharlesaze@gmail.com>2020-05-20 07:41:03 +0200
commit09a819b2ef927adf5239a73f91cdfcefd6774688 (patch)
tree8602814faa153aae01acc95a557d45b24c028f3b /src/shader.c
parent70bf7ac330545f14ab9babddfdf0cb5df9e9ee69 (diff)
downloadmandelbrot-09a819b2ef927adf5239a73f91cdfcefd6774688.tar.gz
mandelbrot-09a819b2ef927adf5239a73f91cdfcefd6774688.tar.bz2
mandelbrot-09a819b2ef927adf5239a73f91cdfcefd6774688.zip
Added colors with 1D texture
Diffstat (limited to 'src/shader.c')
-rw-r--r--src/shader.c37
1 files changed, 23 insertions, 14 deletions
diff --git a/src/shader.c b/src/shader.c
index 0b4091d..68295ab 100644
--- a/src/shader.c
+++ b/src/shader.c
@@ -4,17 +4,15 @@
#define MANDEL_SHADER_FRAG_FILE "shader/fragment.glsl"
static unsigned int st_compile(char *filepath, unsigned int type);
+static int st_get_location(unsigned int shader_id, const char *name);
bool shader_init(Shader *shader)
{
unsigned int shader_vert;
unsigned int shader_frag;
- shader_vert = st_compile(MANDEL_SHADER_VERT_FILE, GL_VERTEX_SHADER);
- if (shader_vert == 0)
- return false;
- shader_frag = st_compile(MANDEL_SHADER_FRAG_FILE, GL_FRAGMENT_SHADER);
- if (shader_frag == 0)
+ if ((shader_vert = st_compile(MANDEL_SHADER_VERT_FILE, GL_VERTEX_SHADER)) == 0
+ || (shader_frag = st_compile(MANDEL_SHADER_FRAG_FILE, GL_FRAGMENT_SHADER)) == 0)
return false;
GL_CALL(shader->id = glCreateProgram());
@@ -25,17 +23,24 @@ bool shader_init(Shader *shader)
GL_CALL(glDeleteShader(shader_vert));
GL_CALL(glDeleteShader(shader_frag));
- GL_CALL(shader->location.width = glGetUniformLocation(shader->id, "u_width"));
- GL_CALL(shader->location.height = glGetUniformLocation(shader->id, "u_height"));
-
- GL_CALL(shader->location.real_start = glGetUniformLocation(shader->id, "u_real_start"));
- GL_CALL(shader->location.real_end = glGetUniformLocation(shader->id, "u_real_end"));
- GL_CALL(shader->location.imag_start = glGetUniformLocation(shader->id, "u_imag_start"));
- GL_CALL(shader->location.imag_end = glGetUniformLocation(shader->id, "u_imag_end"));
+ if ((shader->location.width = st_get_location(shader->id, "u_width")) == -1
+ || (shader->location.height = st_get_location(shader->id, "u_height")) == -1
+ || (shader->location.real_start = st_get_location(shader->id, "u_real_start")) == -1
+ || (shader->location.real_end = st_get_location(shader->id, "u_real_end")) == -1
+ || (shader->location.imag_start = st_get_location(shader->id, "u_imag_start")) == -1
+ || (shader->location.imag_end = st_get_location(shader->id, "u_imag_end")) == -1
+ || (shader->location.iterations = st_get_location(shader->id, "u_iterations")) == -1
+ || (shader->location.texture = st_get_location(shader->id, "u_texture")) == -1)
+ return false;
+ return true;
+}
- GL_CALL(shader->location.iterations = glGetUniformLocation(shader->id, "u_iterations"));
+static int st_get_location(unsigned int shader_id, const char *name)
+{
+ int location;
- return (true);
+ GL_CALL(location = glGetUniformLocation(shader_id, name));
+ return location;
}
void shader_set_uniforms(Shader *shader, State *state)
@@ -49,6 +54,10 @@ void shader_set_uniforms(Shader *shader, State *state)
GL_CALL(glUniform1f(shader->location.imag_end, state->imag_end));
GL_CALL(glUniform1i(shader->location.iterations, state->iterations));
+
+ GL_CALL(glUniform1i(shader->location.texture, 0));
+ GL_CALL(glActiveTexture(GL_TEXTURE0));
+ GL_CALL(glBindTexture(GL_TEXTURE_1D, state->texture));
}
static unsigned int st_compile(char *filepath, unsigned int type)