Fixed some bugs with buffers during font building

This commit is contained in:
2023-05-31 10:47:06 -07:00
parent e3d0070e95
commit 970e98f49a
14 changed files with 186 additions and 76 deletions

View File

@ -8,55 +8,46 @@
namespace Dawn {
struct Color {
uint8_t r, g, b, a;
glm::vec4 precision() {
return {
(float_t)r / 255.0f,
(float_t)g / 255.0f,
(float_t)b / 255.0f,
(float_t)a / 100.0f
};
}
float_t r, g, b, a;
struct Color operator * (const float_t &x) {
return {
(uint8_t)(r * x),
(uint8_t)(g * x),
(uint8_t)(b * x),
(uint8_t)(a * x)
r * x,
g * x,
b * x,
a * x
};
}
struct Color operator - (const struct Color &color) {
return {
(uint8_t)(r - color.r),
(uint8_t)(g - color.g),
(uint8_t)(b - color.b),
(uint8_t)(a - color.a)
r - color.r,
g - color.g,
b - color.b,
a - color.a
};
}
struct Color operator + (const struct Color &color) {
return {
(uint8_t)(r + color.r),
(uint8_t)(g + color.g),
(uint8_t)(b + color.b),
(uint8_t)(a + color.a)
r + color.r,
g + color.g,
b + color.b,
a + color.a
};
}
};
#define COLOR_WHITE { 255, 255, 255, 255 }
#define COLOR_RED { 255, 0, 0, 255 }
#define COLOR_GREEN { 0, 255, 0, 255 }
#define COLOR_BLUE { 0, 0, 255, 255 }
#define COLOR_BLACK { 0, 0, 0, 255 }
#define COLOR_MAGENTA { 255, 0, 255, 255 }
#define COLOR_DARK_GREY { 50, 50, 50, 255 }
#define COLOR_LIGHT_GREY { 204, 204, 204, 255 }
#define COLOR_CORNFLOWER_BLUE { 100, 149, 237, 255 }
#define COLOR_WHITE_TRANSPARENT { 255, 255, 255, 0 }
#define COLOR_WHITE { 1.0f, 1.0f, 1.0f, 1.0f }
#define COLOR_RED { 1.0f, 0, 0, 1.0f }
#define COLOR_GREEN { 0, 1.0f, 0, 1.0f }
#define COLOR_BLUE { 0, 0, 1.0f, 1.0f }
#define COLOR_BLACK { 0, 0, 0, 1.0f }
#define COLOR_MAGENTA { 1.0f, 0, 1.0f, 1.0f }
#define COLOR_DARK_GREY { 0.19607843137254901961f, 0.19607843137254901961f, 0.19607843137254901961f, 1.0f }
#define COLOR_LIGHT_GREY { 0.8f, 0.8f, 0.8f, 1.0f }
#define COLOR_CORNFLOWER_BLUE { 0.39215686274509803922f, 0.58431372549019607843f, 0.92941176470588235294f, 1.0f }
#define COLOR_WHITE_TRANSPARENT { 1.0f, 1.0f, 1.0f, 0 }
#define COLOR_BLACK_TRANSPARENT { 0, 0, 0, 0 }
#define COLOR_TRANSPARENT COLOR_BLACK_TRANSPARENT
}

View File

@ -12,6 +12,7 @@ target_sources(${DAWN_TARGET_NAME}
UILabel.cpp
UIImage.cpp
UIBorder.cpp
UILabelNew.cpp
)
add_subdirectory(menu)

View File

@ -0,0 +1,58 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#include "UILabelNew.hpp"
#include "game/DawnGame.hpp"
using namespace Dawn;
UILabelNew::UILabelNew(SceneItem *item) : UIComponentRenderable(item) {
}
void UILabelNew::onStart() {
std::cout << "Hello new Label" << std::endl;
QuadMesh::initQuadMesh(&this->mesh,
glm::vec2(0, 0), glm::vec2(0, 0),
glm::vec2(32, 32), glm::vec2(1, 1),
0.0f
);
this->shaderBuffer.init();
}
std::vector<struct ShaderPassItem> UILabelNew::getUIRenderPasses() {
auto canvas = this->getCanvas();
auto shader = getGame()->renderManager.fontShader;
struct ShaderPassItem item;
item.shader = shader;
item.mesh = &mesh;
item.matrixValues[shader->paramModel] = transform->getWorldTransform();
item.parameterBuffers[shader->bufferUiCanvas] = &canvas->shaderBuffer;
item.parameterBuffers[shader->bufferFont] = &this->shaderBuffer;
struct FontShaderBufferData fontData;
fontData.fontParts[9].color = COLOR_BLUE;
shaderBuffer.buffer(&fontData);
return { item };
}
float_t UILabelNew::getWidth() {
return 0;
}
float_t UILabelNew::getHeight() {
return 0;
}
float_t UILabelNew::getContentWidth() {
return 0;
}
float_t UILabelNew::getContentHeight() {
return 0;
}

View File

@ -0,0 +1,26 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "scene/components/ui/UIComponentRenderable.hpp"
#include "display/mesh/QuadMesh.hpp"
namespace Dawn {
class UILabelNew : public UIComponentRenderable {
protected:
Mesh mesh;
FontShaderBuffer shaderBuffer;
public:
UILabelNew(SceneItem *item);
void onStart() override;
std::vector<struct ShaderPassItem> getUIRenderPasses() override;
float_t getWidth() override;
float_t getHeight() override;
float_t getContentWidth() override;
float_t getContentHeight() override;
};
}