Delete all rendering / graphics code.

Whilst it was fun to experiment with OpenGL, I do not see myself
maintaining a codebase using that, when all I do is draw bloody pixels
to a buffer.
Thus begins the search for a... more suitable graphical framework.
This commit is contained in:
2026-01-22 15:26:11 +01:00
parent d81502588f
commit ebcd150415
16 changed files with 7 additions and 3829 deletions

View File

@@ -1,17 +0,0 @@
/* This file is part of MCA-Selector-lite,
* and is licensed under GPL-2.0-only.
* Copyright (C)2025 quinnthepigeon@proton.me Quinn
* For further information, view COPYING and CONTRIBUTORS
* at: www.github.com/thepigeongenerator/mcaselector-lite */
#include "input.h"
#include <GLFW/glfw3.h>
void input_callback(GLFWwindow *win, int key, int scancode, int action, int mods)
{
(void)win, (void)key, (void)scancode, (void)action, (void)mods; // make the compiler shut up as this is fine
#ifndef NDEBUG
if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS)
glfwSetWindowShouldClose(win, 1);
#endif
}

View File

@@ -1,12 +0,0 @@
/* This file is part of MCA-Selector-lite,
* and is licensed under GPL-2.0-only.
* Copyright (C)2025 quinnthepigeon@proton.me Quinn
* For further information, view COPYING and CONTRIBUTORS
* at: www.github.com/thepigeongenerator/mcaselector-lite */
#pragma once
#include <GLFW/glfw3.h>
/* Handles incoming key inputs for `win`.
* Intended to be given as an argument to `glfwSetKeyCallback`. */
void input_callback(GLFWwindow *win, int key, int scancode, int action, int mods);

View File

@@ -1,97 +0,0 @@
/* This file is part of MCA-Selector-lite,
* and is licensed under GPL-2.0-only.
* Copyright (C)2025 quinnthepigeon@proton.me Quinn
* For further information, view COPYING and CONTRIBUTORS
* at: www.github.com/thepigeongenerator/mcaselector-lite */
#include "render.h"
#include <GLFW/glfw3.h>
#include <glad/gl.h>
#include <mcaselector-lite/types.h>
#include <stdint.h>
#include "../../util/error.h"
#include "shader.h"
#define VERTC 3
static GLuint pipe;
static GLuint vbo; // vertex buffer object
static GLuint vao; // vertex array object
static GLuint screen_loc; // location to where OpenGL sends to the shaders of the screen dimensions
static int win_w, win_h;
static void screen_resize(int w, int h)
{
s32 verts[VERTC][4] = {
{0, 0, w, 20 },
{0, 20, w, h - 40},
{0, h, w, -20 },
};
glUniform2i(screen_loc, w, h); // send the screen dimensions to the shader pipeline
glViewport(0, 0, w, h); // update the viewport
glBufferData(GL_ARRAY_BUFFER, sizeof(verts), verts, GL_DYNAMIC_DRAW); // bind the data to it
win_w = w;
win_h = h;
}
int render_init(void)
{
pipe = glCreateProgram();
shader_init(pipe); // initialise and include the shaders
glLinkProgram(pipe); // link the application
glValidateProgram(pipe); // validate that what we've done is correct
int len;
glGetProgramiv(pipe, GL_INFO_LOG_LENGTH, &len);
if (len > 0) {
char log[len];
glGetProgramInfoLog(pipe, len, &len, log);
log[len - 1] = '\0'; // terminate the string one character sooner since the log includes a newline
fatal("error whilst linking the pipe: '%s'", log);
}
screen_loc = glGetUniformLocation(pipe, "screen");
glGenBuffers(1, &vbo); // create the vertex buffer objects
glBindBuffer(GL_ARRAY_BUFFER, vbo); // bind to it
glGenVertexArrays(1, &vao);
glBindVertexArray(vao);
// set VBO info
glBindBuffer(GL_ARRAY_BUFFER, vbo);
glEnableVertexAttribArray(0); // set the array data index to 0
glVertexAttribIPointer(0, 4, GL_INT, 4 * sizeof(s32), NULL);
glBindVertexArray(0);
return 0;
}
void render_update(GLFWwindow *win)
{
glDisable(GL_DEPTH_TEST);
glDisable(GL_CULL_FACE);
int w, h;
glfwGetWindowSize(win, &w, &h);
glUseProgram(pipe);
if (w != win_w || h != win_h)
screen_resize(w, h);
glClearColor(0.1F, 0.1F, 0.1F, 1.0F);
glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
glBindVertexArray(vao);
glDrawArrays(GL_POINTS, 0, VERTC);
}
void render_free(void)
{
glDeleteVertexArrays(1, &vao);
glDeleteBuffers(1, &vbo);
glDeleteProgram(pipe);
vbo = 0;
vao = 0;
pipe = 0;
}

