remove glfw+gl from forge.c
This commit is contained in:
+11
-30
@@ -1,5 +1,3 @@
|
||||
#include <GLFW/glfw3.h>
|
||||
#include <glad/gl.h>
|
||||
#include <linmath.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
@@ -12,47 +10,30 @@
|
||||
|
||||
void error_callback(int error, const char *description) {
|
||||
fprintf(stderr, "Error %d: %s\n", error, description);
|
||||
glfwTerminate();
|
||||
close_window(0, true);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
static void key_callback(Window *window, int key,
|
||||
__attribute__((unused)) int scancode, int action,
|
||||
int mods) {
|
||||
__attribute__((unused)) int mods) {
|
||||
// close window on escape key
|
||||
if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS && mods == 0) {
|
||||
glfwSetWindowShouldClose(window, GLFW_TRUE);
|
||||
if (escape_key(key, action)) {
|
||||
close_window(window, false);
|
||||
}
|
||||
}
|
||||
|
||||
void loop(Window *window, ShaderProgram program) {
|
||||
// TODO remove GLFW references
|
||||
// TODO split into smaller functions
|
||||
int width, height;
|
||||
glfwGetFramebufferSize(window, &width, &height);
|
||||
vec2 resolution = {(float)width, (float)height};
|
||||
Context context;
|
||||
|
||||
glViewport(0, 0, width, height);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
context = get_window_context(window);
|
||||
|
||||
mat4x4 m, p, mvp;
|
||||
mat4x4_identity(m);
|
||||
mat4x4_ortho(p, 0.0f, 1.0f, 0.0f, 1.0f, 1.0f, 0.0f);
|
||||
mat4x4_mul(mvp, p, m);
|
||||
apply_program(program, context);
|
||||
|
||||
glUseProgram(program.program);
|
||||
glUniformMatrix4fv(program.mvp_location, 1, GL_FALSE, (const GLfloat *)&mvp);
|
||||
glUniform1f(program.itime_location, (const GLfloat)glfwGetTime());
|
||||
glUniform2fv(program.ires_location, 1, (const GLfloat *)&resolution);
|
||||
glBindVertexArray(program.vertex_array);
|
||||
glDrawArrays(GL_TRIANGLES, 0, 6);
|
||||
|
||||
glfwSwapBuffers(window);
|
||||
glfwPollEvents();
|
||||
update_window(window);
|
||||
}
|
||||
|
||||
void forge_run(Parameters params) {
|
||||
// TODO remove GLFW references
|
||||
Window *window;
|
||||
|
||||
File fragment_shader = read_file(params.frag_path);
|
||||
@@ -68,11 +49,11 @@ void forge_run(Parameters params) {
|
||||
|
||||
if (program.error) {
|
||||
fprintf(stderr, "Failed to compile shaders\n");
|
||||
glfwTerminate();
|
||||
close_window(window, true);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
while (!glfwWindowShouldClose(window)) {
|
||||
while (!window_should_close(window)) {
|
||||
if (params.hot_reload && should_update_file(&fragment_shader)) {
|
||||
update_file(&fragment_shader);
|
||||
update_program(program, fragment_shader);
|
||||
@@ -80,7 +61,7 @@ void forge_run(Parameters params) {
|
||||
loop(window, program);
|
||||
}
|
||||
|
||||
glfwTerminate();
|
||||
close_window(window, true);
|
||||
|
||||
free_file(&fragment_shader);
|
||||
}
|
||||
Reference in New Issue
Block a user