diff --git a/build/build.sh b/build/build.sh index 8d0fac7..3bbf0e4 100755 --- a/build/build.sh +++ b/build/build.sh @@ -41,7 +41,7 @@ make # Now move resources files echo "-LU- Moving resources..." -cd src/ +cd Release if [ -d "$Resources/" ]; then rm -rf Resources/ diff --git a/include/Core/Window.h b/include/Core/Window.h index 0513a49..858829a 100644 --- a/include/Core/Window.h +++ b/include/Core/Window.h @@ -112,6 +112,13 @@ namespace lu void display(); /**< Changes buffer behind the scene essentially displaying all that has been rendered */ + /** + * \brief Notify the window of incoming events + * + * @param e The incoming event. + */ + void notify(const SDL_Event &e); + /** * \brief Sets the window size * diff --git a/src/Core/Application.cpp b/src/Core/Application.cpp index a10f02f..a863908 100644 --- a/src/Core/Application.cpp +++ b/src/Core/Application.cpp @@ -31,8 +31,8 @@ lu::core::Application::initInternal() // Retrieve SDL_Versions lu::core::log("SDL3 version: " + std::to_string(SDL_VERSION)); - if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK | SDL_INIT_GAMEPAD | - SDL_INIT_EVENTS) < 0) + if (!SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK | SDL_INIT_GAMEPAD | + SDL_INIT_EVENTS)) { lu::core::log(LU_AT, "Failed to initialize SDL with error:\n" + diff --git a/src/Core/Window.cpp b/src/Core/Window.cpp index e7f6df2..e4c742b 100644 --- a/src/Core/Window.cpp +++ b/src/Core/Window.cpp @@ -1,5 +1,7 @@ #include "Core/Window.h" +#include "Core/Application.h" + void lu::core::Window::initVideoComponents() { @@ -108,6 +110,23 @@ lu::core::Window::display() SDL_GL_SwapWindow(m_window); } +void +lu::core::Window::notify(const SDL_Event &e) +{ + switch (e.type) + { + case SDL_EVENT_WINDOW_RESIZED: + { + std::cout << e.window.data1 << "-" << e.window.data2 << std::endl; + setSize(e.window.data1, e.window.data2); + lu::core::Application::setScreenBufferSize(e.window.data1, + e.window.data2); + glViewport(0, 0, e.window.data1, e.window.data2); + } + break; + } +} + void lu::core::Window::setSize(int width, int height) { @@ -136,6 +155,7 @@ glm::vec2 lu::core::Window::getSize() { int width, height; - SDL_GetWindowSize(m_window, &width, &height); + // SDL_GetWindowSize(m_window, &width, &height); + SDL_GetWindowSizeInPixels(m_window, &width, &height); return glm::vec2(width, height); } diff --git a/src/Main.cpp b/src/Main.cpp index 11f9a1b..d9ed275 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -3,13 +3,11 @@ #include "GL/glew.h" #include -#include "GLM/glm.hpp" - -#include "Graphics/Text/Font.h" - #include "Core/Application.h" #include "Core/Time.h" #include "Core/Window.h" +#include "GLM/glm.hpp" +#include "Graphics/Text/Font.h" #include "Game/GameMode/ExampleGameMode.h" @@ -45,6 +43,9 @@ main(int argc, char *argv[]) lu::core::Application::enableVSYNC(true); window.setWindowGrab(true); + auto size = window.getSize(); + std::cout << "Size: " << size.x << "x" << size.y << std::endl; + lu::game::ExampleGameMode exGameMode; exGameMode.init(); @@ -77,13 +78,13 @@ main(int argc, char *argv[]) while (SDL_PollEvent(&e) != 0) { exGameMode.checkInput(e); + window.notify(e); if (e.type == SDL_EVENT_QUIT) { running = false; } - - if (e.type == SDL_EVENT_KEY_DOWN) + else if (e.type == SDL_EVENT_KEY_DOWN) { // TOGGLE FULLSCREEN if (e.key.key == SDLK_F11)