Game window stays up until ESC is pressed

This commit is contained in:
ATLAS_Moon
2020-08-15 16:27:24 +00:00
parent 0efe16a204
commit fd605024da
3 changed files with 107 additions and 27 deletions

View File

@@ -1,33 +1,60 @@
#include <gl3w/GL/gl3w.h> // Must be included first
#include "render.hpp"
#include <gl3w/GL/gl3w.h>
#include <GLFW/glfw3.h>
#include <stdio.h>
RenderManager::RenderManager(){}
bool RenderManager::Init (uint16_t width, uint16_t height, const char* title){
if (!glfwInit()) {
printf("[EE] failed to initialize GLFW.\n");
return false;
namespace
{
void handle_resize_event(GLFWwindow*, int width, int height){
printf("Window resized\n");
glViewport(0, 0, width, height);
}
}
render_manager::render_manager() :
m_windowCloseCallback (nullptr),
m_inputHandler (nullptr),
m_mainWindow (nullptr)
{}
render_manager::GLFW_ERROR render_manager::init (int width, int height, const char* title){
if (!glfwInit()) {
fprintf(stdout, "[EE] failed to initialize GLFW.\n");
return GLFW_INIT_ERROR;
}
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);
auto window = glfwCreateWindow(width, height, title, nullptr, nullptr);
if (!window) {
printf ("[EE] Could not create window\n");
return false;
m_mainWindow = glfwCreateWindow(width, height, title, nullptr, nullptr);
if (!m_mainWindow) {
fprintf (stdout, "[EE] Could not create window\n");
return GLFW_WINDOW_ERROR;
}
glfwMakeContextCurrent(window);
glfwMakeContextCurrent(m_mainWindow);
if (gl3wInit()) {
printf("[EE] failed to initialize OpenGL\n");
return false;
fprintf(stdout, "[EE] failed to initialize OpenGL\n");
return GLFW_CONTEXT_ERROR;
}
glViewport(0, 0, width, height);
printf("[DD] OpenGL %s, GLSL %s\n", glGetString(GL_VERSION), glGetString(GL_SHADING_LANGUAGE_VERSION));
return true;
glfwSetFramebufferSizeCallback(m_mainWindow, handle_resize_event);
return GLFW_OK;
}
void render_manager::update(){
glfwSwapBuffers(m_mainWindow);
glfwPollEvents();
}
void render_manager::request_exit()
{
if (m_windowCloseCallback) m_windowCloseCallback();
glfwSetWindowShouldClose(m_mainWindow, true);
}