mirror of
https://github.com/thepigeongenerator/mcaselector-lite.git
synced 2025-12-17 06:05:44 +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_frag_glsl_len;
|
||||||
extern const uint sh_geom_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) {
|
static GLuint shader_compile(GLenum type, const char *src, size_t len) {
|
||||||
int ilen = len;
|
int ilen = len;
|
||||||
GLuint shader = glCreateShader(type);
|
GLuint shader = glCreateShader(type);
|
||||||
@@ -45,6 +46,7 @@ int shader_init(GLuint pipe) {
|
|||||||
glAttachShader(pipe, fs);
|
glAttachShader(pipe, fs);
|
||||||
glAttachShader(pipe, gs);
|
glAttachShader(pipe, gs);
|
||||||
|
|
||||||
|
// mark shaders off for deletion
|
||||||
glDeleteShader(vs);
|
glDeleteShader(vs);
|
||||||
glDeleteShader(fs);
|
glDeleteShader(fs);
|
||||||
glDeleteShader(gs);
|
glDeleteShader(gs);
|
||||||
|
|||||||
@@ -3,8 +3,8 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <glad/gl.h>
|
#include <glad/gl.h>
|
||||||
|
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
|
/* Initialises the (embedded) shaders onto `pipe` */
|
||||||
int shader_init(GLuint pipe);
|
int shader_init(GLuint pipe);
|
||||||
|
|||||||
@@ -2,48 +2,42 @@
|
|||||||
* Licensed under the MIT Licence. See LICENSE for details */
|
* Licensed under the MIT Licence. See LICENSE for details */
|
||||||
#include "window.h"
|
#include "window.h"
|
||||||
|
|
||||||
#include <glad/gl.h>
|
|
||||||
|
|
||||||
#include <GLFW/glfw3.h>
|
#include <GLFW/glfw3.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
#include <glad/gl.h>
|
||||||
|
|
||||||
#include "../error.h"
|
#include "../error.h"
|
||||||
|
#include "../util/intdef.h"
|
||||||
#include "input.h"
|
#include "input.h"
|
||||||
#include "render.h"
|
#include "render.h"
|
||||||
|
|
||||||
// macros for ease of access
|
static struct GLFWwindow *win = NULL;
|
||||||
#define WIN_NAME "MCA Selector Lite"
|
|
||||||
#define WIN_DEFAULT_WIDTH 640
|
|
||||||
#define WIN_DEFAULT_HEIGHT 480
|
|
||||||
|
|
||||||
static GLFWwindow *win = NULL;
|
|
||||||
|
|
||||||
|
/* Initialises the GLFW window with some defaults,
|
||||||
|
* then proceed to activate OpenGL on it. */
|
||||||
int window_init(void) {
|
int window_init(void) {
|
||||||
|
// initialise the window
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, GLFW_TRUE);
|
glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, GLFW_TRUE);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// initialize the window
|
|
||||||
glfwWindowHint(GLFW_RESIZABLE, GLFW_TRUE);
|
glfwWindowHint(GLFW_RESIZABLE, GLFW_TRUE);
|
||||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
|
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
|
||||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 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_PROFILE, GLFW_OPENGL_CORE_PROFILE);
|
||||||
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GLFW_TRUE);
|
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, 1);
|
||||||
glfwWindowHint(GLFW_RED_BITS, 8);
|
glfwWindowHint(GLFW_RED_BITS, 8);
|
||||||
glfwWindowHint(GLFW_GREEN_BITS, 8);
|
glfwWindowHint(GLFW_GREEN_BITS, 8);
|
||||||
glfwWindowHint(GLFW_BLUE_BITS, 8);
|
glfwWindowHint(GLFW_BLUE_BITS, 8);
|
||||||
glfwWindowHint(GLFW_ALPHA_BITS, 0);
|
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;
|
if (!win) return 1;
|
||||||
|
|
||||||
// setup OpenGL for the window
|
|
||||||
glfwMakeContextCurrent(win);
|
glfwMakeContextCurrent(win);
|
||||||
if (!gladLoadGL(glfwGetProcAddress)) return 1;
|
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)
|
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);
|
glfwSetKeyCallback(win, input_callback);
|
||||||
|
|
||||||
// print the OpenGL version information
|
|
||||||
debug(
|
debug(
|
||||||
"version info:\n"
|
"version info:\n"
|
||||||
"\tvendor: %s\n"
|
"\tvendor: %s\n"
|
||||||
@@ -54,19 +48,19 @@ int window_init(void) {
|
|||||||
glGetString(GL_RENDERER),
|
glGetString(GL_RENDERER),
|
||||||
glGetString(GL_VERSION),
|
glGetString(GL_VERSION),
|
||||||
glGetString(GL_SHADING_LANGUAGE_VERSION));
|
glGetString(GL_SHADING_LANGUAGE_VERSION));
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void window_loop(void) {
|
void window_loop(void) {
|
||||||
assert(win != NULL);
|
assert(win);
|
||||||
|
|
||||||
render_init();
|
render_init();
|
||||||
while (!glfwWindowShouldClose(win)) {
|
while (!glfwWindowShouldClose(win)) {
|
||||||
glfwWaitEvents(); // wait till an update has been given
|
glfwWaitEvents();
|
||||||
|
|
||||||
render_update(win);
|
render_update(win);
|
||||||
glfwSwapBuffers(win);
|
glfwSwapBuffers(win);
|
||||||
|
glfwPollEvents();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void window_close(void) {
|
void window_close(void) {
|
||||||
|
|||||||
Reference in New Issue
Block a user