implement some basic rendering boilerplate

This commit is contained in:
Quinn
2025-04-13 01:04:27 +02:00
committed by Quinn
parent 538f20f733
commit ef0063d9aa
3 changed files with 51 additions and 5 deletions

View File

@@ -1,10 +1,25 @@
#include "GLFW/glfw3.h"
#include "error.h"
#include "window/render.h"
struct renderdat rdat; // contains the relevant data needed for rendering, contains rubbish data until init was
static inline int init(void) {
glfwInitHint(GLFW_JOYSTICK_HAT_BUTTONS, GLFW_FALSE); // disable joystick buttons
if (!glfwInit()) return 1; // initialize GLFW
if (render_init(&rdat)) return 1; // initialize the rendering and create a window
return 0;
}
static inline void quit(void) {
glfwTerminate();
}
int main(int argc, char** argv) {
(void)argc, (void)argv;
debug("%s", "owo");
info("%s", "owo");
warn("%s", "owo");
error("%s", "owo");
fatal("%s", "owo");
if (init()) fatal("failed to initialize!");
while (1);
quit();
}

21
src/window/render.c Normal file
View File

@@ -0,0 +1,21 @@
#include "render.h"
#include <GLFW/glfw3.h>
#include <stdlib.h>
// macros for ease of access
#define WIN_NAME "MCA Selector Lite"
#define WIN_DEFAULT_WIDTH 640
#define WIN_DEFAULT_HEIGHT 480
int render_init(struct renderdat* restrict rdat) {
GLFWwindow* const win = glfwCreateWindow(WIN_DEFAULT_WIDTH, WIN_DEFAULT_HEIGHT, WIN_NAME, NULL, NULL);
if (win == NULL) return 1;
rdat->win = win;
return 0;
}
void render_free(struct renderdat* restrict rdat) {
glfwDestroyWindow(rdat->win);
}

10
src/window/render.h Normal file
View File

@@ -0,0 +1,10 @@
#pragma once
#include <GLFW/glfw3.h>
struct renderdat {
GLFWwindow* win;
};
int render_init(struct renderdat* restrict rdat);
void render_free(struct renderdat* restrict rdat);