mirror of
https://github.com/thepigeongenerator/mcaselector-lite.git
synced 2025-12-16 19:45:46 +01:00
refactor the lot a bit, for clairity.
This commit is contained in:
@@ -17,7 +17,8 @@ extern const uint sh_vert_glsl_len;
|
||||
extern const uint sh_frag_glsl_len;
|
||||
extern const uint sh_geom_glsl_len;
|
||||
|
||||
/* compile a shader */
|
||||
/* 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, size_t len) {
|
||||
int ilen = len;
|
||||
GLuint shader = glCreateShader(type);
|
||||
@@ -45,6 +46,7 @@ int shader_init(GLuint pipe) {
|
||||
glAttachShader(pipe, fs);
|
||||
glAttachShader(pipe, gs);
|
||||
|
||||
// mark shaders off for deletion
|
||||
glDeleteShader(vs);
|
||||
glDeleteShader(fs);
|
||||
glDeleteShader(gs);
|
||||
|
||||
@@ -3,8 +3,8 @@
|
||||
#pragma once
|
||||
|
||||
#include <glad/gl.h>
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
/* Initialises the (embedded) shaders onto `pipe` */
|
||||
int shader_init(GLuint pipe);
|
||||
|
||||
@@ -2,48 +2,42 @@
|
||||
* Licensed under the MIT Licence. See LICENSE for details */
|
||||
#include "window.h"
|
||||
|
||||
#include <glad/gl.h>
|
||||
|
||||
#include <GLFW/glfw3.h>
|
||||
#include <assert.h>
|
||||
#include <glad/gl.h>
|
||||
|
||||
#include "../error.h"
|
||||
#include "../util/intdef.h"
|
||||
#include "input.h"
|
||||
#include "render.h"
|
||||
|
||||
// macros for ease of access
|
||||
#define WIN_NAME "MCA Selector Lite"
|
||||
#define WIN_DEFAULT_WIDTH 640
|
||||
#define WIN_DEFAULT_HEIGHT 480
|
||||
|
||||
static GLFWwindow *win = NULL;
|
||||
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
|
||||
|
||||
// initialize the window
|
||||
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); // sets the profile to "core", so old, deprecated functions are disabled.
|
||||
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GLFW_TRUE);
|
||||
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);
|
||||
win = glfwCreateWindow(WIN_DEFAULT_WIDTH, WIN_DEFAULT_HEIGHT, WIN_NAME, NULL, NULL);
|
||||
win = glfwCreateWindow(640, 480, "MCA-Selector lite", NULL, NULL);
|
||||
if (!win) return 1;
|
||||
|
||||
// setup OpenGL for the window
|
||||
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);
|
||||
|
||||
// print the OpenGL version information
|
||||
debug(
|
||||
"version info:\n"
|
||||
"\tvendor: %s\n"
|
||||
@@ -54,20 +48,20 @@ int window_init(void) {
|
||||
glGetString(GL_RENDERER),
|
||||
glGetString(GL_VERSION),
|
||||
glGetString(GL_SHADING_LANGUAGE_VERSION));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void window_loop(void) {
|
||||
assert(win != NULL);
|
||||
|
||||
assert(win);
|
||||
render_init();
|
||||
while (!glfwWindowShouldClose(win)) {
|
||||
glfwWaitEvents(); // wait till an update has been given
|
||||
glfwWaitEvents();
|
||||
|
||||
render_update(win);
|
||||
glfwSwapBuffers(win);
|
||||
glfwPollEvents();
|
||||
}
|
||||
}
|
||||
|
||||
void window_close(void) {
|
||||
assert(win);
|
||||
|
||||
Reference in New Issue
Block a user