From 6d17b081cc16b0ba13ab918e885674b2defa8280 Mon Sep 17 00:00:00 2001 From: Tomasz Kramkowski Date: Fri, 30 Mar 2018 15:50:27 +0100 Subject: Rename project gltest -> faqe The project has been renamed to faqe. The logic for this name: quake -> fake quake -> faqe --- .gitignore | 2 +- Makefile | 6 ++-- faqe.c | 111 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ gltest.c | 111 ------------------------------------------------------------- 4 files changed, 115 insertions(+), 115 deletions(-) create mode 100644 faqe.c delete mode 100644 gltest.c diff --git a/.gitignore b/.gitignore index 8365d9f..76747f5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,5 @@ *.o -gltest +faqe *.exe *.dll diff --git a/Makefile b/Makefile index 6810635..839b032 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,7 @@ # SPDX-License-Identifier: MIT -include config.mk -PROG := gltest +PROG := faqe EPRINTF_PATH ?= ../eprintf PKG_CONFIG ?= pkg-config @@ -14,7 +14,7 @@ CFLAGS += $(shell $(PKG_CONFIG) --cflags $(LIBS)) -std=c11 -MMD -MP LDFLAGS += -Wl,--as-needed LDLIBS += $(shell $(PKG_CONFIG) --libs $(LIBS)) -lm -OBJ := gltest.o gl.o eprintf.o glprog.o +OBJ := faqe.o gl.o eprintf.o glprog.o all: $(PROG) @@ -22,7 +22,7 @@ include assets.mk include $(EPRINTF_PATH)/module.mk $(PROG): $(OBJ) -gltest.o: assets.h +faqe.o: assets.h deplinks: $(EPRINTF_FILES) diff --git a/faqe.c b/faqe.c new file mode 100644 index 0000000..0a9ab7d --- /dev/null +++ b/faqe.c @@ -0,0 +1,111 @@ +/* + * Copyright (C) 2018 Tomasz Kramkowski + * SPDX-License-Identifier: MIT + */ +#include +#include + +#include "assets.h" +#include "eprintf.h" +#include "gl.h" +#include "glprog.h" +#include "linmath.h" +#include "nelem.h" + +enum { + WIDTH = 800, + HEIGHT = 600, +}; + +void fb_size_cb(GLFWwindow *win, int width, int height) +{ + (void)win; + gl_viewport(0, 0, width, height); +} + +void take_input(GLFWwindow *win) +{ + if (glfwGetKey(win, GLFW_KEY_ESCAPE) == GLFW_PRESS) + glfwSetWindowShouldClose(win, true); +} + +int main(int argc, char **argv) +{ + GLFWwindow *win; + GLuint ebo, vbo, vao, prog; + GLint ucolor; + struct vertex { + vec3 pos; + vec3 col; + vec2 uv; + } verts[] = { + {{ 0.5, 0.5, 0.0 }, { 1.0, 0.0, 0.0 }, { 1.0, 1.0 }}, + {{ 0.5, -0.5, 0.0 }, { 0.0, 1.0, 0.0 }, { 1.0, 0.0 }}, + {{ -0.5, -0.5, 0.0 }, { 0.0, 0.0, 1.0 }, { 0.0, 0.0 }}, + {{ -0.5, 0.5, 0.0 }, { 1.0, 1.0, 0.0 }, { 0.0, 1.0 }}, + }; + GLuint idxs[] = { + 0, 1, 3, + 1, 2, 3, + }; + + setprogname(argc >= 1 && argv[0] != NULL ? argv[0] : "faqe"); + + glfwInit(); + + glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); + glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); + glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); + + win = glfwCreateWindow(WIDTH, HEIGHT, "faqe", NULL, NULL); + if (win == NULL) + eprintf("Failed to create GLFW window"); + glfwMakeContextCurrent(win); + + gl_load((gl_loadfunc *)glfwGetProcAddress); + glfwSetFramebufferSizeCallback(win, &fb_size_cb); + fb_size_cb(win, WIDTH, HEIGHT); + + gl_buf_gen(1, &vbo); + gl_buf_gen(1, &ebo); + gl_va_gen(1, &vao); + + gl_va_bind(vao); + + gl_buf_bind(GL_ARRAY_BUFFER, vbo); + gl_buf_data(GL_ARRAY_BUFFER, sizeof verts, verts, GL_STATIC_DRAW); + + gl_buf_bind(GL_ELEMENT_ARRAY_BUFFER, ebo); + gl_buf_data(GL_ELEMENT_ARRAY_BUFFER, sizeof idxs, idxs, GL_STATIC_DRAW); + + gl_va_define(0, NELEM(verts[0].pos), GL_FLOAT, GL_FALSE, sizeof *verts, (void *)offsetof(struct vertex, pos)); + gl_va_enable(0); + gl_va_define(1, NELEM(verts[0].col), GL_FLOAT, GL_FALSE, sizeof *verts, (void *)offsetof(struct vertex, col)); + gl_va_enable(1); + gl_va_define(2, NELEM(verts[0].uv), GL_FLOAT, GL_FALSE, sizeof *verts, (void *)offsetof(struct vertex, uv)); + gl_va_enable(2); + + prog = glprog_load(2, (struct shdrdat []){ + { GL_VERTEX_SHADER, vert_glsl.data, vert_glsl.size }, + { GL_FRAGMENT_SHADER, frag_glsl.data, frag_glsl.size }, + }, + 1, &(struct unidat){ "ucolor", &ucolor }); + + gl_poly_mode(GL_FRONT_AND_BACK, GL_LINE); + + while (!glfwWindowShouldClose(win)) { + take_input(win); + + gl_clearcolor(0.2, 0.3, 0.3, 1.0); + gl_clear(GL_COLOR_BUFFER_BIT); + gl_prog_use(prog); + gl_va_bind(vao); + gl_draw_elems(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0); + gl_va_bind(0); + + glfwSwapBuffers(win); + glfwPollEvents(); + } + + glfwTerminate(); +} diff --git a/gltest.c b/gltest.c deleted file mode 100644 index 394162c..0000000 --- a/gltest.c +++ /dev/null @@ -1,111 +0,0 @@ -/* - * Copyright (C) 2018 Tomasz Kramkowski - * SPDX-License-Identifier: MIT - */ -#include -#include - -#include "assets.h" -#include "eprintf.h" -#include "gl.h" -#include "glprog.h" -#include "linmath.h" -#include "nelem.h" - -enum { - WIDTH = 800, - HEIGHT = 600, -}; - -void fb_size_cb(GLFWwindow *win, int width, int height) -{ - (void)win; - gl_viewport(0, 0, width, height); -} - -void take_input(GLFWwindow *win) -{ - if (glfwGetKey(win, GLFW_KEY_ESCAPE) == GLFW_PRESS) - glfwSetWindowShouldClose(win, true); -} - -int main(int argc, char **argv) -{ - GLFWwindow *win; - GLuint ebo, vbo, vao, prog; - GLint ucolor; - struct vertex { - vec3 pos; - vec3 col; - vec2 uv; - } verts[] = { - {{ 0.5, 0.5, 0.0 }, { 1.0, 0.0, 0.0 }, { 1.0, 1.0 }}, - {{ 0.5, -0.5, 0.0 }, { 0.0, 1.0, 0.0 }, { 1.0, 0.0 }}, - {{ -0.5, -0.5, 0.0 }, { 0.0, 0.0, 1.0 }, { 0.0, 0.0 }}, - {{ -0.5, 0.5, 0.0 }, { 1.0, 1.0, 0.0 }, { 0.0, 1.0 }}, - }; - GLuint idxs[] = { - 0, 1, 3, - 1, 2, 3, - }; - - setprogname(argc >= 1 && argv[0] != NULL ? argv[0] : "gltest"); - - glfwInit(); - - glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); - glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); - glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); - - win = glfwCreateWindow(WIDTH, HEIGHT, "gltest", NULL, NULL); - if (win == NULL) - eprintf("Failed to create GLFW window"); - glfwMakeContextCurrent(win); - - gl_load((gl_loadfunc *)glfwGetProcAddress); - glfwSetFramebufferSizeCallback(win, &fb_size_cb); - fb_size_cb(win, WIDTH, HEIGHT); - - gl_buf_gen(1, &vbo); - gl_buf_gen(1, &ebo); - gl_va_gen(1, &vao); - - gl_va_bind(vao); - - gl_buf_bind(GL_ARRAY_BUFFER, vbo); - gl_buf_data(GL_ARRAY_BUFFER, sizeof verts, verts, GL_STATIC_DRAW); - - gl_buf_bind(GL_ELEMENT_ARRAY_BUFFER, ebo); - gl_buf_data(GL_ELEMENT_ARRAY_BUFFER, sizeof idxs, idxs, GL_STATIC_DRAW); - - gl_va_define(0, NELEM(verts[0].pos), GL_FLOAT, GL_FALSE, sizeof *verts, (void *)offsetof(struct vertex, pos)); - gl_va_enable(0); - gl_va_define(1, NELEM(verts[0].col), GL_FLOAT, GL_FALSE, sizeof *verts, (void *)offsetof(struct vertex, col)); - gl_va_enable(1); - gl_va_define(2, NELEM(verts[0].uv), GL_FLOAT, GL_FALSE, sizeof *verts, (void *)offsetof(struct vertex, uv)); - gl_va_enable(2); - - prog = glprog_load(2, (struct shdrdat []){ - { GL_VERTEX_SHADER, vert_glsl.data, vert_glsl.size }, - { GL_FRAGMENT_SHADER, frag_glsl.data, frag_glsl.size }, - }, - 1, &(struct unidat){ "ucolor", &ucolor }); - - gl_poly_mode(GL_FRONT_AND_BACK, GL_LINE); - - while (!glfwWindowShouldClose(win)) { - take_input(win); - - gl_clearcolor(0.2, 0.3, 0.3, 1.0); - gl_clear(GL_COLOR_BUFFER_BIT); - gl_prog_use(prog); - gl_va_bind(vao); - gl_draw_elems(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0); - gl_va_bind(0); - - glfwSwapBuffers(win); - glfwPollEvents(); - } - - glfwTerminate(); -} -- cgit v1.2.3-54-g00ecf