add text to demo

This commit is contained in:
Bailey Harrison 2023-08-01 16:32:47 +01:00
parent cdb57ede9f
commit a26fa5153b
2 changed files with 15 additions and 9 deletions

View File

@ -31,7 +31,7 @@ class Scene {
/* ecs stuff */ /* ecs stuff */
uint32_t CreateEntity(const std::string& tag, uint32_t parent = 0, const glm::vec3& pos = {}); uint32_t CreateEntity(const std::string& tag, uint32_t parent = 0, const glm::vec3& pos = glm::vec3{0.0f, 0.0f, 0.0f});
uint32_t GetEntity(const std::string& tag, uint32_t parent = 0); uint32_t GetEntity(const std::string& tag, uint32_t parent = 0);

View File

@ -125,23 +125,26 @@ void PlayGame(GameSettings settings) {
my_scene, app.GetResourcePath("models/cobble_house/cobble_house.dae")); my_scene, app.GetResourcePath("models/cobble_house/cobble_house.dae"));
my_scene->GetComponent<engine::TransformComponent>(cobbleHouse)->position += my_scene->GetComponent<engine::TransformComponent>(cobbleHouse)->position +=
glm::vec3{33.0f, 0.1f, 35.0f}; glm::vec3{33.0f, 0.1f, 35.0f};
auto cobbleCustom = my_scene->AddComponent<engine::CustomComponent>(cobbleHouse); auto cobbleCustom =
my_scene->AddComponent<engine::CustomComponent>(cobbleHouse);
cobbleCustom->onInit = [](void) { cobbleCustom->onInit = [](void) {
LOG_INFO("Cobble house spin component initialised!"); LOG_INFO("Cobble house spin component initialised!");
}; };
cobbleCustom->onUpdate = [&](float ts) { cobbleCustom->onUpdate = [&](float ts) {
static auto t = my_scene->GetComponent<engine::TransformComponent>(cobbleHouse); static auto t =
my_scene->GetComponent<engine::TransformComponent>(cobbleHouse);
t->rotation *= glm::angleAxis(ts, glm::vec3{0.0f, 0.0f, 1.0f}); t->rotation *= glm::angleAxis(ts, glm::vec3{0.0f, 0.0f, 1.0f});
}; };
/* some text */ /* some text */
{ {
int width, height; int width, height;
auto bitmap = app.GetResource<engine::resources::Font>("builtin.mono") auto bitmap =
->GetTextBitmap("ABCDEFGHIJKLMNOPQRSTUVWXYZ12345", app.GetResource<engine::resources::Font>("builtin.mono")
1080.0f, width, height); ->GetTextBitmap("Welcome 2 my gaem", 128.0f, width, height);
uint32_t textbox = my_scene->CreateEntity("textbox"); uint32_t textbox =
my_scene->CreateEntity("textbox", 0, glm::vec3{0.0f, 0.8f, 0.0f});
auto textbox_renderable = auto textbox_renderable =
my_scene->AddComponent<engine::RenderableComponent>(textbox); my_scene->AddComponent<engine::RenderableComponent>(textbox);
textbox_renderable->material = textbox_renderable->material =
@ -152,8 +155,11 @@ void PlayGame(GameSettings settings) {
&app.render_data_, bitmap->data(), width, height, &app.render_data_, bitmap->data(), width, height,
engine::resources::Texture::Filtering::kAnisotropic); engine::resources::Texture::Filtering::kAnisotropic);
textbox_renderable->mesh = GenSphereMesh(app.gfxdev(), 1.0f, 5); textbox_renderable->mesh = GenSphereMesh(app.gfxdev(), 1.0f, 5);
my_scene->GetComponent<engine::TransformComponent>(textbox)->scale.y = auto textTransform =
(float)height / (float)width; my_scene->GetComponent<engine::TransformComponent>(textbox);
textTransform->scale.y =
(static_cast<float>(height) / static_cast<float>(width));
textTransform->scale *= 0.5f;
textbox_renderable->shown = true; textbox_renderable->shown = true;
auto textboxComponent = auto textboxComponent =