summaryrefslogtreecommitdiffstats
path: root/fiz/naloga/gl/helmholtz.c
diff options
context:
space:
mode:
Diffstat (limited to 'fiz/naloga/gl/helmholtz.c')
-rw-r--r--fiz/naloga/gl/helmholtz.c43
1 files changed, 35 insertions, 8 deletions
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();