diff --git a/docs/general/project_properties.md b/docs/general/project_properties.md index 82b8e404..b534b19f 100644 --- a/docs/general/project_properties.md +++ b/docs/general/project_properties.md @@ -12,6 +12,10 @@ Project properties define how the game will be configured before running. An ex "width": 800, "height": 600 }, + "window_size": { + "width": 800, + "height": 600 + }, "colliders_visible": true, "pixel_snap": true, "target_fps": 60, @@ -77,7 +81,11 @@ First scene loaded for the game. `base_resolution` -Base resolution of the game +Base resolution of the game. + +`window_size` + +The initial window size when starting the game. `colliders_visible` diff --git a/src/core/ecs/system/systems/collision_entity_system.h b/src/core/ecs/system/systems/collision_entity_system.h index f8cfa2e3..b87def6c 100644 --- a/src/core/ecs/system/systems/collision_entity_system.h +++ b/src/core/ecs/system/systems/collision_entity_system.h @@ -52,8 +52,8 @@ class CollisionEntitySystem : public EntitySystem { Vector2 collisionScreenScale = Vector2(transform2DComponent.scale.x * parentTransform.scale.x * colliderComponent.collider.w * camera.zoom.x, transform2DComponent.scale.y * parentTransform.scale.y * colliderComponent.collider.h * camera.zoom.y); ProjectProperties *projectProperties = ProjectProperties::GetInstance(); - collisionScreenScale.x *= windowWidth / static_cast(projectProperties->windowWidth); - collisionScreenScale.y *= windowHeight / static_cast(projectProperties->windowHeight); + collisionScreenScale.x *= windowWidth / static_cast(projectProperties->resolutionWidth); + collisionScreenScale.y *= windowHeight / static_cast(projectProperties->resolutionHeight); return Rect2(collisionScreenPosition, collisionScreenScale); } diff --git a/src/core/game.cpp b/src/core/game.cpp index 29b44888..3d7ce8f0 100644 --- a/src/core/game.cpp +++ b/src/core/game.cpp @@ -203,12 +203,12 @@ void Game::InitializeRendering() { projectProperties->gameTitle.c_str(), SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, - projectProperties->windowWidth, - projectProperties->windowHeight, + projectProperties->intitialWindowWidth, + projectProperties->intitialWindowHeight, renderContext->windowFlags); renderContext->gl_context = SDL_GL_CreateContext(renderContext->window); - renderContext->currentWindowWidth = projectProperties->windowWidth; - renderContext->currentWindowHeight = projectProperties->windowHeight; + renderContext->currentWindowWidth = projectProperties->intitialWindowWidth; + renderContext->currentWindowHeight = projectProperties->intitialWindowHeight; if (!gladLoadGLLoader((GLADloadproc)SDL_GL_GetProcAddress)) { logger->Error("Couldn't initialize glad"); diff --git a/src/core/project_properties.h b/src/core/project_properties.h index 8c14dead..56c2c35f 100644 --- a/src/core/project_properties.h +++ b/src/core/project_properties.h @@ -80,8 +80,11 @@ class ProjectProperties { gameTitle = JsonHelper::Get(projectConfigurationsJson, "game_title"); initialScenePath = JsonHelper::Get(projectConfigurationsJson, "initial_scene"); nlohmann::json baseResolutionJson = JsonHelper::Get(projectConfigurationsJson, "base_resolution"); - windowWidth = JsonHelper::Get(baseResolutionJson, "width"); - windowHeight = JsonHelper::Get(baseResolutionJson, "height"); + resolutionWidth = JsonHelper::Get(baseResolutionJson, "width"); + resolutionHeight = JsonHelper::Get(baseResolutionJson, "height"); + nlohmann::json windowSizeJson = JsonHelper::Get(projectConfigurationsJson, "window_size"); + intitialWindowWidth = JsonHelper::Get(windowSizeJson, "width"); + intitialWindowHeight = JsonHelper::Get(windowSizeJson, "height"); areColliderVisible = JsonHelper::Get(projectConfigurationsJson, "colliders_visible"); pixelSnap = JsonHelper::GetDefault(projectConfigurationsJson, "pixel_snap", false); targetFPS = JsonHelper::Get(projectConfigurationsJson, "target_fps"); @@ -167,8 +170,10 @@ class ProjectProperties { } public: std::string gameTitle = "Seika Engine"; - int windowWidth = 800; - int windowHeight = 600; + int resolutionWidth = 800; + int resolutionHeight = 600; + int intitialWindowWidth = resolutionWidth; + int intitialWindowHeight = resolutionHeight; Color backgroundDrawColor = Color::NormalizedColor(20, 20, 20); bool areColliderVisible = false; std::string initialScenePath; diff --git a/src/core/rendering/font_renderer.cpp b/src/core/rendering/font_renderer.cpp index 64078afa..c3083de7 100644 --- a/src/core/rendering/font_renderer.cpp +++ b/src/core/rendering/font_renderer.cpp @@ -14,10 +14,10 @@ void FontRenderer::Draw(Font *font, const std::string &text, float x, float y, f glBindVertexArray(font->VAO); y = ConvertMinMax(y, - static_cast(projectProperties->windowHeight), + static_cast(projectProperties->resolutionHeight), 0, 0, - static_cast(projectProperties->windowHeight)); + static_cast(projectProperties->resolutionHeight)); y -= font->GetSize() * 0.8f; // iterate through all characters @@ -57,7 +57,7 @@ void FontRenderer::Draw(Font *font, const std::string &text, float x, float y, f } void FontRenderer::UpdateProjection() { - glm::mat4 projection = glm::ortho(0.0f, static_cast(projectProperties->windowWidth), 0.0f, static_cast(projectProperties->windowHeight), -1.0f, 1.0f); + glm::mat4 projection = glm::ortho(0.0f, static_cast(projectProperties->resolutionWidth), 0.0f, static_cast(projectProperties->resolutionHeight), -1.0f, 1.0f); shader.Use(); shader.SetMatrix4Float("projection", projection); } diff --git a/src/core/rendering/renderer3d.cpp b/src/core/rendering/renderer3d.cpp index 0cd945c4..4dc8f4b1 100644 --- a/src/core/rendering/renderer3d.cpp +++ b/src/core/rendering/renderer3d.cpp @@ -60,7 +60,7 @@ void Renderer3D::Initialize() { void Renderer3D::Render(CameraManager *cameraManager) { glEnable(GL_DEPTH_TEST); static ProjectProperties *projectProperties = ProjectProperties::GetInstance(); - const float aspectRatio = projectProperties->windowWidth / projectProperties->windowHeight; + const float aspectRatio = projectProperties->resolutionWidth / projectProperties->resolutionHeight; Camera3D camera = cameraManager->GetCurrentCamera3D(); glm::mat4 projection = glm::perspective(glm::radians(camera.fieldOfView), aspectRatio, 0.1f, 100.0f); glm::mat4 view = CameraHandler::GetCameraViewMatrix(camera); diff --git a/src/core/rendering/sprite_renderer.cpp b/src/core/rendering/sprite_renderer.cpp index f0d560f0..14b047f6 100644 --- a/src/core/rendering/sprite_renderer.cpp +++ b/src/core/rendering/sprite_renderer.cpp @@ -111,7 +111,7 @@ void SpriteRenderer::Draw(Texture *texture2D, Rect2 sourceRectangle, Rect2 desti void SpriteRenderer::UpdateProjection() { shader.Use(); - projection = glm::ortho(0.0f, static_cast(projectProperties->windowWidth), static_cast(projectProperties->windowHeight), 0.0f, -1.0f, 1.0f); + projection = glm::ortho(0.0f, static_cast(projectProperties->resolutionWidth), static_cast(projectProperties->resolutionHeight), 0.0f, -1.0f, 1.0f); shader.SetMatrix4Float("projection", projection); }