summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnton Luka Šijanec <anton@sijanec.eu>2022-05-09 22:38:58 +0200
committerAnton Luka Šijanec <anton@sijanec.eu>2022-05-09 22:38:58 +0200
commit448f44dad78f51e0b2250aac7ab25420c5cf3469 (patch)
tree99f263402ed549a546cf9e3bae7b1e8acdcb7aea
parentmaček v praznem stanovanju, W. Szymborska (diff)
downloadsola-gimb-3-448f44dad78f51e0b2250aac7ab25420c5cf3469.tar
sola-gimb-3-448f44dad78f51e0b2250aac7ab25420c5cf3469.tar.gz
sola-gimb-3-448f44dad78f51e0b2250aac7ab25420c5cf3469.tar.bz2
sola-gimb-3-448f44dad78f51e0b2250aac7ab25420c5cf3469.tar.lz
sola-gimb-3-448f44dad78f51e0b2250aac7ab25420c5cf3469.tar.xz
sola-gimb-3-448f44dad78f51e0b2250aac7ab25420c5cf3469.tar.zst
sola-gimb-3-448f44dad78f51e0b2250aac7ab25420c5cf3469.zip
-rw-r--r--fiz/naloga/gl/fragment.glsl73
-rw-r--r--fiz/naloga/gl/helmholtz.c48
-rw-r--r--fiz/naloga/gl/vertex.glsl10
3 files changed, 127 insertions, 4 deletions
diff --git a/fiz/naloga/gl/fragment.glsl b/fiz/naloga/gl/fragment.glsl
index e69de29..c4952c4 100644
--- a/fiz/naloga/gl/fragment.glsl
+++ b/fiz/naloga/gl/fragment.glsl
@@ -0,0 +1,73 @@
+#version 330
+#pragma optionNV (unroll 1)
+
+#define show_vec
+
+#define SEG 32
+
+#define R .8
+#define I .5
+#define n 100.
+
+#define PI 3.1415
+
+in vec2 UVo;
+
+uniform float time;
+uniform int OPTIONS;
+
+out vec4 fragColor;
+
+vec3 tuljava (vec3 pz) {
+ 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;
+ sum+=cross(dl,r)/(length(r)*length(r)*length(r));
+ }
+ sum *= 1e-6;
+ return sum;
+}
+
+void main () {
+ 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;
+ rez *= 1000.;
+#ifdef show_vec
+ fragColor = vec4(rez, 1);
+#else
+ fragColor = vec4(vec3(length(rez)), 1);
+#endif
+}
+/*
+ uniform float time;
+ uform int OPTIONS;
+//uniform mat2 bounds;
+
+out vec4 frag_colour;
+
+
+void main() {
+vec2 UV = UVo;
+float scale = 1.1;
+vec2 complex=UV*scale;
+vec2 ot=vec2(0);
+int tmpy=OPTIONS;
+for (int x = 0; x < 16; x++){
+ot=vec2(complex.x*ot.x-complex.y*ot.y,complex.x*ot.y+complex.y*ot.x);
+int swch = tmpy & 1;
+ot+=complex * (swch*2-1);
+tmpy>>=1;
+}
+
+frag_colour = vec4(vec3(smoothstep(.05,0,length(ot))), 1.);
+}
+ */
diff --git a/fiz/naloga/gl/helmholtz.c b/fiz/naloga/gl/helmholtz.c
index 7d8171b..cbc1db3 100644
--- a/fiz/naloga/gl/helmholtz.c
+++ b/fiz/naloga/gl/helmholtz.c
@@ -41,11 +41,37 @@ int main (void) {
glfwSwapInterval(1); // vsync
glfwSetKeyCallback(okno, key_callback);
GLuint program = glCreateProgram();
+ float points[] = {
+ -1.0f, 1.0f, -1.0f,
+ -1.0f, -1.0f, -1.0f,
+ 1.0f, -1.0f, -1.0f,
+ 1.0f, -1.0f, -1.0f,
+ 1.0f, 1.0f, -1.0f,
+ -1.0f, 1.0f, -1.0f
+ };
+ // <black box>
+ GLuint points_vbo, vao;
+ glGenBuffers(1, &points_vbo);
+ glBindBuffer(GL_ARRAY_BUFFER, points_vbo);
+ glBufferData(GL_ARRAY_BUFFER, sizeof points, points, GL_STATIC_DRAW);
+ glGenVertexArrays(1, &vao);
+ glBindVertexArray(vao);
+ glEnableVertexAttribArray(0);
+ glBindBuffer(GL_ARRAY_BUFFER, points_vbo);
+ glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, NULL);
+ // </black box>
+ 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); \
- glShaderSource(whi##_shader, 1, (const GLchar **) &_binary_##whi##_glsl_start, &whi##_len); \
+ 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; \
@@ -59,6 +85,9 @@ int main (void) {
glAttachShader(program, whi##_shader);
DO_SHADER(vertex, VERTEX);
DO_SHADER(fragment, FRAGMENT);
+ // <black box>
+ glBindAttribLocation(program, 0, "vertex_position");
+ // </black box>
glLinkProgram(program);
GLint isLinked = 0;
glGetProgramiv(program, GL_LINK_STATUS, &isLinked);
@@ -73,13 +102,24 @@ int main (void) {
glDeleteProgram(program);
return 5;
}
- glDetachShader(program, vertex_shader); // TODO: ali lahko glDeleteShader po linku?
- glDetachShader(program, fragment_shader);
+ // glDetachShader(program, vertex_shader);
+ // glDetachShader(program, fragment_shader);
+ // glDeleteShader(fragment_shader); // testiraj, mogoče se to sme
+ // glDeleteShader(vertex_shader);
+ GLuint timeI = glGetUniformLocation(program, "time");
+ GLuint optI = glGetUniformLocation(program, "OPTIONS");
+ uint32_t opts = 123456;
+ glClearColor(0.1, 0.2, 0.3, 1);
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());
+ glUniform1i(optI, opts++);
+ glBindVertexArray(vao);
+ glDrawArrays(GL_TRIANGLES, 0, 6 /* dva triangla po 3 */);
glfwSwapBuffers(okno);
glfwWaitEvents(); // glfwPollEvents pa returna takoj
}
diff --git a/fiz/naloga/gl/vertex.glsl b/fiz/naloga/gl/vertex.glsl
index e69de29..d17b522 100644
--- a/fiz/naloga/gl/vertex.glsl
+++ b/fiz/naloga/gl/vertex.glsl
@@ -0,0 +1,10 @@
+#version 330
+
+layout(location = 0) in vec3 vertex_position;
+
+out vec2 UVo;
+
+void main() {
+ UVo = vertex_position.xy;
+ gl_Position = vec4(vertex_position, 1.0);
+}