View File

@@ -1,13 +0,0 @@
/* This file is part of MCA-Selector-lite,
* and is licensed under GPL-2.0-only.
* Copyright (C)2025 quinnthepigeon@proton.me Quinn
* For further information, view COPYING and CONTRIBUTORS
* at: www.github.com/thepigeongenerator/mcaselector-lite */
#pragma once
#include <GLFW/glfw3.h>
#include <glad/gl.h>
int render_init(void);
void render_update(GLFWwindow *win);
void render_free(void);

View File

@@ -1,59 +0,0 @@
/* This file is part of MCA-Selector-lite,
* and is licensed under GPL-2.0-only.
* Copyright (C)2025 quinnthepigeon@proton.me Quinn
* For further information, view COPYING and CONTRIBUTORS
* at: www.github.com/thepigeongenerator/mcaselector-lite */
#include "shader.h"
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include "../../util/error.h"
// NOTE: we are currently just sucking up the memory costs for ease. We can either include the source files themselves. Or use compression, where I'd prefer the latter for ease of installation.
extern const char sh_vert_glsl[];
extern const char sh_frag_glsl[];
extern const char sh_geom_glsl[];
extern const uint sh_vert_glsl_len;
extern const uint sh_frag_glsl_len;
extern const uint sh_geom_glsl_len;
/* Compiles a shader of `type` from `src` with `len` bytes.
* Returns the integer for the shader. */
static GLuint shader_compile(GLenum type, const char *src, usize len)
{
int ilen = len;
GLuint shader = glCreateShader(type);
glShaderSource(shader, 1, &src, &ilen);
glCompileShader(shader);
// repurposing ilen for the max length of the shader log
glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &ilen);
if (ilen > 0) {
char log[ilen];
glGetShaderInfoLog(shader, ilen, &ilen, log);
log[ilen - 1] = '\0'; // terminate the string one character sooner since the log includes a newline
error("error whilst compiling shader type '0x%X': '%s'", type, log);
}
return shader;
}
int shader_init(GLuint pipe)
{
GLuint vs = shader_compile(GL_VERTEX_SHADER, sh_vert_glsl, sh_vert_glsl_len);
GLuint fs = shader_compile(GL_FRAGMENT_SHADER, sh_frag_glsl, sh_frag_glsl_len);
GLuint gs = shader_compile(GL_GEOMETRY_SHADER, sh_geom_glsl, sh_geom_glsl_len);
glAttachShader(pipe, vs);
glAttachShader(pipe, fs);
glAttachShader(pipe, gs);
// mark shaders off for deletion
glDeleteShader(vs);
glDeleteShader(fs);
glDeleteShader(gs);
return 1;
}

View File

@@ -1,13 +0,0 @@
/* This file is part of MCA-Selector-lite,
* and is licensed under GPL-2.0-only.
* Copyright (C)2025 quinnthepigeon@proton.me Quinn
* For further information, view COPYING and CONTRIBUTORS
* at: www.github.com/thepigeongenerator/mcaselector-lite */
#pragma once
#include <glad/gl.h>
#include <stddef.h>
#include <stdint.h>
/* Initialises the (embedded) shaders onto `pipe` */
int shader_init(GLuint pipe);

View File

