Testing UI without assets.
This commit is contained in:
Binary file not shown.
Before Width: | Height: | Size: 2.7 KiB |
@ -7,6 +7,7 @@
|
||||
target_sources(${DAWN_TARGET_NAME}
|
||||
PRIVATE
|
||||
BitmapFont.cpp
|
||||
ExampleFont.cpp
|
||||
TrueTypeFont.cpp
|
||||
FontMeasure.cpp
|
||||
)
|
104
src/dawn/display/font/ExampleFont.cpp
Normal file
104
src/dawn/display/font/ExampleFont.cpp
Normal file
@ -0,0 +1,104 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "ExampleFont.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
ExampleFont::ExampleFont() : realTilesetGrid(128/8, 64/8, 128, 64, 0, 0, 0, 0) {
|
||||
this->texture = &this->realTexture;
|
||||
this->tileset = &this->realTilesetGrid;
|
||||
}
|
||||
|
||||
struct Color ExampleFont::getColor(uint8_t n) {
|
||||
if(n == 0) return COLOR_TRANSPARENT;
|
||||
return COLOR_WHITE;
|
||||
}
|
||||
|
||||
void ExampleFont::init() {
|
||||
struct Color pixels[128*64];
|
||||
uint8_t data[] = {
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x30, 0xD8, 0x50, 0x78, 0xC8, 0x70, 0x30, 0x30, 0x60, 0x48, 0x20, 0x00, 0x00, 0x00, 0x18,
|
||||
0x00, 0x30, 0xD8, 0xF8, 0xA0, 0xD0, 0xC8, 0x30, 0x60, 0x30, 0x30, 0x20, 0x00, 0x00, 0x00, 0x30,
|
||||
0x00, 0x30, 0x90, 0x50, 0x70, 0x20, 0x60, 0x60, 0x60, 0x30, 0x78, 0xF8, 0x00, 0xF8, 0x00, 0x60,
|
||||
0x00, 0x00, 0x00, 0xF8, 0x28, 0x58, 0xD4, 0x00, 0x60, 0x30, 0x30, 0x20, 0x30, 0x00, 0x30, 0xC0,
|
||||
0x00, 0x30, 0x00, 0x50, 0xF0, 0x98, 0xC8, 0x00, 0x30, 0x60, 0x48, 0x20, 0x30, 0x00, 0x30, 0x80,
|
||||
0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x74, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x70, 0x10, 0xF0, 0xF0, 0x38, 0xF8, 0x70, 0xF8, 0x70, 0x70, 0x30, 0x30, 0x18, 0x00, 0x60, 0xF0,
|
||||
0x88, 0x30, 0x08, 0x08, 0x48, 0x80, 0x80, 0x08, 0x88, 0x88, 0x30, 0x30, 0x30, 0xF8, 0x30, 0x08,
|
||||
0x88, 0x10, 0x70, 0x30, 0x88, 0xF0, 0xF0, 0x10, 0x70, 0x78, 0x00, 0x00, 0x60, 0x00, 0x18, 0x70,
|
||||
0x88, 0x10, 0x80, 0x08, 0xF8, 0x08, 0x88, 0x20, 0x88, 0x08, 0x30, 0x30, 0x30, 0xF8, 0x30, 0x00,
|
||||
0x70, 0x10, 0xF8, 0xF0, 0x08, 0xF0, 0x70, 0x20, 0x70, 0x70, 0x30, 0x10, 0x18, 0x00, 0x60, 0x60,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x70, 0x70, 0xF0, 0x78, 0xF0, 0xF8, 0xF8, 0x78, 0x88, 0xF8, 0x08, 0x48, 0x80, 0x88, 0x88, 0x70,
|
||||
0x88, 0x88, 0x88, 0x80, 0x88, 0x80, 0x80, 0x80, 0x88, 0x20, 0x08, 0x50, 0x80, 0xD8, 0xC8, 0x88,
|
||||
0xB8, 0x88, 0xF0, 0x80, 0x88, 0xF0, 0xF0, 0xB8, 0xF8, 0x20, 0x08, 0x60, 0x80, 0xA8, 0xA8, 0x88,
|
||||
0x80, 0xF8, 0x88, 0x80, 0x88, 0x80, 0x80, 0x88, 0x88, 0x20, 0x88, 0x50, 0x80, 0x88, 0x98, 0x88,
|
||||
0x70, 0x88, 0xF0, 0x78, 0xF0, 0xF8, 0x80, 0x78, 0x88, 0xF8, 0x70, 0x48, 0xF8, 0x88, 0x88, 0x70,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0xF0, 0x70, 0xF0, 0x78, 0xF8, 0x88, 0x88, 0x88, 0x88, 0x88, 0xF8, 0xF0, 0x80, 0xF0, 0x20, 0x00,
|
||||
0x88, 0x88, 0x88, 0x80, 0x20, 0x88, 0x88, 0x88, 0x50, 0x50, 0x10, 0xC0, 0xC0, 0x30, 0x50, 0x00,
|
||||
0xF0, 0x88, 0xF0, 0x70, 0x20, 0x88, 0x88, 0xA8, 0x20, 0x20, 0x20, 0xC0, 0x60, 0x30, 0x88, 0x00,
|
||||
0x80, 0x88, 0xA0, 0x08, 0x20, 0x88, 0x50, 0xD8, 0x50, 0x20, 0x40, 0xC0, 0x30, 0x30, 0x00, 0x00,
|
||||
0x80, 0x70, 0x98, 0xF0, 0x20, 0x78, 0x20, 0x88, 0x88, 0x20, 0xF8, 0xF0, 0x18, 0xF0, 0x00, 0xF8,
|
||||
0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x30, 0x70, 0xF0, 0x78, 0xF0, 0xF8, 0xF8, 0x78, 0x88, 0x70, 0x08, 0x48, 0x40, 0x88, 0x88, 0x70,
|
||||
0x30, 0x88, 0x88, 0x80, 0x88, 0x80, 0x80, 0x80, 0x88, 0x20, 0x08, 0x50, 0x40, 0xD8, 0xC8, 0x88,
|
||||
0x18, 0x88, 0xF0, 0x80, 0x88, 0xF0, 0xF0, 0xB8, 0xF8, 0x20, 0x08, 0x60, 0x40, 0xA8, 0xA8, 0x88,
|
||||
0x00, 0xF8, 0x88, 0x80, 0x88, 0x80, 0x80, 0x88, 0x88, 0x20, 0x88, 0x50, 0x40, 0x88, 0x98, 0x88,
|
||||
0x00, 0x88, 0xF0, 0x78, 0xF0, 0xF8, 0x80, 0x78, 0x88, 0x70, 0x70, 0x48, 0x78, 0x88, 0x88, 0x70,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0xF0, 0x70, 0xF0, 0x78, 0xF8, 0x88, 0x88, 0x88, 0x88, 0x88, 0xF8, 0x70, 0x30, 0x70, 0x48, 0x00,
|
||||
0x88, 0x88, 0x88, 0x80, 0x20, 0x88, 0x88, 0x88, 0x50, 0x50, 0x10, 0x60, 0x30, 0x30, 0xB0, 0x00,
|
||||
0xF0, 0x88, 0xF0, 0x70, 0x20, 0x88, 0x88, 0xA8, 0x20, 0x20, 0x20, 0xC0, 0x30, 0x18, 0x00, 0x00,
|
||||
0x80, 0x88, 0xA0, 0x08, 0x20, 0x88, 0x50, 0xD8, 0x50, 0x20, 0x40, 0x60, 0x30, 0x30, 0x00, 0x00,
|
||||
0x80, 0x70, 0x98, 0xF0, 0x20, 0x78, 0x20, 0x88, 0x88, 0x20, 0xF8, 0x70, 0x30, 0x70, 0x00, 0x00,
|
||||
0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
|
||||
};
|
||||
|
||||
int32_t j = 0;
|
||||
for(int32_t i = 0; i < ((128/8) * 64); i++) {
|
||||
uint8_t n = data[i];
|
||||
pixels[j++] = this->getColor(n & 0x80);
|
||||
pixels[j++] = this->getColor(n & 0x40);
|
||||
pixels[j++] = this->getColor(n & 0x20);
|
||||
pixels[j++] = this->getColor(n & 0x10);
|
||||
pixels[j++] = this->getColor(n & 0x08);
|
||||
pixels[j++] = this->getColor(n & 0x04);
|
||||
pixels[j++] = this->getColor(n & 0x02);
|
||||
pixels[j++] = this->getColor(n & 0x01);
|
||||
}
|
||||
|
||||
this->realTexture.setSize(128, 64);
|
||||
this->realTexture.buffer(pixels);
|
||||
}
|
22
src/dawn/display/font/ExampleFont.hpp
Normal file
22
src/dawn/display/font/ExampleFont.hpp
Normal file
@ -0,0 +1,22 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "BitmapFont.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
class ExampleFont : public BitmapFont {
|
||||
protected:
|
||||
Texture realTexture;
|
||||
TilesetGrid realTilesetGrid;
|
||||
|
||||
struct Color getColor(uint8_t n);
|
||||
|
||||
public:
|
||||
ExampleFont();
|
||||
|
||||
void init();
|
||||
};
|
||||
}
|
@ -12,7 +12,7 @@ UILabel::UILabel(SceneItem *item) :
|
||||
UIComponent(item),
|
||||
text(""),
|
||||
fontSize(10.0f),
|
||||
font(nullptr),
|
||||
font(&item->scene->game->renderManager.defaultFont),
|
||||
maxWidth(UI_LABEL_MAX_WIDTH_NONE)
|
||||
{
|
||||
}
|
||||
|
@ -6,17 +6,39 @@
|
||||
#pragma once
|
||||
#include "scene/Scene.hpp"
|
||||
#include "prefabs/SimpleSpinningCubePrefab.hpp"
|
||||
#include "scene/components/ui/UILabel.hpp"
|
||||
#include "scene/components/ui/UIImage.hpp"
|
||||
#include "display/font/BitmapFont.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
class HelloWorldScene : public Scene {
|
||||
protected:
|
||||
Camera *camera;
|
||||
SimpleSpinningCubePrefab *cube;
|
||||
UICanvas *canvas;
|
||||
UILabel *label;
|
||||
UIImage *image;
|
||||
BitmapFont font;
|
||||
|
||||
void stage() override {
|
||||
camera = Camera::create(this);
|
||||
camera->transform->lookAt(glm::vec3(3, 3, 3), glm::vec3(0, 0, 0));
|
||||
|
||||
cube = SimpleSpinningCubePrefab::create(this);
|
||||
|
||||
canvas = UICanvas::create(this);
|
||||
|
||||
auto imageItem = this->createSceneItem();
|
||||
image = imageItem->addComponent<UIImage>();
|
||||
image->color = COLOR_BLACK;
|
||||
imageItem->transform.setParent(canvas->transform);
|
||||
|
||||
auto labelItem = this->createSceneItem();
|
||||
label = labelItem->addComponent<UILabel>();
|
||||
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());
|
||||
}
|
||||
|
||||
std::vector<Asset*> getRequiredAssets() override {
|
||||
|
@ -18,15 +18,15 @@ RenderManager::RenderManager(DawnGame *game) :
|
||||
|
||||
void RenderManager::init() {
|
||||
this->renderPipeline.init();
|
||||
|
||||
this->simpleShader.compile();
|
||||
this->uiShaderProgram.compile();
|
||||
|
||||
// Prepare the initial values
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
glDepthMask(GL_TRUE);
|
||||
glDepthFunc(GL_LESS);
|
||||
|
||||
this->defaultFont.init();
|
||||
}
|
||||
|
||||
RenderTarget * RenderManager::getBackBuffer() {
|
||||
|
@ -9,6 +9,7 @@
|
||||
#include "display/shader/SimpleTexturedShader.hpp"
|
||||
#include "display/shader/UIShaderProgram.hpp"
|
||||
#include "display/RenderPipeline.hpp"
|
||||
#include "display/font/ExampleFont.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
class RenderManager : public IRenderManager {
|
||||
@ -19,6 +20,7 @@ namespace Dawn {
|
||||
BackBufferRenderTarget backBuffer;
|
||||
SimpleTexturedShader simpleShader;
|
||||
UIShaderProgram uiShaderProgram;
|
||||
ExampleFont defaultFont;
|
||||
|
||||
/**
|
||||
* Construct a new RenderManager for a game instance.
|
||||
|
Reference in New Issue
Block a user