mirror of
https://github.com/thepigeongenerator/mcaselector-lite.git
synced 2025-12-16 19:45:46 +01:00
handle window exits more gracefully and appropriately.
This commit is contained in:
@@ -2,9 +2,8 @@
|
||||
* Licensed under the MIT Licence. See LICENSE for details */
|
||||
#include "render.h"
|
||||
|
||||
#include <glad/gl.h>
|
||||
|
||||
#include <GLFW/glfw3.h>
|
||||
#include <glad/gl.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "../error.h"
|
||||
@@ -80,3 +79,12 @@ void render_update(GLFWwindow *win) {
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
* Licensed under the MIT Licence. See LICENSE for details */
|
||||
#pragma once
|
||||
|
||||
#include <glad/gl.h>
|
||||
|
||||
#include <GLFW/glfw3.h>
|
||||
#include <glad/gl.h>
|
||||
|
||||
int render_init(void);
|
||||
void render_update(GLFWwindow *win);
|
||||
void render_free(void);
|
||||
|
||||
@@ -69,5 +69,13 @@ void window_loop(void) {
|
||||
glfwSwapBuffers(win);
|
||||
}
|
||||
|
||||
glfwDestroyWindow(win);
|
||||
void window_close(void) {
|
||||
assert(win);
|
||||
glfwSetWindowShouldClose(win, 1);
|
||||
}
|
||||
|
||||
void window_free(void) {
|
||||
glfwDestroyWindow(win);
|
||||
render_free();
|
||||
win = NULL;
|
||||
}
|
||||
|
||||
@@ -2,5 +2,18 @@
|
||||
* Licensed under the MIT Licence. See LICENSE for details */
|
||||
#pragma once
|
||||
|
||||
int window_init(void); // initializes the global window, returns non-zero upon failure
|
||||
void window_loop(void); // performs the window updates
|
||||
/* 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);
|
||||
|
||||
@@ -14,6 +14,10 @@ static void error_callback(int err, const char *const msg) {
|
||||
}
|
||||
|
||||
static void quit(void) {
|
||||
window_free();
|
||||
|
||||
/* terminates GLFW; destroying any
|
||||
* remaining windows, or other resources held by GLFW. */
|
||||
glfwTerminate();
|
||||
}
|
||||
|
||||
@@ -30,7 +34,7 @@ int main(int argc, char **argv) {
|
||||
fatal("failed to initialise!");
|
||||
|
||||
window_loop();
|
||||
quit();
|
||||
window_free();
|
||||
|
||||
// return success, since some architectures do not follow 0=success
|
||||
return EXIT_SUCCESS;
|
||||
|
||||
Reference in New Issue
Block a user