diff --git a/src/dawn/display/font/BitmapFont.cpp b/src/dawn/display/font/BitmapFont.cpp index 087b7397..12bc7e42 100644 --- a/src/dawn/display/font/BitmapFont.cpp +++ b/src/dawn/display/font/BitmapFont.cpp @@ -44,7 +44,10 @@ void BitmapFont::buffer( size_t j = 0; size_t wordStart = 0; glm::vec2 xy0(0, 0); - glm::vec2 tileSize = glm::vec2(tileset->getTileWidth(), tileset->getTileHeight()); + glm::vec2 tileSize = + glm::vec2(tileset->getTileWidth(), tileset->getTileHeight()) * + (fontSize / this->getDefaultFontSize()) + ; // Buffer quads while(c = text[i++]) { @@ -139,9 +142,9 @@ void BitmapFont::draw(Mesh *mesh, int32_t start, int32_t len) { } float_t BitmapFont::getLineHeight(float_t fontSize) { - return 16.0f; + return tileset->getTileHeight(); } float_t BitmapFont::getDefaultFontSize() { - return 16.0f; + return tileset->getTileHeight(); } \ No newline at end of file diff --git a/src/dawn/prefabs/FPSLabel.hpp b/src/dawn/prefabs/FPSLabel.hpp new file mode 100644 index 00000000..c71acf8a --- /dev/null +++ b/src/dawn/prefabs/FPSLabel.hpp @@ -0,0 +1,32 @@ +// Copyright (c) 2023 Dominic Masters +// +// This software is released under the MIT License. +// https://opensource.org/licenses/MIT + +#pragma once +#include "prefab/SceneItemPrefab.hpp" +#include "scene/components/ui/UILabel.hpp" + +namespace Dawn { + class FPSLabel : public SceneItemPrefab, public StateOwner { + public: + static std::vector prefabAssets(AssetManager *man) { + return {}; + } + + UILabel *label; + + FPSLabel(Scene *s, sceneitemid_t i) : SceneItemPrefab(s, i) {} + + void prefabInit(AssetManager *man) override { + label = this->addComponent(); + label->text = "No Frame"; + + useEvent([&](float_t delta){ + std::string strFps = std::to_string((int32_t)(1.0f / delta)); + std::string strTick = std::to_string((int32_t)(delta * 1000.0f)); + label->text = strFps + "FPS (" + strTick + "ms)"; + }, scene->eventSceneUnpausedUpdate); + } + }; +} \ No newline at end of file diff --git a/src/dawnglfw/host/DawnGLFWHost.cpp b/src/dawnglfw/host/DawnGLFWHost.cpp index 648e2338..023152cd 100644 --- a/src/dawnglfw/host/DawnGLFWHost.cpp +++ b/src/dawnglfw/host/DawnGLFWHost.cpp @@ -48,7 +48,7 @@ int32_t DawnHost::init(DawnGame *game) { // Load GLAD glfwMakeContextCurrent(this->data->window); - glfwSwapInterval(0); + glfwSwapInterval(1); gladLoadGLLoader((GLADloadproc)glfwGetProcAddress); // Override the defaults diff --git a/src/dawnhelloworld/scenes/HelloWorldScene.hpp b/src/dawnhelloworld/scenes/HelloWorldScene.hpp index 9c951f2c..8e26574e 100644 --- a/src/dawnhelloworld/scenes/HelloWorldScene.hpp +++ b/src/dawnhelloworld/scenes/HelloWorldScene.hpp @@ -6,7 +6,7 @@ #pragma once #include "scene/Scene.hpp" #include "prefabs/SimpleSpinningCubePrefab.hpp" -#include "scene/components/ui/UILabel.hpp" +#include "prefabs/FPSLabel.hpp" #include "scene/components/ui/UIImage.hpp" #include "display/font/BitmapFont.hpp" @@ -17,38 +17,20 @@ namespace Dawn { SimpleSpinningCubePrefab *cube; UICanvas *canvas; UILabel *label; - UIImage *image; - BitmapFont font; - Texture test; void stage() override { camera = Camera::create(this); camera->transform->lookAt(glm::vec3(3, 3, 3), glm::vec3(0, 0, 0)); - cube = SimpleSpinningCubePrefab::create(this); - cube->material->texture = &test; - struct Color colors[] = { - COLOR_RED, COLOR_BLUE, COLOR_GREEN, - COLOR_MAGENTA, COLOR_DARK_GREY, COLOR_WHITE, - COLOR_BLACK, COLOR_CORNFLOWER_BLUE, COLOR_RED - }; - test.setSize(3, 3); - test.buffer(colors); canvas = UICanvas::create(this); - auto imageItem = this->createSceneItem(); - image = imageItem->addComponent(); - image->color = COLOR_BLACK; - imageItem->transform.setParent(canvas->transform); - - auto labelItem = this->createSceneItem(); - label = labelItem->addComponent(); + auto labelItem = FPSLabel::create(this); labelItem->transform.setParent(canvas->transform); - label->text = "Hello World, how are you today? I hope you are doing well. I really like the fact I can ramble in my text for once."; - label->maxWidth = 220; - image->alignment = glm::vec4(0, 0, label->getContentWidth(), label->getContentHeight()); + labelItem->label->alignX = UI_COMPONENT_ALIGN_END; + labelItem->label->alignment = glm::vec4(0, 0, 0, 0); + labelItem->label->fontSize = 16; } std::vector getRequiredAssets() override {