@@ -1,91 +0,0 @@
/* This file is part of MCA-Selector-lite,
* and is licensed under GPL-2.0-only.
* Copyright (C)2025 quinnthepigeon@proton.me Quinn
* For further information, view COPYING and CONTRIBUTORS
* at: www.github.com/thepigeongenerator/mcaselector-lite */
#include "window.h"
#include <GLFW/glfw3.h>
#include <assert.h>
#include <glad/gl.h>
#include <mcaselector-lite/types.h>
#include "../../util/error.h"
#include "input.h"
#include "render.h"
static struct GLFWwindow *win = NULL;
/* Initialises the GLFW window with some defaults,
* then proceed to activate OpenGL on it. */
int window_init(void)
{
// initialise the window
#ifndef NDEBUG
glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, GLFW_TRUE);
#endif
glfwWindowHint(GLFW_RESIZABLE, GLFW_TRUE);
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, 1);
glfwWindowHint(GLFW_RED_BITS, 8);
glfwWindowHint(GLFW_GREEN_BITS, 8);
glfwWindowHint(GLFW_BLUE_BITS, 8);
glfwWindowHint(GLFW_ALPHA_BITS, 0);
/* NOTE: on my system; x86_64, GTX 1650 580.82.09-2, X11, i3, this causes one direct, 2 indirect memory leaks.
* This is not my fault, and can safely be ignored. */
win = glfwCreateWindow(640, 480, "MCA-Selector lite", NULL, NULL);
if (!win)
return 1;
glfwMakeContextCurrent(win);
if (!gladLoadGL(glfwGetProcAddress))
return 1;
glfwSwapInterval(1); // wait 1 screen update for a redraw a.k.a. "vsync". (not really applicable in this case but eh)
glfwSetKeyCallback(win, input_callback);
debug(
"version info:\n"
"\tvendor: %s\n"
"\trenderer: %s\n"
"\tversion: %s\n"
"\tshading lang: %s\n",
glGetString(GL_VENDOR),
glGetString(GL_RENDERER),
glGetString(GL_VERSION),
glGetString(GL_SHADING_LANGUAGE_VERSION));
return 0;
}
void window_loop(void)
{
assert(win);
render_init();
while (!glfwWindowShouldClose(win)) {
glfwWaitEvents();
render_update(win);
glfwSwapBuffers(win);
glfwPollEvents();
}
}
void window_close(void)
{
assert(win);
glfwSetWindowShouldClose(win, 1);
}
void window_free(void)
{
if (!win) {
debug("window has already been freed.");
return;
}
glfwDestroyWindow(win);
render_free();
win = NULL;
}

View File

@@ -1,22 +0,0 @@
/* This file is part of MCA-Selector-lite,
* and is licensed under GPL-2.0-only.
* Copyright (C)2025 quinnthepigeon@proton.me Quinn
* For further information, view COPYING and CONTRIBUTORS
* at: www.github.com/thepigeongenerator/mcaselector-lite */
#pragma once
/* Set up the window, enabling OpenGL, and
* configuring the settings that are needed.
* Returns `0` upon success, otherwise `1`. */
int window_init(void);
/* Calls the update loop for the window.
* This function does not exit until the window does. */
void window_loop(void);
/* Requests the window to close (gracefully). */
void window_close(void);
/* Cleans up all resources held by the window.
* If the window is still open, it will be terminated. */
void window_free(void);

View File

@@ -3,29 +3,11 @@
* Copyright (C)2025 quinnthepigeon@proton.me Quinn
* For further information, view COPYING and CONTRIBUTORS
* at: www.github.com/thepigeongenerator/mcaselector-lite */
#include <GLFW/glfw3.h>
#include <glad/gl.h>
#include <stdio.h>
#include <stdlib.h>
#include "io/win/window.h"
#include "util/error.h"
/* reroutes GLFW errors to our logging system. */
static void error_callback(int err, const char *const msg)
{
error("glfw returned (%i); \"%s\"", err, msg);
}
static void quit(void)
{
window_free();
/* terminates GLFW; destroying any
* remaining windows, or other resources held by GLFW. */
glfwTerminate();
}
#if __has_extension(c_static_assert)
__extension__ _Static_assert(-3 >> 5 == -1,
"The platform does not compile right-shifting signed integers to an arithmetic shift!");
@@ -36,14 +18,7 @@ int main(int argc, char **argv)
{
(void)argc, (void)argv;
printf("debug: [DBG], info: [INF], warning: [WAR], error: [ERR], fatal: [FAT]\n");
atexit(quit);
glfwSetErrorCallback(error_callback);
glfwInitHint(GLFW_JOYSTICK_HAT_BUTTONS, GLFW_FALSE); // disable joystick buttons; since we won't need them
if (!glfwInit() || window_init())
fatal("failed to initialise!");
window_loop();
// atexit(quit);
/* return success, since some architectures do not follow 0=success
* This action will call `quit`. */