diff options
-rw-r--r-- | img | 2 | ||||
-rw-r--r-- | shader.frag | 2 | ||||
-rw-r--r-- | sv.c | 151 | ||||
-rw-r--r-- | vns.png | bin | 12268 -> 0 bytes |
4 files changed, 15 insertions, 140 deletions
@@ -6,5 +6,3 @@ void.png /home/ch/images/art/20130113_164510.JPG /home/ch/images/art/20171014_092615.JPG /home/ch/images/art/20171202_151645.JPG -vns.png -vns-invert.png diff --git a/shader.frag b/shader.frag index 60d5e50..9d8d7fa 100644 --- a/shader.frag +++ b/shader.frag @@ -69,7 +69,7 @@ void main (void) { coord = zoom(st(),1.0-0.5*(1.0-params[2])); coord = translate(coord,vec2(-0.1,-0.1)); vec3 i2 = texture2D(images[2],coord).rgb; - img.rgb = pow((1.0-2.3*img.rgb),1.0+(1.0-params[1])*2*i2); + img.rgb = 2.5*pow((1.0-2.3*img.rgb),1.0+(1.0-params[1])*2*i2); } else if (program == 2) { coord = zoom(st(),1.0-0.5*(1.0-params[2])); @@ -41,14 +41,7 @@ typedef struct Img { } Image; Image images[8]; - -float params[4]; - -int record = 0; -int recording = 0; -int fullscreen = 0; - -FILE* ffmpeg; +GLfloat params[4]; static snd_seq_t *midi_seq; static int midiin; @@ -56,64 +49,11 @@ static int midiin; int ticks =0; int running = 0; int program=0; -int frame = 0; -unsigned char buffer[1920*1080*4]; -struct arg_struct { - unsigned char buffer[1920*1080*4]; - int frame; -}; - -void *screenshot(void * f) { - unsigned char pixels[width*height*4]; - //time_t current_time = time(NULL); - //char output_file[25]; - char output_file[20]; - //strftime(output_file, 25, "%Y-%m-%d_%H%M%S.png", localtime(¤t_time)); - sprintf(output_file, "record/%i.png",*(int*)f); - glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, pixels); - - // Flip the image on Y - int depth = 4; - int row,col,z; - stbi_uc temp; - for (row = 0; row < (height>>1); row++) { - for (col = 0; col < width; col++) { - for (z = 0; z < depth; z++) { - temp = pixels[(row * width + col) * depth + z]; - pixels[(row * width + col) * depth + z] = pixels[((height - row - 1) * width + col) * depth + z]; - pixels[((height - row - 1) * width + col) * depth + z] = temp; - } - } - } - printf("%s\n",output_file); - if (0 == stbi_write_png(output_file, width, height, 4, pixels, width * 4)) { printf("can't create file %s",output_file); } -} - -void *save(void * b) { - //struct arg_struct args; - //glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, buffer); - char output_file[20]; - sprintf(output_file, "record/%i.png",frame); - printf("%ix%i\n",width,height); - printf("%s\n",output_file); - int r = stbi_write_png(output_file, width, height, 4, buffer, width * 4); - printf("%s\n",output_file); - printf("%i\n",r); - //struct arg_struct *args = arguments; - //char output_file[20]; - //sprintf(output_file, "record/%i.png",frame); - //printf("%s\n",output_file); - //int r = stbi_write_png(output_file, width, height, 4, buffer, width * 4); - //printf("%i\n",r); - //if (0 == stbi_write_png(output_file, width, height, 4, buffer, width * 4)) { printf("can't create file %s",output_file); } - return(NULL); -} static void error_callback(int error, const char* description) { fputs(description, stderr); } static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods) { if (key == GLFW_KEY_Q && action == GLFW_PRESS) glfwSetWindowShouldClose(window, GL_TRUE); - //else if (key == GLFW_KEY_SPACE && action == GLFW_PRESS) screenshot(); } const char * readShader(char * path) { @@ -189,7 +129,6 @@ void resize_callback(GLFWwindow* window, int w, int h) { void readImage(int i) { images[i].new = 1; - int w,h,comp; stbi_set_flip_vertically_on_load(1); unsigned char* pixels = stbi_load(images[i].path, &w, &h, &comp, STBI_rgb_alpha); @@ -202,10 +141,6 @@ void readImage(int i) { glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER); - //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_MIRRORED_REPEAT); - //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_MIRRORED_REPEAT); - //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); - //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels); stbi_image_free(pixels); } @@ -230,28 +165,10 @@ void *readMidi() { } else if(ev->type == SND_SEQ_EVENT_SONGPOS) ticks = ev->data.control.value*24; - else if(ev->type == SND_SEQ_EVENT_START) { + else if(ev->type == SND_SEQ_EVENT_START) running = 1; - if (record) { - /* - time_t current_time = time(NULL); - char output_file[25]; - strftime(output_file, 25, "%Y-%m-%d_%H%M%S.mkv", localtime(¤t_time)); - char cmd[250]; - sprintf(cmd, "ffmpeg -framerate 60 -f rawvideo -pix_fmt rgba -s %ix%i -i - -preset ultrafast -y -c:v libx264 -crf 0 -vf vflip %s",width,height,output_file); - ffmpeg = popen(cmd, "w"); - */ - frame = 0; - recording = 1; - } - } - else if(ev->type == SND_SEQ_EVENT_STOP) { + else if(ev->type == SND_SEQ_EVENT_STOP) running = 0; - if (recording) { - recording = 0; - //pclose(ffmpeg); - } - } else if(ev->type == SND_SEQ_EVENT_CONTINUE) running = 1; else if(ev->type == SND_SEQ_EVENT_CLOCK) @@ -270,15 +187,6 @@ void *watchShader() { int main(int argc, char **argv) { - // parse options - int opt; - while ((opt = getopt(argc, argv, "rf")) != -1) { - switch (opt) { - case 'r': record = 1; fullscreen = 1; break; - case 'f': fullscreen = 1; break; - } - } - for (int i = optind; i<argc; i++) { strncpy(images[i-optind].path, argv[i],40); images[i-optind].new = 1; @@ -291,12 +199,8 @@ int main(int argc, char **argv) { const GLFWvidmode * mode = glfwGetVideoMode(glfwGetPrimaryMonitor()); width = mode->width; height = mode->height; - if (fullscreen) { - window = glfwCreateWindow(width,height, "", glfwGetPrimaryMonitor(), NULL); - } else { - window = glfwCreateWindow(width,height, "sv", NULL, NULL); - glfwSetWindowSizeCallback(window, resize_callback); - } + window = glfwCreateWindow(width,height, "sv", NULL, NULL); + glfwSetWindowSizeCallback(window, resize_callback); glfwMakeContextCurrent(window); glfwSetKeyCallback(window, key_callback); glfwSetErrorCallback(error_callback); @@ -312,6 +216,7 @@ int main(int argc, char **argv) { glCreateTextures(GL_TEXTURE_2D,1,&backbuffer); glTextureStorage2D(backbuffer,1,GL_RGBA32F,width,height); glBindImageTexture(0,backbuffer, 0, GL_FALSE, 0, GL_READ_WRITE, GL_RGBA32F); + for (int i = 0; i<8; i++) { readImage(i); images[i].new = 0; @@ -321,56 +226,28 @@ int main(int argc, char **argv) { pthread_create(&midiin_t, NULL, readMidi, NULL); pthread_t frag_t; pthread_create(&frag_t, NULL, watchShader, NULL); - - int n = 0; - printf("%ix%i\n",width,height); + while (!glfwWindowShouldClose(window)) { + if (shader.new) { createShader(); glUniform2f(glGetUniformLocation(shader.id, "resolution"),width,height); // important!! for (int i = 0; i<8; i++) { imageUniforms(i); } shader.new = 0; } + glUniform1f(glGetUniformLocation(shader.id, "time"),glfwGetTime()); glUniform1f(glGetUniformLocation(shader.id, "ticks"),(float)ticks); glUniform1i(glGetUniformLocation(shader.id, "program"),program); - for (int i = 0; i<4; i++) { - glUniform1f(glGetUniformLocation(shader.id, "params")+i, params[i]); - } + glUniform1fv(glGetUniformLocation(shader.id, "params"), 8, params); - glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); - glfwSwapBuffers(window); - - if (recording) { - /* - pid_t pid = fork(); - if (pid == 0) { - unsigned char buffer[width*height*4]; - //struct arg_struct args; - glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, buffer); - char output_file[20]; - sprintf(output_file, "record/%i.png",frame); - printf("%s\n",output_file); - int r = stbi_write_png(output_file, width, height, 4, buffer, width * 4); - printf("%i\n",r); - exit(EXIT_SUCCESS); - } - */ - //args.buffer = buffer; - //args.frame = frame; - glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, buffer); - pthread_t tid; - pthread_create (&tid, NULL, save, NULL); - pthread_detach (tid); - //printf("%i\n",frame); - frame++; - //fwrite(buffer, sizeof(int)*width*height, 1, ffmpeg); + if (running) { + glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); + glfwSwapBuffers(window); + glfwPollEvents(); } - - glfwPollEvents(); } - //if (recording) pclose(ffmpeg); pthread_cancel(midiin_t); pthread_cancel(frag_t); glfwDestroyWindow(window); diff --git a/vns.png b/vns.png Binary files differdeleted file mode 100644 index 3b998d9..0000000 --- a/vns.png +++ /dev/null |