summaryrefslogtreecommitdiff
path: root/main.c
diff options
context:
space:
mode:
authorMoritz Ruge <ruge.moritz@gmail.com>2026-08-06 13:57:18 +0200
committerMoritz Ruge <ruge.moritz@gmail.com>2026-08-06 16:36:08 +0200
commit6fd20124218af64fd4c56ba5a62bcec6ab9c2cb3 (patch)
tree56cfe504f2c2dfbfcb30b036e10b32e3f435fc49 /main.c
parent9f6786eb6276aeb8ab4d4a7969b1fc9874336e86 (diff)
init 2
Diffstat (limited to 'main.c')
-rw-r--r--main.c88
1 files changed, 88 insertions, 0 deletions
diff --git a/main.c b/main.c
new file mode 100644
index 0000000..32aff4e
--- /dev/null
+++ b/main.c
@@ -0,0 +1,88 @@
+#include <KHR/khrplatform.h>
+#define GLFW_INCLUDE_NONE
+#include <glad/glad.h>
+#include <GLFW/glfw3.h>
+#include <GL/gl.h>
+#include <stdio.h>
+
+// struct and function declaration
+// ----------------------------------------------------------------------------
+void framebuffer_size_callback(GLFWwindow* window, int width, int height);
+void processInput(GLFWwindow* window);
+// ----------------------------------------------------------------------------
+// END
+
+int main(void) {
+
+ // GLFW settings init and which version of opengl we should use
+ // and which subset of opengl profiles
+ glfwInit();
+ glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
+ glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 4);
+ glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
+
+
+
+ // Window settings
+ // create window
+ int w_height = 1280;
+ int w_width = 820;
+ GLFWwindow* window = glfwCreateWindow(w_height, w_width, "Test", NULL, NULL);
+ if (window == NULL) {
+ printf("Failed to create GLFW window\n");
+ glfwTerminate();
+ glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
+ return -1;
+ }
+ // init window
+ glfwMakeContextCurrent(window);
+
+ // init GLAD
+ if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)) {
+ printf("Failed to initialize GLAD\n");
+ return -1;
+ }
+
+ // opengl viewport
+ framebuffer_size_callback(window, w_width, w_height);
+
+ // -------------------------------------------------------------------------
+ // render loop
+ // -------------------------------------------------------------------------
+ while (!glfwWindowShouldClose(window)) {
+ // input
+ processInput(window);
+
+ // rendering commands here
+ // -----------------------
+ glClearColor(0.2f, 0.3f, 0.3f, 1.0f);
+ glClear(GL_COLOR_BUFFER_BIT);
+
+ // check and call events and swap the buffers
+ glfwSwapBuffers(window);
+ glfwPollEvents();
+ }
+
+ glfwTerminate();
+ return 0;
+}
+
+// END render loop
+// -----------------------------------------------------------------------------
+
+// Functions
+// -----------------------------------------------------------------------------
+// glfw: whenever the window size changed (by OS or user resize) this callback function executes
+// ---------------------------------------------------------------------------------------------
+void framebuffer_size_callback(GLFWwindow* window, int width, int height) {
+ glViewport(0, 0, width, height);
+}
+
+// process all input: query GLFW whether relevant keys are pressed/released this frame and react accordingly
+// ---------------------------------------------------------------------------------------------------------
+void processInput(GLFWwindow* window) {
+ if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS) glfwSetWindowShouldClose(window, 1);
+ if (glfwGetKey(window, GLFW_KEY_Q) == GLFW_PRESS) glfwSetWindowShouldClose(window, 1);
+}
+
+