mirror of
https://github.com/thepigeongenerator/mcaselector-lite.git
synced 2025-12-17 03:25:45 +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 */
|
* Licensed under the MIT Licence. See LICENSE for details */
|
||||||
#include "render.h"
|
#include "render.h"
|
||||||
|
|
||||||
#include <glad/gl.h>
|
|
||||||
|
|
||||||
#include <GLFW/glfw3.h>
|
#include <GLFW/glfw3.h>
|
||||||
|
#include <glad/gl.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
#include "../error.h"
|
#include "../error.h"
|
||||||
@@ -80,3 +79,12 @@ void render_update(GLFWwindow *win) {
|
|||||||
glBindVertexArray(vao);
|
glBindVertexArray(vao);
|
||||||
glDrawArrays(GL_POINTS, 0, VERTC);
|
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 */
|
* Licensed under the MIT Licence. See LICENSE for details */
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <glad/gl.h>
|
|
||||||
|
|
||||||
#include <GLFW/glfw3.h>
|
#include <GLFW/glfw3.h>
|
||||||
|
#include <glad/gl.h>
|
||||||
|
|
||||||
int render_init(void);
|
int render_init(void);
|
||||||
void render_update(GLFWwindow *win);
|
void render_update(GLFWwindow *win);
|
||||||
|
void render_free(void);
|
||||||
|
|||||||
@@ -69,5 +69,13 @@ void window_loop(void) {
|
|||||||
glfwSwapBuffers(win);
|
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 */
|
* Licensed under the MIT Licence. See LICENSE for details */
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
int window_init(void); // initializes the global window, returns non-zero upon failure
|
/* Set up the window, enabling OpenGL, and
|
||||||
void window_loop(void); // performs the window updates
|
* 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) {
|
static void quit(void) {
|
||||||
|
window_free();
|
||||||
|
|
||||||
|
/* terminates GLFW; destroying any
|
||||||
|
* remaining windows, or other resources held by GLFW. */
|
||||||
glfwTerminate();
|
glfwTerminate();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -30,7 +34,7 @@ int main(int argc, char **argv) {
|
|||||||
fatal("failed to initialise!");
|
fatal("failed to initialise!");
|
||||||
|
|
||||||
window_loop();
|
window_loop();
|
||||||
quit();
|
window_free();
|
||||||
|
|
||||||
// return success, since some architectures do not follow 0=success
|
// return success, since some architectures do not follow 0=success
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
|
|||||||
Reference in New Issue
Block a user