Blank window
This commit is contained in:
63
source/app/src/App.cpp
Normal file
63
source/app/src/App.cpp
Normal 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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user