TTF Prog
This commit is contained in:
@ -8,7 +8,125 @@
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
void _uiLabelBake(
|
||||
UILabelNew::UILabelNew(SceneItem *item) : UIComponentRenderable(item) {
|
||||
|
||||
}
|
||||
|
||||
void UILabelNew::onStart() {
|
||||
this->shaderBuffer.init();
|
||||
|
||||
if(FT_New_Face(
|
||||
getGame()->renderManager.getFontManager()->fontLibrary,
|
||||
"/usr/share/fonts/TTF/arial.ttf",
|
||||
// "C:\\Windows\\Fonts\\arial.ttf",
|
||||
0,
|
||||
&face
|
||||
)) {
|
||||
assertUnreachable();
|
||||
}
|
||||
UILabelNew::bakeTexture(defFace, face, 32);
|
||||
|
||||
|
||||
if(FT_New_Face(
|
||||
getGame()->renderManager.getFontManager()->fontLibrary,
|
||||
"/usr/share/fonts/TTF/arialbd.ttf",
|
||||
// "C:\\Windows\\Fonts\\arialbd.ttf",
|
||||
0,
|
||||
&faceBold
|
||||
)) {
|
||||
assertUnreachable();
|
||||
}
|
||||
UILabelNew::bakeTexture(defFaceBold, faceBold, 32);
|
||||
|
||||
|
||||
if(FT_New_Face(
|
||||
getGame()->renderManager.getFontManager()->fontLibrary,
|
||||
"/usr/share/fonts/TTF/ariali.ttf",
|
||||
// "C:\\Windows\\Fonts\\ariali.ttf",
|
||||
0,
|
||||
&faceItalics
|
||||
)) {
|
||||
assertUnreachable();
|
||||
}
|
||||
UILabelNew::bakeTexture(defFaceItalics, faceItalics, 32);
|
||||
|
||||
struct FontShaderBufferData fontData;
|
||||
glm::vec2 position = glm::vec2(32, 32);
|
||||
|
||||
mesh.createBuffers(QUAD_VERTICE_COUNT * 128, QUAD_INDICE_COUNT * 128);
|
||||
auto x = UILabelNew::bufferQuads(
|
||||
"Hello ",
|
||||
fontData,
|
||||
defFace,
|
||||
position,
|
||||
0,
|
||||
0
|
||||
);
|
||||
x += UILabelNew::bufferQuads(
|
||||
" World",
|
||||
fontData,
|
||||
defFaceItalics,
|
||||
position,
|
||||
x,
|
||||
1
|
||||
);
|
||||
x += UILabelNew::bufferQuads(
|
||||
" How are you?",
|
||||
fontData,
|
||||
defFaceBold,
|
||||
position,
|
||||
x,
|
||||
2
|
||||
);
|
||||
|
||||
fontData.colors[0] = COLOR_MAGENTA;
|
||||
fontData.textures[0] = 0;
|
||||
fontData.colors[1] = COLOR_RED;
|
||||
fontData.textures[1] = 1;
|
||||
fontData.colors[2] = COLOR_GREEN;
|
||||
fontData.textures[2] = 2;
|
||||
shaderBuffer.buffer(&fontData);
|
||||
}
|
||||
|
||||
std::vector<struct ShaderPassItem> UILabelNew::getUIRenderPasses() {
|
||||
auto canvas = this->getCanvas();
|
||||
auto shader = getGame()->renderManager.fontShader;
|
||||
|
||||
struct ShaderPassItem item;
|
||||
item.shader = shader;
|
||||
item.mesh = &this->mesh;
|
||||
item.matrixValues[shader->paramModel] = transform->getWorldTransform();
|
||||
item.parameterBuffers[shader->bufferUiCanvas] = &canvas->shaderBuffer;
|
||||
item.parameterBuffers[shader->bufferFont] = &this->shaderBuffer;
|
||||
item.renderFlags = RENDER_MANAGER_RENDER_FLAG_BLEND;
|
||||
item.textureSlots[0] = &defFace.texture;
|
||||
item.textureSlots[1] = &defFaceItalics.texture;
|
||||
item.textureSlots[2] = &defFaceBold.texture;
|
||||
item.textureValues[shader->paramTexture0] = 0;
|
||||
item.textureValues[shader->paramTexture1] = 1;
|
||||
item.textureValues[shader->paramTexture2] = 2;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
void UILabelNew::bakeTexture(
|
||||
struct UILabelFontDef &fontDef,
|
||||
FT_Face &face,
|
||||
uint32_t fontSize
|
||||
@ -78,155 +196,45 @@ void _uiLabelBake(
|
||||
memoryFree(buffer);
|
||||
}
|
||||
|
||||
|
||||
|
||||
int32_t _uiLabelQuad(
|
||||
int32_t UILabelNew::bufferQuads(
|
||||
std::string text,
|
||||
Mesh *mesh,
|
||||
struct FontShaderBufferData &bufferData,
|
||||
struct UILabelFontDef &fontDef,
|
||||
glm::vec2 &position,
|
||||
int32_t quadStart,
|
||||
int32_t partIndex
|
||||
) {
|
||||
// Get string length
|
||||
int32_t len = text.length();
|
||||
if(mesh == nullptr) return len;
|
||||
|
||||
// Loop each char
|
||||
|
||||
glm::vec2 wh = glm::vec2(fontDef.texture.getWidth(), fontDef.texture.getHeight());
|
||||
|
||||
// For each char
|
||||
for(int32_t i = 0; i < len; i++) {
|
||||
char ch = text[i];
|
||||
int32_t j = quadStart + i;
|
||||
FT_ULong c = text[i];
|
||||
FT_ULong c = ch;
|
||||
auto &charInfo = fontDef.charStore[c];
|
||||
|
||||
// Determine texture coordinates.
|
||||
glm::vec2 uv0 = glm::vec2(0.0f, charInfo.textureY) / wh;
|
||||
glm::vec2 uv1 = uv0 + (charInfo.bitmapSize / wh);
|
||||
|
||||
QuadMesh::bufferQuadMeshWithZ(mesh,
|
||||
// Buffer the quad.
|
||||
QuadMesh::bufferQuadMeshWithZ(&this->mesh,
|
||||
position + charInfo.bitmapPosition, uv0,
|
||||
position + charInfo.bitmapPosition + charInfo.bitmapSize, uv1,
|
||||
0.0f,
|
||||
j * QUAD_VERTICE_COUNT, j * QUAD_INDICE_COUNT
|
||||
);
|
||||
|
||||
// Move the current position along.
|
||||
position.x += (float_t)(charInfo.advanceX >> 6);
|
||||
position.y += (float_t)(charInfo.advanceY >> 6);
|
||||
bufferData.fontQuadParts[j] = partIndex;
|
||||
|
||||
// Set the part index to the quad mappings
|
||||
bufferData.fontQuadMappings[j] = partIndex;
|
||||
}
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
|
||||
|
||||
UILabelNew::UILabelNew(SceneItem *item) : UIComponentRenderable(item) {
|
||||
|
||||
}
|
||||
|
||||
void UILabelNew::onStart() {
|
||||
std::cout << "Hello new Label" << std::endl;
|
||||
this->shaderBuffer.init();
|
||||
|
||||
|
||||
if(FT_New_Face(
|
||||
getGame()->renderManager.getFontManager()->fontLibrary,
|
||||
// "/usr/share/fonts/TTF/arial.ttf",
|
||||
"C:\\Windows\\Fonts\\arial.ttf",
|
||||
0,
|
||||
&face
|
||||
)) {
|
||||
assertUnreachable();
|
||||
}
|
||||
_uiLabelBake(defFace, face, 32);
|
||||
|
||||
|
||||
if(FT_New_Face(
|
||||
getGame()->renderManager.getFontManager()->fontLibrary,
|
||||
// "/usr/share/fonts/TTF/arialbd.ttf",
|
||||
"C:\\Windows\\Fonts\\arialbd.ttf",
|
||||
0,
|
||||
&faceBold
|
||||
)) {
|
||||
assertUnreachable();
|
||||
}
|
||||
_uiLabelBake(defFaceBold, faceBold, 32);
|
||||
|
||||
|
||||
if(FT_New_Face(
|
||||
getGame()->renderManager.getFontManager()->fontLibrary,
|
||||
// "/usr/share/fonts/TTF/ariali.ttf",
|
||||
"C:\\Windows\\Fonts\\ariali.ttf",
|
||||
0,
|
||||
&faceItalics
|
||||
)) {
|
||||
assertUnreachable();
|
||||
}
|
||||
_uiLabelBake(defFaceItalics, faceItalics, 32);
|
||||
|
||||
struct FontShaderBufferData fontData;
|
||||
|
||||
glm::vec2 position = glm::vec2(32, 32);
|
||||
|
||||
testMesh.createBuffers(QUAD_VERTICE_COUNT * 96, QUAD_INDICE_COUNT * 96);
|
||||
auto x = _uiLabelQuad(
|
||||
"Hello ",
|
||||
&this->testMesh,
|
||||
fontData,
|
||||
defFace,
|
||||
position,
|
||||
0,
|
||||
0
|
||||
);
|
||||
x += _uiLabelQuad(
|
||||
"World",
|
||||
&this->testMesh,
|
||||
fontData,
|
||||
defFaceItalics,
|
||||
position,
|
||||
x,
|
||||
1
|
||||
);
|
||||
|
||||
fontData.fontParts[0].color = COLOR_MAGENTA;
|
||||
fontData.fontParts[0].texture = 0;
|
||||
fontData.fontParts[1].color = COLOR_RED;
|
||||
fontData.fontParts[1].texture = 1;
|
||||
shaderBuffer.buffer(&fontData);
|
||||
}
|
||||
|
||||
std::vector<struct ShaderPassItem> UILabelNew::getUIRenderPasses() {
|
||||
auto canvas = this->getCanvas();
|
||||
auto shader = getGame()->renderManager.fontShader;
|
||||
|
||||
struct ShaderPassItem item;
|
||||
item.shader = shader;
|
||||
item.mesh = &testMesh;
|
||||
item.matrixValues[shader->paramModel] = transform->getWorldTransform();
|
||||
item.parameterBuffers[shader->bufferUiCanvas] = &canvas->shaderBuffer;
|
||||
item.parameterBuffers[shader->bufferFont] = &this->shaderBuffer;
|
||||
item.renderFlags = RENDER_MANAGER_RENDER_FLAG_BLEND;
|
||||
item.textureSlots[0] = &defFace.texture;
|
||||
item.textureSlots[1] = &defFaceItalics.texture;
|
||||
item.textureValues[shader->paramTexture0] = 0;
|
||||
item.textureValues[shader->paramTexture1] = 1;
|
||||
|
||||
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;
|
||||
}
|
@ -7,38 +7,17 @@
|
||||
#include "scene/components/ui/UIComponentRenderable.hpp"
|
||||
#include "display/mesh/QuadMesh.hpp"
|
||||
|
||||
|
||||
#define NEW_LABEL_CHAR_BEGIN 32
|
||||
#define NEW_LABEL_CHAR_END 192
|
||||
|
||||
namespace Dawn {
|
||||
struct UILabelChar {
|
||||
int32_t advanceX;
|
||||
int32_t advanceY;
|
||||
glm::vec2 bitmapSize;
|
||||
glm::vec2 bitmapPosition;
|
||||
float_t textureY;
|
||||
};
|
||||
|
||||
struct UILabelFontDef {
|
||||
Texture texture;
|
||||
uint32_t fontSize;
|
||||
FT_Face *face;
|
||||
std::map<FT_ULong, struct UILabelChar> charStore;
|
||||
};
|
||||
|
||||
struct UILabelPart {
|
||||
struct UILabelStyle {
|
||||
struct Color;
|
||||
UILabelFontDef *fontDef;
|
||||
std::string text;
|
||||
};
|
||||
|
||||
class UILabelNew : public UIComponentRenderable {
|
||||
protected:
|
||||
private:
|
||||
Mesh mesh;
|
||||
FontShaderBuffer shaderBuffer;
|
||||
|
||||
Mesh testMesh;
|
||||
|
||||
FT_Face face;
|
||||
FT_Face faceBold;
|
||||
FT_Face faceItalics;
|
||||
@ -47,6 +26,27 @@ namespace Dawn {
|
||||
struct UILabelFontDef defFaceBold;
|
||||
struct UILabelFontDef defFaceItalics;
|
||||
|
||||
/**
|
||||
* Buffers the quads for the given text and updates the progressing values
|
||||
* as the buffer process continues.
|
||||
*
|
||||
* @param text Text to buffer.
|
||||
* @param bufferData The output quad mappings for the text.
|
||||
* @param fontDef The font definition to use.
|
||||
* @param position The 2D position to buffer the quads at.
|
||||
* @param quadStart The starting quad index.
|
||||
* @param partIndex The part index to store for each quad buffered.
|
||||
* @return The number of quads buffered, not the string length.
|
||||
*/
|
||||
int32_t bufferQuads(
|
||||
std::string text,
|
||||
struct FontShaderBufferData &bufferData,
|
||||
struct UILabelFontDef &fontDef,
|
||||
glm::vec2 &position,
|
||||
int32_t quadStart,
|
||||
int32_t partIndex
|
||||
);
|
||||
|
||||
public:
|
||||
UILabelNew(SceneItem *item);
|
||||
|
||||
|
Reference in New Issue
Block a user