Dawn/src/dawnliminal/scenes/HelloWorldScene.hpp
2023-05-26 10:44:17 -07:00

69 lines
2.1 KiB
C++

// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "scene/Scene.hpp"
#include "prefabs/SimpleSpinningCubePrefab.hpp"
#include "prefabs/ui/debug/FPSLabel.hpp"
#include "scene/components/ui/UIImage.hpp"
#include "display/font/BitmapFont.hpp"
#include "display/font/NewTrueType.hpp"
namespace Dawn {
class HelloWorldScene : public Scene {
protected:
Camera *camera;
SimpleSpinningCubePrefab *cube;
FT_Face face;
Texture texture;
std::map<FT_ULong, struct TrueTypeCharacterInfo> charStore;
SceneItem *item;
void stage() override {
camera = Camera::create(this);
camera->transform->lookAt(glm::vec3(3, 3, 3), glm::vec3(0, 0, 0));
// cube = SimpleSpinningCubePrefab::create(this);
item = this->createSceneItem();
auto meshRenderer = item->addComponent<MeshRenderer>();
auto quadMeshHost = item->addComponent<QuadMeshHost>();
auto material = item->addComponent<SimpleTexturedMaterial>();
if(FT_New_Face(
this->game->renderManager.getFontManager()->fontLibrary,
"C:\\Windows\\Fonts\\Arial.ttf",
0,
&face
)) {
assertUnreachable();
}
if(FT_Set_Pixel_Sizes(face, 0, 16)) {
assertUnreachable();
}
_newTrueTypePlaceholder(face, texture, charStore);
FT_ULong c = 'B';
auto x = charStore[c];
glm::vec2 wh = glm::vec2(texture.getWidth(), texture.getHeight());
quadMeshHost->uv0 = glm::vec2(0.0f, x.textureY) / wh;
quadMeshHost->uv1 = (glm::vec2)quadMeshHost->uv0 + (x.bitmapSize / wh);
std::cout << "Done" << std::endl;
material->texture = &texture;
}
std::vector<Asset*> getRequiredAssets() override {
auto assMan = &this->game->assetManager;
std::vector<Asset*> assets;
vectorAppend(&assets, SimpleSpinningCubePrefab::getRequiredAssets(assMan));
return assets;
}
public:
HelloWorldScene(DawnGame *game) : Scene(game) {}
};
}