diff options
| author | 2026-11-07 16:58:45 +0000 | |
|---|---|---|
| committer | 2026-11-16 00:02:30 +0000 | |
| commit | 6fb035821f4a92f29ab245920d7fb8db69c0c9b9 (patch) | |
| tree | 838eabcf13d231cf43f7814bb33e6498e9d1f969 /src/main.c | |
Diffstat (limited to 'src/main.c')
| -rw-r--r-- | src/main.c | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/src/main.c b/src/main.c new file mode 100644 index 0000000..1675754 --- /dev/null +++ b/src/main.c @@ -0,0 +1,80 @@ +#include <stdio.h> +#include <string.h> + +#include "main.h" + +int main() +{ + if (!glfwPlatformSupported(GLFW_PLATFORM_WAYLAND)) { + printf("Wayland is not supported\n"); + return 1; + } + glfwInitHint(GLFW_PLATFORM, GLFW_PLATFORM_WAYLAND); + + if (!glfwInit()) { + printf("Failed to initialize GLFW\n"); + return 1; + } + glfwSetErrorCallback(error_callback); + + glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); + glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); + glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); + + GLFWwindow* window = glfwCreateWindow(800, 600, "LearnOpenGL", NULL, NULL); + if (window == NULL) { + printf("Failed to create GLFW window\n"); + glfwTerminate(); + return 1; + } + glfwMakeContextCurrent(window); + glfwSetFramebufferSizeCallback(window, framebuffer_size_callback); + + glViewport(0, 0, 800, 600); + + while(!glfwWindowShouldClose(window)) { + processInput(window); + + glClearColor(0.121f, 0.157f, 0.246f, 1.0f); + glClear(GL_COLOR_BUFFER_BIT); + + glfwSwapBuffers(window); + glfwPollEvents(); + } + glfwTerminate(); + + return 0; +} + +void error_callback(int error, const char* description) +{ + fprintf(stderr, "Error %d: %s\n", error, description); +} + +void framebuffer_size_callback(GLFWwindow* window, int width, int height) +{ + glViewport(0, 0, width, height); +} + +void processInput(GLFWwindow *window) +{ + if(glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS) + glfwSetWindowShouldClose(window, GLFW_TRUE); +} + +/* TODO */ +/* void hexToRGB(CRT_RGB* rgb, const char* hex) { */ +/* if (strlen(hex) == 0) { */ +/* printf("Invalid hex: %s", hex); */ +/* return; */ +/* } */ + +/* if (hex[0] != '#') { */ +/* printf("Invalid hex: %s", hex); */ +/* return; */ +/* } */ + +/* const char* r; */ +/* const char* g; */ +/* const char* b; */ +/* } */ |
