diff options
author | Anton Luka Šijanec <anton@sijanec.eu> | 2022-05-10 00:53:01 +0200 |
---|---|---|
committer | Anton Luka Šijanec <anton@sijanec.eu> | 2022-05-10 00:53:01 +0200 |
commit | 0c88f7d7ffb82a729df516a91847bcf0a1ee68d4 (patch) | |
tree | 34f251e14ac652f405075d992560cadad83ec9bd /fiz/naloga | |
parent | helmholtz gl (diff) | |
download | sola-gimb-3-0c88f7d7ffb82a729df516a91847bcf0a1ee68d4.tar sola-gimb-3-0c88f7d7ffb82a729df516a91847bcf0a1ee68d4.tar.gz sola-gimb-3-0c88f7d7ffb82a729df516a91847bcf0a1ee68d4.tar.bz2 sola-gimb-3-0c88f7d7ffb82a729df516a91847bcf0a1ee68d4.tar.lz sola-gimb-3-0c88f7d7ffb82a729df516a91847bcf0a1ee68d4.tar.xz sola-gimb-3-0c88f7d7ffb82a729df516a91847bcf0a1ee68d4.tar.zst sola-gimb-3-0c88f7d7ffb82a729df516a91847bcf0a1ee68d4.zip |
Diffstat (limited to 'fiz/naloga')
-rw-r--r-- | fiz/naloga/gl/fragment.glsl | 41 | ||||
-rw-r--r-- | fiz/naloga/gl/helmholtz.c | 43 |
2 files changed, 67 insertions, 17 deletions
diff --git a/fiz/naloga/gl/fragment.glsl b/fiz/naloga/gl/fragment.glsl index c4952c4..095cb78 100644 --- a/fiz/naloga/gl/fragment.glsl +++ b/fiz/naloga/gl/fragment.glsl @@ -1,11 +1,10 @@ #version 330 -#pragma optionNV (unroll 1) +// #pragma optionNV (unroll 1) #define show_vec #define SEG 32 -#define R .8 #define I .5 #define n 100. @@ -18,12 +17,11 @@ uniform int OPTIONS; out vec4 fragColor; -vec3 tuljava (vec3 pz) { +vec3 tuljava (vec3 pz, float R) { float dr = 2. * PI / float(SEG); vec3 sum = vec3(0); for (int i = 0; i < SEG; i++){ float theta = dr * float(i); - // jebi se, zakaj neza? pisat ?ita linearno >:( vec3 dl = vec3(0,cos(theta),-sin(theta))*dr*R; vec3 r = vec3(0,sin(theta),cos(theta))*R; r+=pz; @@ -33,13 +31,38 @@ vec3 tuljava (vec3 pz) { return sum; } + void main () { + float R = 0.8; + float R2 = abs(sin((time+8.2)/.6))+0.5; vec2 uv = UVo; - vec3 poz = vec3(uv*2.,sin(time/10.)*R); - vec3 offset = vec3(R/2.,0,0); - - vec3 rez = tuljava(poz+offset)*n*I + - tuljava(poz-offset)*n*I; + vec2 poz = vec2(uv*2.); // zavrteti moramo tako točke same, kot tudi + vec2 offset = vec2(R/2.,0); // njihove komponente + float kot = time/.4; + float multi = n*I/**abs(sin(time/.2)+0.2)*/; + vec2 dodatek = vec2(sin(time/.6)*.5, cos(time/.4)*.6); + vec3 rez = tuljava( + vec3(poz+offset, 1/2*R), R + )*n*I + + tuljava( + vec3( + vec2(poz-offset+dodatek)* + mat2( cos(kot), + sin(kot), -sin(kot), + cos(kot) + ), + 1/2*R + ), + R2 + )*multi*mat3( cos(kot), + sin(kot), + 0, + -sin(kot), + cos(kot), + 0, + 0, + 0, + 1); rez *= 1000.; #ifdef show_vec fragColor = vec4(rez, 1); diff --git a/fiz/naloga/gl/helmholtz.c b/fiz/naloga/gl/helmholtz.c index cbc1db3..5f8f44d 100644 --- a/fiz/naloga/gl/helmholtz.c +++ b/fiz/naloga/gl/helmholtz.c @@ -1,9 +1,12 @@ #include <stdlib.h> #include <stdio.h> -#include <complex.h> #include <unistd.h> #include <GL/glxew.h> #include <GLFW/glfw3.h> + +#include <fcntl.h> +#include <unistd.h> +#include <sys/mman.h> extern char _binary_vertex_glsl_start[]; extern char _binary_vertex_glsl_end[]; extern char _binary_fragment_glsl_start[]; @@ -63,15 +66,10 @@ int main (void) { const char * vertex = _binary_vertex_glsl_start; const char * fragment = _binary_fragment_glsl_start; #define DO_SHADER(whi, WHI) \ - fprintf(stderr, "shader code:\n%.*s\n", whi##_len, whi); \ - fprintf(stderr, "glCreateShader ...\n"); \ GLuint whi##_shader = glCreateShader(GL_##WHI##_SHADER); \ - fprintf(stderr, "glShaderSource ...\n"); \ glShaderSource(whi##_shader, 1, &whi, &whi##_len); \ - fprintf(stderr, "glCompileShader ...\n"); \ glCompileShader(whi##_shader); \ GLint whi##_success = 0; \ - fprintf(stderr, "glGetShaderiv ...\n"); \ glGetShaderiv(whi##_shader, GL_COMPILE_STATUS, &whi##_success); \ if (whi##_success == GL_FALSE) { \ GLint logSize = 0; \ @@ -110,18 +108,47 @@ int main (void) { GLuint optI = glGetUniformLocation(program, "OPTIONS"); uint32_t opts = 123456; glClearColor(0.1, 0.2, 0.3, 1); + unsigned frame = 0; + getchar(); // da vmes odpremo okno v floating načinu s pravilno velikostjo while (!glfwWindowShouldClose(okno)) { int w, h; glfwGetFramebufferSize(okno, &w, &h); glViewport(0, 0, w, h); glClear(GL_COLOR_BUFFER_BIT); glUseProgram(program); // testiraj, mogoče se to sme dat iz loopa gor - glUniform1f(timeI, glfwGetTime()); + glUniform1f(timeI, (float) frame/60); glUniform1i(optI, opts++); glBindVertexArray(vao); glDrawArrays(GL_TRIANGLES, 0, 6 /* dva triangla po 3 */); glfwSwapBuffers(okno); - glfwWaitEvents(); // glfwPollEvents pa returna takoj + glfwPollEvents(); // wait / poll + frame++; + char fn[25]; + sprintf(fn, "animacija%04d.ppm", frame); + int fd; + if ((fd = open(fn, O_CREAT | O_RDWR, 00664)) == -1) { + perror("open"); + abort(); + } + if (ftruncate(fd, 128+w*h*3) == -1) { + perror("ftruncate"); + abort(); + } + void * p; + if ((p = mmap(NULL, 128+w*h*3, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0)) == MAP_FAILED) { + perror("mmap"); + abort(); + } + sprintf(p, "P6\n\n%57d\n%57d\n255\n", w, h); + glReadPixels(0, 0, w, h, GL_RGB, GL_UNSIGNED_BYTE, (unsigned char *) p + 128); + if (munmap(p, 128+w*h*3) == -1) { + perror("munmap"); + abort(); + } + if (close(fd) == -1) { + perror("close"); + abort(); + } } glfwDestroyWindow(okno); glfwTerminate(); |