mirror of
https://github.com/thepigeongenerator/mcaselector-lite.git
synced 2025-12-17 07:55:45 +01:00
add OpenGL bootstrapping code
This commit is contained in:
@@ -2,9 +2,15 @@
|
|||||||
// 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 before GLFW
|
||||||
|
#define GLAD_GL_IMPLEMENTATION
|
||||||
|
#include <glad/gl.h>
|
||||||
|
|
||||||
|
// include system libraries
|
||||||
#include <GLFW/glfw3.h>
|
#include <GLFW/glfw3.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
#include "input.h"
|
#include "input.h"
|
||||||
|
|
||||||
// macros for ease of access
|
// macros for ease of access
|
||||||
@@ -19,18 +25,19 @@ int window_init(void) {
|
|||||||
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); // TODO: read about opengl profiles
|
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
|
||||||
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GLFW_TRUE);
|
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GLFW_TRUE);
|
||||||
win = glfwCreateWindow(WIN_DEFAULT_WIDTH, WIN_DEFAULT_HEIGHT, WIN_NAME, NULL, NULL);
|
win = glfwCreateWindow(WIN_DEFAULT_WIDTH, WIN_DEFAULT_HEIGHT, WIN_NAME, NULL, NULL);
|
||||||
if (!win) return 1;
|
if (!win) return 1;
|
||||||
|
|
||||||
// make the current window the current context
|
|
||||||
glfwMakeContextCurrent(win);
|
|
||||||
|
|
||||||
// configure callbacks
|
// configure callbacks
|
||||||
glfwSetKeyCallback(win, key_callback);
|
glfwSetKeyCallback(win, key_callback);
|
||||||
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)
|
||||||
|
|
||||||
|
// setup OpenGL
|
||||||
|
glfwMakeContextCurrent(win);
|
||||||
|
if (!gladLoadGL(glfwGetProcAddress)) return 1;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -39,6 +46,9 @@ void window_loop(void) {
|
|||||||
|
|
||||||
while (!glfwWindowShouldClose(win)) {
|
while (!glfwWindowShouldClose(win)) {
|
||||||
glfwWaitEvents(); // wait till an update has been given
|
glfwWaitEvents(); // wait till an update has been given
|
||||||
|
glClearColor(0.1F, 0.1F, 0.1F, 1.0F);
|
||||||
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
|
glfwSwapBuffers(win);
|
||||||
}
|
}
|
||||||
|
|
||||||
glfwDestroyWindow(win);
|
glfwDestroyWindow(win);
|
||||||
|
|||||||
Reference in New Issue
Block a user