Blank window

This commit is contained in:
Pablo Rodriguez
2025-07-27 12:38:06 -04:00
parent e8e91e86c7
commit 06a9f74f2c
6 changed files with 116 additions and 6 deletions

63
source/app/src/App.cpp Normal file
View File

@@ -0,0 +1,63 @@
#include "App.hpp"
#include <cstdlib>
#include <iostream>
#include <GL/glew.h>
#include <GLFW/glfw3.h>
int App::main(std::vector<std::string> &args) {
auto app = App{};
app.game_loop();
return EXIT_SUCCESS;
}
void App::error_callback_s(int error, const char *description)
{
std::cerr << "[GLFW error]: " << description << '\n';
exit(EXIT_FAILURE);
}
void App::key_callback_s(GLFWwindow *window, int key, int scancode, int action, int mods) {
auto app = static_cast<App*>(glfwGetWindowUserPointer(window));
app->key_callback(key, scancode, action, mods);
}
App::App():
mpWindow{NULL} {
glfwSetErrorCallback(error_callback_s);
glfwInit();
mpWindow = glfwCreateWindow(640, 480, "uGLy", NULL, NULL);
glfwSetWindowUserPointer(mpWindow, this);
glfwSetKeyCallback(mpWindow, key_callback_s);
glfwMakeContextCurrent(mpWindow);
if(glewInit() != GLEW_OK) {
error_callback_s(GLFW_NO_ERROR, "glewInit() failed");
}
}
App::~App() {
glfwTerminate();
glfwSetErrorCallback(NULL);
}
void App::game_loop() {
while(!glfwWindowShouldClose(mpWindow)) {
glfwPollEvents();
}
}
void App::key_callback(int key, int scancode, int action, int mods) {
if(key == GLFW_KEY_ESCAPE && action == GLFW_PRESS) {
glfwSetWindowShouldClose(mpWindow, GLFW_TRUE);
}
}