summaryrefslogtreecommitdiffstats
path: root/fiz/naloga
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--fiz/naloga/gl/.gitignore2
-rw-r--r--fiz/naloga/gl/Makefile40
-rw-r--r--fiz/naloga/gl/fragment.glsl0
-rw-r--r--fiz/naloga/gl/helmholtz.c89
-rw-r--r--fiz/naloga/gl/test.c7
-rw-r--r--fiz/naloga/gl/vertex.glsl0
6 files changed, 138 insertions, 0 deletions
diff --git a/fiz/naloga/gl/.gitignore b/fiz/naloga/gl/.gitignore
new file mode 100644
index 0000000..4da39b2
--- /dev/null
+++ b/fiz/naloga/gl/.gitignore
@@ -0,0 +1,2 @@
+test
+helmholtz
diff --git a/fiz/naloga/gl/Makefile b/fiz/naloga/gl/Makefile
new file mode 100644
index 0000000..7d04b8b
--- /dev/null
+++ b/fiz/naloga/gl/Makefile
@@ -0,0 +1,40 @@
+DESTDIR=/
+CC = cc
+cflags = -O0 -Wall -I. -fpic -Wformat-security -Wextra -pedantic -g3 $(shell pkg-config --cflags libstrophe)
+ldflags = $(shell pkg-config --libs glew) -lglfw
+PROJ = helmholtz
+# cflags and ldflags are used so that users specifying CFLAGS and LDFLAGS do not override my flags
+# += is not used, because gcc usually accepts last option, for example -O0 -O2 will use -O2
+.NOTPARALLEL:
+$(PROJ): vertex_shader.o fragment_shader.o $(PROJ).c
+ # $(CC) -c -DIX_LIB $(cflags) $(CFLAGS) $(PROJ).c
+ # $(CC) -shared -olib$(PROJ).so $(PROJ).o
+ # $(CC) -L. $(cflags) $(CFLAGS) $(PROJ).c -l$(PROJ) $(ldflags) -o$(PROJ)
+ $(CC) $(cflags) $(CFLAGS) $(PROJ).c $(ldflags) -o$(PROJ) *_shader.o
+
+%_shader.o: %.glsl
+ ld -r -b binary -o $@ $<
+
+install:
+ mkdir -p $(DESTDIR)/usr/bin # $(DESTDIR)/etc $(DESTDIR)/usr/include $(DESTDIR)/usr/lib
+ cp $(PROJ) $(DESTDIR)/usr/bin/
+ # cp $(PROJ).conf $(DESTDIR)/etc/$(PROJ)
+ # cp lib$(PROJ).so $(DESTDIR)/usr/lib/
+ # cp $(PROJ).h $(DESTDIR)/usr/include/
+
+distclean: clean
+
+clean:
+ rm -f $(PROJ) # $(PROJ).o lib$(PROJ).so
+
+uninstall:
+ rm -f $(DESTDIR)/usr/bin/$(PROJ) # $(DESTDIR)/etc/$(PROJ) $(DESTDIR)/usr/include/$(PROJ).h $(DESTDIR)/usr/lib/lib$(PROJ).so
+
+valgrind:
+ valgrind --leak-check=full --show-leak-kinds=all --track-origins=yes --verbose --log-file=valgrind-out.txt $(COMMAND)
+
+test:
+ ld -r -b binary -o vertex_shader.o vertex.glsl
+ gcc -Wall -Wextra -pedantic -Wformat -Wformat-security -g3 -O0 -otest test.c vertex_shader.o
+
+.PHONY: valgrind clean distclean install uninstall default test
diff --git a/fiz/naloga/gl/fragment.glsl b/fiz/naloga/gl/fragment.glsl
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/fiz/naloga/gl/fragment.glsl
diff --git a/fiz/naloga/gl/helmholtz.c b/fiz/naloga/gl/helmholtz.c
new file mode 100644
index 0000000..7d8171b
--- /dev/null
+++ b/fiz/naloga/gl/helmholtz.c
@@ -0,0 +1,89 @@
+#include <stdlib.h>
+#include <stdio.h>
+#include <complex.h>
+#include <unistd.h>
+#include <GL/glxew.h>
+#include <GLFW/glfw3.h>
+extern char _binary_vertex_glsl_start[];
+extern char _binary_vertex_glsl_end[];
+extern char _binary_fragment_glsl_start[];
+extern char _binary_fragment_glsl_end[];
+void error_callback (int error, const char * description) {
+ fprintf(stderr, "error_callback: %s, error == %d\n", description, error);
+}
+void key_callback (GLFWwindow * okno, int tipka, int koda, int dejanje, int modifikatorji) {
+ fprintf(stderr, "tipka %d, koda %d, dejanje %d, modifikatorji %d, okno %p\n",
+ tipka, koda, dejanje, modifikatorji, (void *) okno);
+}
+int main (void) {
+ GLint vertex_len = _binary_vertex_glsl_end - _binary_vertex_glsl_start;
+ GLint fragment_len = _binary_fragment_glsl_end - _binary_fragment_glsl_start;
+ if (!glfwInit()) {
+ fprintf(stderr, "glfwInit failed\n");
+ return 1;
+ }
+ glfwSetErrorCallback(error_callback);
+ glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 1);
+ glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 4);
+ // glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); // forward compat is ogl 3.0+
+ GLFWwindow * okno = glfwCreateWindow(800, 600, "okno", NULL, NULL);
+ if (!okno) {
+ fprintf(stderr, "glfwCreateWindow failed\n");
+ glfwTerminate();
+ return 2;
+ }
+ glfwMakeContextCurrent(okno);
+ GLenum err = glewInit();
+ if (err != GLEW_OK) {
+ fprintf(stderr, "glewInit failed: %s\n", glewGetErrorString(err));
+ return 3;
+ }
+ glfwSwapInterval(1); // vsync
+ glfwSetKeyCallback(okno, key_callback);
+ GLuint program = glCreateProgram();
+#define DO_SHADER(whi, WHI) \
+ GLuint whi##_shader = glCreateShader(GL_##WHI##_SHADER); \
+ glShaderSource(whi##_shader, 1, (const GLchar **) &_binary_##whi##_glsl_start, &whi##_len); \
+ glCompileShader(whi##_shader); \
+ GLint whi##_success = 0; \
+ glGetShaderiv(whi##_shader, GL_COMPILE_STATUS, &whi##_success); \
+ if (whi##_success == GL_FALSE) { \
+ GLint logSize = 0; \
+ glGetShaderiv(whi##_shader, GL_INFO_LOG_LENGTH, &logSize); \
+ char infoLog[logSize]; \
+ glGetShaderInfoLog(whi##_shader, logSize, &logSize, infoLog); \
+ fprintf(stderr, "prevod shaderja ni uspel. dnevnik:\n%s\n", infoLog); \
+ glDeleteShader(whi##_shader); \
+ return 4; \
+ } \
+ glAttachShader(program, whi##_shader);
+ DO_SHADER(vertex, VERTEX);
+ DO_SHADER(fragment, FRAGMENT);
+ glLinkProgram(program);
+ GLint isLinked = 0;
+ glGetProgramiv(program, GL_LINK_STATUS, &isLinked);
+ if (isLinked == GL_FALSE) {
+ GLint logSize = 0;
+ glGetProgramiv(program, GL_INFO_LOG_LENGTH, &logSize);
+ char infoLog[logSize];
+ glGetProgramInfoLog(program, logSize, &logSize, infoLog);
+ fprintf(stderr, "linkanje programa ni uspelo. dnevnik:\n%s\n", infoLog);
+ glDeleteShader(vertex_shader);
+ glDeleteShader(fragment_shader);
+ glDeleteProgram(program);
+ return 5;
+ }
+ glDetachShader(program, vertex_shader); // TODO: ali lahko glDeleteShader po linku?
+ glDetachShader(program, fragment_shader);
+ while (!glfwWindowShouldClose(okno)) {
+ int w, h;
+ glfwGetFramebufferSize(okno, &w, &h);
+ glViewport(0, 0, w, h);
+
+ glfwSwapBuffers(okno);
+ glfwWaitEvents(); // glfwPollEvents pa returna takoj
+ }
+ glfwDestroyWindow(okno);
+ glfwTerminate();
+ return 0;
+}
diff --git a/fiz/naloga/gl/test.c b/fiz/naloga/gl/test.c
new file mode 100644
index 0000000..7aff87c
--- /dev/null
+++ b/fiz/naloga/gl/test.c
@@ -0,0 +1,7 @@
+#include <stdio.h>
+extern char _binary_vertex_glsl_start[];
+extern char _binary_vertex_glsl_end[];
+int main (void) {
+ fwrite(_binary_vertex_glsl_start, (_binary_vertex_glsl_end - _binary_vertex_glsl_start), 1, stdout);
+ return 0;
+}
diff --git a/fiz/naloga/gl/vertex.glsl b/fiz/naloga/gl/vertex.glsl
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/fiz/naloga/gl/vertex.glsl