texture resolutions
This commit is contained in:
parent
a091a542f3
commit
641953bba1
4 changed files with 35 additions and 11 deletions
26
renderer.c
26
renderer.c
|
|
@ -52,6 +52,7 @@ const char *fragment_header_src =
|
|||
"uniform sampler2D iChannel1;\n"
|
||||
"uniform sampler2D iChannel2;\n"
|
||||
"uniform sampler2D iChannel3;\n"
|
||||
"uniform vec3 iChannelResolution[4];\n"
|
||||
"void mainImage(out vec4 fragColor, in vec2 fragCoord);\n"
|
||||
"void main() {\n"
|
||||
" mainImage(color, gl_FragCoord.xy);\n"
|
||||
|
|
@ -167,8 +168,8 @@ Renderer new_renderer(char **textures, int texture_count) {
|
|||
|
||||
// textures
|
||||
for (int i = 0; i < texture_count; i++) {
|
||||
glGenTextures(1, &renderer.textures[i]);
|
||||
glBindTexture(GL_TEXTURE_2D, renderer.textures[i]);
|
||||
glGenTextures(1, &renderer.textures[i].texture);
|
||||
glBindTexture(GL_TEXTURE_2D, renderer.textures[i].texture);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
|
||||
|
|
@ -178,6 +179,10 @@ Renderer new_renderer(char **textures, int texture_count) {
|
|||
if (data) {
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, data);
|
||||
glGenerateMipmap(GL_TEXTURE_2D);
|
||||
renderer.textures[i].width = width;
|
||||
renderer.textures[i].height = height;
|
||||
renderer.textures[i].nr_channels = nr_channels;
|
||||
printf("texture info | width: %d, height: %d, nr_channels: %d\n", width, height, nr_channels);
|
||||
}
|
||||
else {
|
||||
fprintf(stderr, "failed to load texture %d\n", i);
|
||||
|
|
@ -226,22 +231,22 @@ void render(Renderer *state, int w, int h, double time, char *shader_path, int r
|
|||
switch (i) {
|
||||
case 0:
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D, state->textures[i]);
|
||||
glBindTexture(GL_TEXTURE_2D, state->textures[i].texture);
|
||||
glUniform1i(glGetUniformLocation(state->shader, "iChannel0"), i);
|
||||
break;
|
||||
case 1:
|
||||
glActiveTexture(GL_TEXTURE1);
|
||||
glBindTexture(GL_TEXTURE_2D, state->textures[i]);
|
||||
glBindTexture(GL_TEXTURE_2D, state->textures[i].texture);
|
||||
glUniform1i(glGetUniformLocation(state->shader, "iChannel1"), i);
|
||||
break;
|
||||
case 2:
|
||||
glActiveTexture(GL_TEXTURE2);
|
||||
glBindTexture(GL_TEXTURE_2D, state->textures[i]);
|
||||
glBindTexture(GL_TEXTURE_2D, state->textures[i].texture);
|
||||
glUniform1i(glGetUniformLocation(state->shader, "iChannel2"), i);
|
||||
break;
|
||||
case 3:
|
||||
glActiveTexture(GL_TEXTURE3);
|
||||
glBindTexture(GL_TEXTURE_2D, state->textures[i]);
|
||||
glBindTexture(GL_TEXTURE_2D, state->textures[i].texture);
|
||||
glUniform1i(glGetUniformLocation(state->shader, "iChannel3"), i);
|
||||
break;
|
||||
default:
|
||||
|
|
@ -251,6 +256,15 @@ void render(Renderer *state, int w, int h, double time, char *shader_path, int r
|
|||
}
|
||||
}
|
||||
|
||||
GLfloat iChannelResolutions[4 * 3];
|
||||
for (int i = 0; i < state->texture_count; i++) {
|
||||
iChannelResolutions[i * 3] = state->textures[i].width;
|
||||
iChannelResolutions[i * 3 + 1] = state->textures[i].height;
|
||||
iChannelResolutions[i * 3 + 2] = 1.0;
|
||||
}
|
||||
int uniform_iChannelResolution = glGetUniformLocation(state->shader, "iChannelResolution");
|
||||
glUniform3fv(uniform_iChannelResolution, state->texture_count, iChannelResolutions);
|
||||
|
||||
int uniform_iResolution = glGetUniformLocation(state->shader, "iResolution");
|
||||
glUniform2f(uniform_iResolution, w, h);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue