// Copyright [2023] Krzysztof Rudnicki #ifndef HOME_KUCHY_ENGINEER_THESIS_WUT_BREAKOUT_BREAKOUT_CPP #define HOME_KUCHY_ENGINEER_THESIS_WUT_BREAKOUT_BREAKOUT_CPP #include #include "../dependencies/include/glad/glad.h" #include "./game.hpp" #include "./resourceManager.hpp" // GLFW function declarations void framebuffer_size_callback(GLFWwindow *window, int width, int height); void key_callback(GLFWwindow *window, int key, int scancode, int action, int mode); // The Width of the screen constexpr int SCREEN_WIDTH = 800; // The height of the screen constexpr int SCREEN_HEIGHT = 600; Game &getBreakoutInstance() { static Game Breakout(SCREEN_WIDTH, SCREEN_HEIGHT); return Breakout; } int main(int /*argc*/, char * /*argv*/[]) { glfwInit(); glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); #ifdef __APPLE__ glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); #endif glfwWindowHint(GLFW_RESIZABLE, 0); GLFWwindow *window = glfwCreateWindow(SCREEN_WIDTH, SCREEN_HEIGHT, "Breakout", nullptr, nullptr); glfwMakeContextCurrent(window); // glad: load all OpenGL function pointers // --------------------------------------- if (gladLoadGLLoader(reinterpret_cast(glfwGetProcAddress)) == 0) { std::cout << "Failed to initialize GLAD" << std::endl; return -1; } glfwSetKeyCallback(window, bugprone-easily-swappable-parameters // -------------------- glViewport(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // initialize game // --------------- Breakout.Init(); // deltaTime variables // ------------------- float deltaTime = 0.0F; float lastFrame = 0.0F; while (glfwWindowShouldClose(window) == 0) { // calculate delta time // -------------------- float const currentFrame = glfwGetTime(); deltaTime = currentFrame - lastFrame; lastFrame = currentFrame; glfwPollEvents(); // manage user input // ----------------- Breakout.ProcessInput(deltaTime); // update game state // ----------------- Breakout.Update(deltaTime); // render // ------ glClearColor(0.0F, 0.0F, 0.0F, 1.0F); glClear(GL_COLOR_BUFFER_BIT); Breakout.Render(); glfwSwapBuffers(window); } // delete all resources as loaded using the resource manager // --------------------------------------------------------- ResourceManager::Clear(); glfwTerminate(); return 0; } void key_callback(GLFWwindow *window, int key, int /*scancode*/, int action, int /*mode*/) { // when a user presses the escape key, we set the // WindowShouldClose property to true, closing the application if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS) { glfwSetWindowShouldClose(window, 1); } if (key >= 0 && key < 1024) { if (action == GLFW_PRESS) { Breakout.Keys[key] = true; } else if (action == GLFW_RELEASE) { Breakout.Keys[key] = false; } } } void framebuffer_size_callback(GLFWwindow * /*window*/, int width, int height) { // make sure the viewport matches the new window dimensions; // note that width and // height will be significantly larger than specified on retina displays. glViewport(0, 0, width, height); } #endif // BREAKOUT_CPP