diff options
Diffstat (limited to 'gltest.c')
-rw-r--r-- | gltest.c | 51 |
1 files changed, 7 insertions, 44 deletions
@@ -7,6 +7,7 @@ #include "eprintf.h" #include "gldefs.h" +#include "glprog.h" #include "linmath.h" #include "loadgl.h" #include "shaders.h" @@ -14,7 +15,6 @@ enum { WIDTH = 800, HEIGHT = 600, - LOGSIZE = 1024, }; void fb_size_cb(GLFWwindow *win, int width, int height) @@ -29,53 +29,12 @@ void take_input(GLFWwindow *win) glfwSetWindowShouldClose(win, true); } -GLuint load_shader(GLenum type, const char *data, GLint size) -{ - GLuint shdr; - GLint success; - char log[LOGSIZE]; - - shdr = gl_shdr_create(type); - gl_shdr_source(shdr, 1, &data, &size); - gl_shdr_compile(shdr); - gl_shdr_param(shdr, GL_COMPILE_STATUS, &success); - - if (!success) { - gl_shdr_infolog(shdr, sizeof log, NULL, log); - eprintf("Failed to compile shader:\n%s", log); - } - - return shdr; -} - -GLuint load_prog(void) -{ - GLuint vert, frag, prog; - GLuint success; - char log[LOGSIZE]; - - vert = load_shader(GL_VERTEX_SHADER, shader_vert_data, shader_vert_size); - frag = load_shader(GL_FRAGMENT_SHADER, shader_frag_data, shader_frag_size); - prog = gl_prog_create(); - gl_prog_attachshdr(prog, vert); - gl_prog_attachshdr(prog, frag); - gl_prog_link(prog); - gl_prog_param(prog, GL_COMPILE_STATUS, &success); - if (!success) { - gl_prog_infolog(prog, sizeof log, NULL, log); - eprintf("Failed to link program:\n%s", log); - } - gl_shdr_del(vert); - gl_shdr_del(frag); - - return prog; -} - int main(int argc, char **argv) { GLFWwindow *win; int ret; GLuint ebo, vbo, vao, prog; + GLint ucolor; vec3 verts[] = { { 0.5f, 0.5f, 0.0f }, { 0.5f, -0.5f, 0.0f }, @@ -121,7 +80,11 @@ int main(int argc, char **argv) gl_va_define(0, 3, GL_FLOAT, GL_FALSE, sizeof *verts, 0); gl_va_enable(0); - prog = load_prog(); + prog = glprog_load(2, (struct shdrdat []){ + { GL_VERTEX_SHADER, shader_vert_data, shader_vert_size }, + { GL_FRAGMENT_SHADER, shader_frag_data, shader_frag_size }, + }, + 1, &(struct unidat){ "ucolor", &ucolor }); gl_poly_mode(GL_FRONT_AND_BACK, GL_LINE); |