Change gameShouldTerminate
This commit is contained in:
2
.vscode/launch.json
vendored
2
.vscode/launch.json
vendored
@@ -9,7 +9,7 @@
|
|||||||
"name": "(gdb) Starten",
|
"name": "(gdb) Starten",
|
||||||
"type": "cppdbg",
|
"type": "cppdbg",
|
||||||
"request": "launch",
|
"request": "launch",
|
||||||
"program": "build/Fall-Fever",
|
"program": "${workspaceFolder}/build/Fall-Fever",
|
||||||
"args": [],
|
"args": [],
|
||||||
"stopAtEntry": false,
|
"stopAtEntry": false,
|
||||||
"cwd": "${workspaceFolder}",
|
"cwd": "${workspaceFolder}",
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ target_link_libraries(
|
|||||||
Fall-Fever PRIVATE
|
Fall-Fever PRIVATE
|
||||||
glfw
|
glfw
|
||||||
glad
|
glad
|
||||||
|
GL
|
||||||
)
|
)
|
||||||
|
|
||||||
target_compile_options(Fall-Fever PRIVATE -Wall -Wextra -pedantic)
|
target_compile_options(Fall-Fever PRIVATE -Wall -Wextra -pedantic)
|
||||||
|
|||||||
@@ -30,22 +30,24 @@ Controller::~Controller() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Controller::run() {
|
void Controller::run() {
|
||||||
bool running = 1;
|
glClearColor(0.341f, 0.678f, 0.408f, 1.0f);
|
||||||
while(running) {
|
// This is the game loop
|
||||||
|
while(!glfwWindowShouldClose(gameWindow->getGLFWwindow())) {
|
||||||
// Timing
|
// Timing
|
||||||
limit_framerate();
|
limit_framerate();
|
||||||
std::cout << 1/deltaTime << std::endl;
|
std::cout << "FPS: " << 1/deltaTime << std::endl;
|
||||||
|
|
||||||
// Update game
|
// Update game
|
||||||
|
|
||||||
// Render and buffer swap
|
// Render and buffer swap
|
||||||
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
glfwSwapBuffers(gameWindow->getGLFWwindow());
|
glfwSwapBuffers(gameWindow->getGLFWwindow());
|
||||||
|
|
||||||
|
|
||||||
// Check events, handle input
|
// Check events, handle input
|
||||||
gameEventHandler->handleEvents(gameWindow->getGLFWwindow());
|
gameEventHandler->handleEvents(gameWindow->getGLFWwindow());
|
||||||
if(gameEventHandler->gameShouldTerminate) running = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Controller::error_callback(int error, const char* description) {
|
void Controller::error_callback(int error, const char* description) {
|
||||||
|
|||||||
@@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
void EventHandler::handleEvents(GLFWwindow *window) {
|
void EventHandler::handleEvents(GLFWwindow *window) {
|
||||||
glfwPollEvents();
|
glfwPollEvents();
|
||||||
gameShouldTerminate = glfwWindowShouldClose(window);
|
|
||||||
|
|
||||||
if(glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS)
|
if(glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS)
|
||||||
glfwSetWindowShouldClose(window, true);
|
glfwSetWindowShouldClose(window, true);
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ class EventHandler {
|
|||||||
public:
|
public:
|
||||||
|
|
||||||
void handleEvents(GLFWwindow *window);
|
void handleEvents(GLFWwindow *window);
|
||||||
bool gameShouldTerminate;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ Window::Window() {
|
|||||||
// Create OpenGL context
|
// Create OpenGL context
|
||||||
glfwMakeContextCurrent(window);
|
glfwMakeContextCurrent(window);
|
||||||
|
|
||||||
|
// Initialize GLAD
|
||||||
if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)) {
|
if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)) {
|
||||||
std::cout << "Failed to initialize GLAD" << std::endl;
|
std::cout << "Failed to initialize GLAD" << std::endl;
|
||||||
exit(-1);
|
exit(-1);
|
||||||
@@ -21,6 +22,7 @@ Window::Window() {
|
|||||||
|
|
||||||
glViewport(0, 0, width, height);
|
glViewport(0, 0, width, height);
|
||||||
|
|
||||||
|
// Tell GLFW which function to call when window is resized
|
||||||
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
|
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -29,6 +31,7 @@ Window::~Window() {
|
|||||||
glfwDestroyWindow(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::framebuffer_size_callback(GLFWwindow* window, int width, int height) {
|
||||||
(void)window;
|
(void)window;
|
||||||
glViewport(0, 0, width, height);
|
glViewport(0, 0, width, height);
|
||||||
|
|||||||
Reference in New Issue
Block a user