summaryrefslogtreecommitdiffstats
path: root/fiz/naloga/gl/helmholtz.c
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 /fiz/naloga/gl/helmholtz.c
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
Diffstat (limited to 'fiz/naloga/gl/helmholtz.c')
-rw-r--r--fiz/naloga/gl/helmholtz.c48
1 files changed, 44 insertions, 4 deletions
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
}