Change gameShouldTerminate

This commit is contained in:
4VRDriver
2020-08-31 13:21:19 +02:00
parent 291acdbe0d
commit 4fc4b402bc
6 changed files with 11 additions and 7 deletions

2
.vscode/launch.json vendored
View File

@@ -9,7 +9,7 @@
"name": "(gdb) Starten",
"type": "cppdbg",
"request": "launch",
"program": "build/Fall-Fever",
"program": "${workspaceFolder}/build/Fall-Fever",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",

View File

@@ -21,6 +21,7 @@ target_link_libraries(
Fall-Fever PRIVATE
glfw
glad
GL
)
target_compile_options(Fall-Fever PRIVATE -Wall -Wextra -pedantic)

View File

@@ -30,22 +30,24 @@ Controller::~Controller() {
}
void Controller::run() {
bool running = 1;
while(running) {
glClearColor(0.341f, 0.678f, 0.408f, 1.0f);
// This is the game loop
while(!glfwWindowShouldClose(gameWindow->getGLFWwindow())) {
// Timing
limit_framerate();
std::cout << 1/deltaTime << std::endl;
std::cout << "FPS: " << 1/deltaTime << std::endl;
// Update game
// Render and buffer swap
glClear(GL_COLOR_BUFFER_BIT);
glfwSwapBuffers(gameWindow->getGLFWwindow());
// Check events, handle input
gameEventHandler->handleEvents(gameWindow->getGLFWwindow());
if(gameEventHandler->gameShouldTerminate) running = 0;
}
}
void Controller::error_callback(int error, const char* description) {

View File

@@ -2,7 +2,6 @@
void EventHandler::handleEvents(GLFWwindow *window) {
glfwPollEvents();
gameShouldTerminate = glfwWindowShouldClose(window);
if(glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS)
glfwSetWindowShouldClose(window, true);

View File

@@ -7,7 +7,6 @@ class EventHandler {
public:
void handleEvents(GLFWwindow *window);
bool gameShouldTerminate;
private:

View File

@@ -14,6 +14,7 @@ Window::Window() {
// Create OpenGL context
glfwMakeContextCurrent(window);
// Initialize GLAD
if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)) {
std::cout << "Failed to initialize GLAD" << std::endl;
exit(-1);
@@ -21,6 +22,7 @@ Window::Window() {
glViewport(0, 0, width, height);
// Tell GLFW which function to call when window is resized
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
}
@@ -29,6 +31,7 @@ Window::~Window() {
glfwDestroyWindow(window);
}
// This function is called when the window gets resized
void Window::framebuffer_size_callback(GLFWwindow* window, int width, int height) {
(void)window;
glViewport(0, 0, width, height);