Font Testing
This commit is contained in:
BIN
assets/ark-pixel.ttf
Normal file
BIN
assets/ark-pixel.ttf
Normal file
Binary file not shown.
@ -7,4 +7,5 @@
|
|||||||
target_sources(${DAWN_TARGET_NAME}
|
target_sources(${DAWN_TARGET_NAME}
|
||||||
PRIVATE
|
PRIVATE
|
||||||
TextureAsset.cpp
|
TextureAsset.cpp
|
||||||
|
TrueTypeAsset.cpp
|
||||||
)
|
)
|
@ -15,20 +15,22 @@ TextureAsset::TextureAsset(AssetManager &assetManager, std::string name) :
|
|||||||
}
|
}
|
||||||
|
|
||||||
void TextureAsset::updateSync() {
|
void TextureAsset::updateSync() {
|
||||||
if(this->state == 0x00 || this->state == 0x01) return;
|
if(
|
||||||
|
this->state != 0x03
|
||||||
|
) return;
|
||||||
|
|
||||||
this->state = 0x03;
|
this->state = 0x04;
|
||||||
this->texture->setSize(this->width, this->height);
|
this->texture->setSize(this->width, this->height);
|
||||||
this->texture->buffer(this->colors);
|
this->texture->buffer(this->colors);
|
||||||
this->state = 0x04;
|
this->state = 0x05;
|
||||||
this->loaded = true;
|
this->loaded = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TextureAsset::updateAsync() {
|
void TextureAsset::updateAsync() {
|
||||||
if(this->state != 0x00) return;
|
if(this->state != 0x00) return;
|
||||||
this->loader.loadRaw(&this->buffer);
|
|
||||||
|
|
||||||
this->state = 0x01;
|
this->state = 0x01;
|
||||||
|
this->loader.loadRaw(&this->buffer);
|
||||||
|
this->state = 0x02;
|
||||||
|
|
||||||
// Parse header data.
|
// Parse header data.
|
||||||
char integer[32];
|
char integer[32];
|
||||||
@ -52,7 +54,7 @@ void TextureAsset::updateAsync() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this->colors = (struct Color *)((void *)(this->buffer + i));
|
this->colors = (struct Color *)((void *)(this->buffer + i));
|
||||||
this->state = 0x02;
|
this->state = 0x03;
|
||||||
}
|
}
|
||||||
|
|
||||||
TextureAsset::~TextureAsset() {
|
TextureAsset::~TextureAsset() {
|
||||||
|
76
src/dawn/asset/assets/TrueTypeAsset.cpp
Normal file
76
src/dawn/asset/assets/TrueTypeAsset.cpp
Normal file
@ -0,0 +1,76 @@
|
|||||||
|
// Copyright (c) 2022 Dominic Masters
|
||||||
|
//
|
||||||
|
// This software is released under the MIT License.
|
||||||
|
// https://opensource.org/licenses/MIT
|
||||||
|
|
||||||
|
#include "TrueTypeAsset.hpp"
|
||||||
|
|
||||||
|
using namespace Dawn;
|
||||||
|
|
||||||
|
TrueTypeAsset::TrueTypeAsset(AssetManager &assMan, std::string name) :
|
||||||
|
Asset(assMan, name),
|
||||||
|
loader(name + ".truetype")
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void TrueTypeAsset::updateSync() {
|
||||||
|
if(this->state != 0x04) return;
|
||||||
|
this->font.texture.setSize(this->width, this->height);
|
||||||
|
this->font.texture.buffer(this->pixels);
|
||||||
|
auto i = this->pixels;
|
||||||
|
memoryCopy(
|
||||||
|
this->characterData,
|
||||||
|
this->font.characterData,
|
||||||
|
sizeof(truetypechar_t) * TRUETYPE_NUM_CHARS
|
||||||
|
);
|
||||||
|
this->state = 0x05;
|
||||||
|
this->loaded = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void TrueTypeAsset::updateAsync() {
|
||||||
|
int32_t fontSize;
|
||||||
|
size_t i, j;
|
||||||
|
char intBuffer[32];
|
||||||
|
char c;
|
||||||
|
|
||||||
|
if(this->state != 0x00) return;
|
||||||
|
|
||||||
|
this->state = 0x01;
|
||||||
|
this->loader.loadRaw(&this->buffer);
|
||||||
|
this->state = 0x02;
|
||||||
|
|
||||||
|
// Parse header data.
|
||||||
|
i = j = 0;
|
||||||
|
width = -1, height = -1, fontSize = -1;
|
||||||
|
while(true) {
|
||||||
|
c = this->buffer[i++];
|
||||||
|
if(c == '|') {
|
||||||
|
intBuffer[j] = '\0';
|
||||||
|
if(width == -1) {
|
||||||
|
this->width = atoi(intBuffer);
|
||||||
|
j = 0;
|
||||||
|
continue;
|
||||||
|
} else if(height == -1) {
|
||||||
|
this->height = atoi(intBuffer);
|
||||||
|
j = 0;
|
||||||
|
continue;
|
||||||
|
} else {
|
||||||
|
fontSize = atoi(intBuffer);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
intBuffer[j++] = c;
|
||||||
|
}
|
||||||
|
|
||||||
|
this->state = 0x03;
|
||||||
|
this->font.fontSize = fontSize;
|
||||||
|
this->pixels = (struct Color*)(this->buffer + i);
|
||||||
|
this->characterData = (truetypechar_t*)(
|
||||||
|
(uint8_t*)this->pixels + (this->width * this->height * sizeof(struct Color))
|
||||||
|
);
|
||||||
|
this->state = 0x04;
|
||||||
|
}
|
||||||
|
|
||||||
|
TrueTypeAsset::~TrueTypeAsset() {
|
||||||
|
|
||||||
|
}
|
30
src/dawn/asset/assets/TrueTypeAsset.hpp
Normal file
30
src/dawn/asset/assets/TrueTypeAsset.hpp
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
// Copyright (c) 2022 Dominic Masters
|
||||||
|
//
|
||||||
|
// This software is released under the MIT License.
|
||||||
|
// https://opensource.org/licenses/MIT
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
#include "../Asset.hpp"
|
||||||
|
#include "../AssetLoader.hpp"
|
||||||
|
#include "display/font/TrueTypeFont.hpp"
|
||||||
|
|
||||||
|
namespace Dawn {
|
||||||
|
class TrueTypeAsset : public Asset {
|
||||||
|
protected:
|
||||||
|
AssetLoader loader;
|
||||||
|
uint8_t *buffer = nullptr;
|
||||||
|
truetypechar_t *characterData = nullptr;
|
||||||
|
struct Color *pixels = nullptr;
|
||||||
|
int32_t width, height;
|
||||||
|
|
||||||
|
public:
|
||||||
|
TrueTypeFont font;
|
||||||
|
|
||||||
|
TrueTypeAsset(AssetManager &assMan, std::string name);
|
||||||
|
|
||||||
|
void updateSync() override;
|
||||||
|
void updateAsync() override;
|
||||||
|
|
||||||
|
~TrueTypeAsset();
|
||||||
|
};
|
||||||
|
}
|
@ -152,8 +152,8 @@ Transform * Transform::getParent() {
|
|||||||
Transform::~Transform() {
|
Transform::~Transform() {
|
||||||
this->setParent(nullptr);
|
this->setParent(nullptr);
|
||||||
|
|
||||||
auto it = this->parent->children.begin();
|
auto it = this->children.begin();
|
||||||
while(it != this->parent->children.end()) {
|
while(it != this->children.end()) {
|
||||||
(*it)->setParent(nullptr);
|
(*it)->setParent(nullptr);
|
||||||
++it;
|
++it;
|
||||||
}
|
}
|
||||||
|
@ -7,4 +7,15 @@
|
|||||||
target_sources(${DAWN_TARGET_NAME}
|
target_sources(${DAWN_TARGET_NAME}
|
||||||
PRIVATE
|
PRIVATE
|
||||||
TrueTypeFont.cpp
|
TrueTypeFont.cpp
|
||||||
)
|
FontMeasure.cpp
|
||||||
|
)
|
||||||
|
|
||||||
|
tool_truetype(truetype_ark
|
||||||
|
ark-pixel.ttf
|
||||||
|
truetype_ark
|
||||||
|
96
|
||||||
|
96
|
||||||
|
10
|
||||||
|
)
|
||||||
|
|
||||||
|
add_dependencies(${DAWN_TARGET_NAME} truetype_ark)
|
@ -10,40 +10,25 @@
|
|||||||
#include "util/mathutils.hpp"
|
#include "util/mathutils.hpp"
|
||||||
#include "display/Texture.hpp"
|
#include "display/Texture.hpp"
|
||||||
#include "display/mesh/QuadMesh.hpp"
|
#include "display/mesh/QuadMesh.hpp"
|
||||||
|
#include "FontMeasure.hpp"
|
||||||
|
|
||||||
#define FONT_NEWLINE '\n'
|
#define FONT_NEWLINE '\n'
|
||||||
#define FONT_SPACE ' '
|
#define FONT_SPACE ' '
|
||||||
|
|
||||||
namespace Dawn {
|
namespace Dawn {
|
||||||
class FontMeasure {
|
|
||||||
public:
|
|
||||||
virtual float_t getWidth() = 0;
|
|
||||||
virtual float_t getHeight() = 0;
|
|
||||||
virtual int32_t getQuadsOnLine(int32_t line);
|
|
||||||
virtual int32_t getQuadIndexOnLine(int32_t line);
|
|
||||||
virtual int32_t getLineCount();
|
|
||||||
virtual int32_t getQuadCount();
|
|
||||||
};
|
|
||||||
|
|
||||||
class Font {
|
class Font {
|
||||||
public:
|
public:
|
||||||
Font();
|
|
||||||
|
|
||||||
virtual void init() = 0;
|
|
||||||
|
|
||||||
virtual void buffer(
|
virtual void buffer(
|
||||||
std::string text,
|
std::string text,
|
||||||
float_t fontSize,
|
float_t fontSize,
|
||||||
float_t maxWidth,
|
float_t maxWidth,
|
||||||
Mesh &mesh,
|
Mesh &mesh,
|
||||||
FontMeasure &measure
|
struct FontMeasure *info
|
||||||
) = 0;
|
) = 0;
|
||||||
|
|
||||||
virtual Texture & getTexture() = 0;
|
virtual Texture & getTexture() = 0;
|
||||||
virtual void draw(Mesh &mesh, int32_t startCharacter, int32_t length) = 0;
|
virtual void draw(Mesh &mesh, int32_t startCharacter, int32_t length) = 0;
|
||||||
virtual float_t getLineHeight(float_t fontSize) = 0;
|
virtual float_t getLineHeight(float_t fontSize) = 0;
|
||||||
virtual float_t getDefaultFontSize() = 0;
|
virtual float_t getDefaultFontSize() = 0;
|
||||||
|
|
||||||
virtual ~Font();
|
|
||||||
};
|
};
|
||||||
}
|
}
|
39
src/dawn/display/font/FontMeasure.cpp
Normal file
39
src/dawn/display/font/FontMeasure.cpp
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
// Copyright (c) 2022 Dominic Masters
|
||||||
|
//
|
||||||
|
// This software is released under the MIT License.
|
||||||
|
// https://opensource.org/licenses/MIT
|
||||||
|
|
||||||
|
#include "FontMeasure.hpp"
|
||||||
|
|
||||||
|
using namespace Dawn;
|
||||||
|
|
||||||
|
float_t FontMeasure::getWidth() {
|
||||||
|
return this->width;
|
||||||
|
}
|
||||||
|
|
||||||
|
float_t FontMeasure::getHeight() {
|
||||||
|
return this->height;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t FontMeasure::getQuadCount() {
|
||||||
|
return this->realLength;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t FontMeasure::getLineCount() {
|
||||||
|
return this->lines.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t FontMeasure::getQuadsOnLine(int32_t line) {
|
||||||
|
return this->lines[line].length;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t FontMeasure::getQuadIndexOnLine(int32_t line) {
|
||||||
|
return this->lines[line].start;
|
||||||
|
}
|
||||||
|
|
||||||
|
void FontMeasure::addLine(int32_t start, int32_t len) {
|
||||||
|
struct FontLineMeasure info;
|
||||||
|
info.start = start;
|
||||||
|
info.length = len;
|
||||||
|
this->lines.push_back(info);
|
||||||
|
}
|
46
src/dawn/display/font/FontMeasure.hpp
Normal file
46
src/dawn/display/font/FontMeasure.hpp
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
// Copyright (c) 2022 Dominic Masters
|
||||||
|
//
|
||||||
|
// This software is released under the MIT License.
|
||||||
|
// https://opensource.org/licenses/MIT
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
#include "dawnlibs.hpp"
|
||||||
|
|
||||||
|
namespace Dawn {
|
||||||
|
struct FontLineMeasure {
|
||||||
|
/** What (real character) index the line starts at */
|
||||||
|
int32_t start;
|
||||||
|
/** How many (real) characters the line is in length */
|
||||||
|
int32_t length;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct FontMeasure {
|
||||||
|
public:
|
||||||
|
/** How many raw chars are in the string */
|
||||||
|
int32_t length;
|
||||||
|
|
||||||
|
/** How many real characters (non whitespace) are in the string */
|
||||||
|
int32_t realLength;
|
||||||
|
|
||||||
|
/** The real character info for each line */
|
||||||
|
std::vector<struct FontLineMeasure> lines;
|
||||||
|
|
||||||
|
/** Dimensions of the string */
|
||||||
|
float_t width, height;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Internal method that adds a line to the text buffer process.
|
||||||
|
*
|
||||||
|
* @param start Start character index for the next line.
|
||||||
|
* @param len Length of the next line.
|
||||||
|
*/
|
||||||
|
void addLine(int32_t start, int32_t length);
|
||||||
|
|
||||||
|
float_t getWidth();
|
||||||
|
float_t getHeight();
|
||||||
|
int32_t getQuadsOnLine(int32_t line);
|
||||||
|
int32_t getQuadIndexOnLine(int32_t line);
|
||||||
|
size_t getLineCount();
|
||||||
|
int32_t getQuadCount();
|
||||||
|
};
|
||||||
|
}
|
@ -5,6 +5,11 @@
|
|||||||
|
|
||||||
#include "TrueTypeFont.hpp"
|
#include "TrueTypeFont.hpp"
|
||||||
|
|
||||||
|
#ifndef STB_TRUETYPE_IMPLEMENTATION
|
||||||
|
#define STB_TRUETYPE_IMPLEMENTATION
|
||||||
|
#include <stb_truetype.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
using namespace Dawn;
|
using namespace Dawn;
|
||||||
|
|
||||||
void TrueTypeFont::bakeQuad(truetypequad_t *quad,float_t *x,float_t *y,char c){
|
void TrueTypeFont::bakeQuad(truetypequad_t *quad,float_t *x,float_t *y,char c){
|
||||||
@ -17,10 +22,12 @@ void TrueTypeFont::bakeQuad(truetypequad_t *quad,float_t *x,float_t *y,char c){
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
float_t TrueTypeFont::getScale(float_t scale) {
|
float_t TrueTypeFont::getScale(float_t scale) {
|
||||||
return scale / this->fontSize;
|
return scale / this->fontSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
float_t TrueTypeFont::getSpaceSize(float_t fontSize) {
|
float_t TrueTypeFont::getSpaceSize(float_t fontSize) {
|
||||||
return mathRoundFloat(this->fontSize * 0.3f);
|
return mathRoundFloat(this->fontSize * 0.3f);
|
||||||
}
|
}
|
||||||
@ -34,21 +41,14 @@ void TrueTypeFont::buffer(
|
|||||||
float_t fontSize,
|
float_t fontSize,
|
||||||
float_t maxWidth,
|
float_t maxWidth,
|
||||||
Mesh &mesh,
|
Mesh &mesh,
|
||||||
FontMeasure &measure
|
struct FontMeasure *info
|
||||||
) {
|
) {
|
||||||
// truetypequad_t *quads;
|
|
||||||
// int32_t stringLength, wordStart, i, j;
|
|
||||||
// float_t x, y, wordX;
|
|
||||||
// float_t scale;
|
|
||||||
// char c;
|
|
||||||
// truetypequad_t *quad;
|
|
||||||
|
|
||||||
auto stringLength = text.length();
|
auto stringLength = text.length();
|
||||||
|
|
||||||
if(stringLength == 0) {
|
if(stringLength == 0) {
|
||||||
info->length = 0;
|
info->length = 0;
|
||||||
info->realLength = 0;
|
info->realLength = 0;
|
||||||
info->lineCount = 0;
|
info->lines.clear();
|
||||||
info->lines[0].start = 0;
|
info->lines[0].start = 0;
|
||||||
info->lines[0].length = 0;
|
info->lines[0].length = 0;
|
||||||
info->height = 0;
|
info->height = 0;
|
||||||
@ -71,11 +71,10 @@ void TrueTypeFont::buffer(
|
|||||||
// Setup Scales
|
// Setup Scales
|
||||||
info->length = 0;
|
info->length = 0;
|
||||||
info->realLength = 0;
|
info->realLength = 0;
|
||||||
info->lineCount = 0;
|
info->lines.clear();
|
||||||
|
|
||||||
// Prepare the line counters
|
// Prepare the line counters
|
||||||
info->lines[0].start = 0;
|
info->addLine(0, 0);
|
||||||
info->lines[0].length = 0;
|
|
||||||
|
|
||||||
// Reset Dimensions
|
// Reset Dimensions
|
||||||
info->width = info->height = 0;
|
info->width = info->height = 0;
|
||||||
@ -95,7 +94,7 @@ void TrueTypeFont::buffer(
|
|||||||
|
|
||||||
// Did this space cause a newline?
|
// Did this space cause a newline?
|
||||||
if(x > maxWidth) {
|
if(x > maxWidth) {
|
||||||
trueTypeTextBufferAddLine(info, info->realLength, 0);
|
info->addLine(info->realLength, 0);
|
||||||
y += this->getLineHeight(fontSize);
|
y += this->getLineHeight(fontSize);
|
||||||
x = 0;
|
x = 0;
|
||||||
}
|
}
|
||||||
@ -106,7 +105,7 @@ void TrueTypeFont::buffer(
|
|||||||
|
|
||||||
// New line.
|
// New line.
|
||||||
if(c == FONT_NEWLINE) {
|
if(c == FONT_NEWLINE) {
|
||||||
trueTypeTextBufferAddLine(info, info->realLength, 0);
|
info->addLine(info->realLength, 0);
|
||||||
wordStart = info->realLength;
|
wordStart = info->realLength;
|
||||||
y += this->getLineHeight(fontSize);
|
y += this->getLineHeight(fontSize);
|
||||||
x = 0;
|
x = 0;
|
||||||
@ -130,19 +129,17 @@ void TrueTypeFont::buffer(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Go back to the previous (still current) line and remove the chars
|
// Go back to the previous (still current) line and remove the chars
|
||||||
info->lines[info->lineCount].length -= info->realLength - wordStart;
|
info->lines[info->lines.size() - 1].length -= info->realLength - wordStart;
|
||||||
|
|
||||||
// Next line begins with this word
|
// Next line begins with this word
|
||||||
y += this->getLineHeight(fontSize);
|
y += this->getLineHeight(fontSize);
|
||||||
trueTypeTextBufferAddLine(info, wordStart, info->realLength-wordStart);
|
info->addLine(wordStart, info->realLength-wordStart);
|
||||||
wordX = 0;
|
wordX = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
info->lines[info->lineCount].length++;
|
info->lines[info->lines.size() - 1].length++;
|
||||||
info->realLength++;
|
info->realLength++;
|
||||||
}
|
}
|
||||||
|
|
||||||
info->lineCount++;
|
|
||||||
|
|
||||||
// Initialize primitive
|
// Initialize primitive
|
||||||
mesh.createBuffers(
|
mesh.createBuffers(
|
||||||
@ -192,5 +189,6 @@ float_t TrueTypeFont::getLineHeight(float_t fontSize) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
float_t TrueTypeFont::getDefaultFontSize() {
|
float_t TrueTypeFont::getDefaultFontSize() {
|
||||||
return this->fontSize;
|
return (float_t)this->fontSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,11 +6,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "Font.hpp"
|
#include "Font.hpp"
|
||||||
|
|
||||||
#ifndef STB_TRUETYPE_IMPLEMENTATION
|
|
||||||
#define STB_TRUETYPE_IMPLEMENTATION
|
|
||||||
#include <stb_truetype.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace Dawn {
|
namespace Dawn {
|
||||||
/** Which character (ASCII) to start the font from */
|
/** Which character (ASCII) to start the font from */
|
||||||
#define TRUETYPE_FIRST_CHAR 32
|
#define TRUETYPE_FIRST_CHAR 32
|
||||||
@ -24,33 +19,6 @@ namespace Dawn {
|
|||||||
typedef stbtt_bakedchar truetypechar_t;
|
typedef stbtt_bakedchar truetypechar_t;
|
||||||
typedef stbtt_aligned_quad truetypequad_t;
|
typedef stbtt_aligned_quad truetypequad_t;
|
||||||
|
|
||||||
class TrueTypeFontMeasure : public FontMeasure {
|
|
||||||
public:
|
|
||||||
// typedef struct {
|
|
||||||
// /** What (real character) index the line starts at */
|
|
||||||
// int32_t start;
|
|
||||||
// /** How many (real) characters the line is in length */
|
|
||||||
// int32_t length;
|
|
||||||
// } truetypefontinfoline_t;
|
|
||||||
|
|
||||||
// typedef struct {
|
|
||||||
// /** How many raw chars are in the string */
|
|
||||||
// int32_t length;
|
|
||||||
|
|
||||||
// /** How many real characters (non whitespace) are in the string */
|
|
||||||
// int32_t realLength;
|
|
||||||
|
|
||||||
// /** How many lines is the string? Trailing newlines will count */
|
|
||||||
// int32_t lineCount;
|
|
||||||
|
|
||||||
// /** The real character info for each line */
|
|
||||||
// truetypefontinfoline_t lines[256];
|
|
||||||
|
|
||||||
// /** Dimensions of the string */
|
|
||||||
// float_t width, height;
|
|
||||||
// } truetypefontinfo_t;
|
|
||||||
};
|
|
||||||
|
|
||||||
class TrueTypeFont : public Font {
|
class TrueTypeFont : public Font {
|
||||||
protected:
|
protected:
|
||||||
/**
|
/**
|
||||||
@ -96,17 +64,15 @@ namespace Dawn {
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
Texture texture;
|
Texture texture;
|
||||||
float_t fontSize;
|
int32_t fontSize;
|
||||||
truetypechar_t characterData[TRUETYPE_NUM_CHARS];
|
truetypechar_t characterData[TRUETYPE_NUM_CHARS];
|
||||||
|
|
||||||
void init() override;
|
|
||||||
|
|
||||||
void buffer(
|
void buffer(
|
||||||
std::string text,
|
std::string text,
|
||||||
float_t fontSize,
|
float_t fontSize,
|
||||||
float_t maxWidth,
|
float_t maxWidth,
|
||||||
Mesh &mesh,
|
Mesh &mesh,
|
||||||
FontMeasure &measure
|
struct FontMeasure *info
|
||||||
) override;
|
) override;
|
||||||
|
|
||||||
Texture & getTexture() override;
|
Texture & getTexture() override;
|
||||||
|
@ -4,9 +4,13 @@
|
|||||||
// https://opensource.org/licenses/MIT
|
// https://opensource.org/licenses/MIT
|
||||||
|
|
||||||
#include "DawnPokerGame.hpp"
|
#include "DawnPokerGame.hpp"
|
||||||
|
#include "asset/assets/TextureAsset.hpp"
|
||||||
|
|
||||||
using namespace Dawn;
|
using namespace Dawn;
|
||||||
|
|
||||||
|
std::shared_ptr<TrueTypeAsset> asset;
|
||||||
|
std::shared_ptr<TextureAsset> assetTexture;
|
||||||
|
|
||||||
DawnGame::DawnGame(DawnHost &host) :
|
DawnGame::DawnGame(DawnHost &host) :
|
||||||
host(host),
|
host(host),
|
||||||
renderManager(*this)
|
renderManager(*this)
|
||||||
@ -23,14 +27,32 @@ int32_t DawnGame::init() {
|
|||||||
auto camera = cameraObject->addComponent<Camera>();
|
auto camera = cameraObject->addComponent<Camera>();
|
||||||
camera->transform.lookAt(glm::vec3(5, 5, 5), glm::vec3(0, 0, 0));
|
camera->transform.lookAt(glm::vec3(5, 5, 5), glm::vec3(0, 0, 0));
|
||||||
|
|
||||||
auto canvas = UICanvas::createCanvas(this->scene);
|
// auto canvas = UICanvas::createCanvas(this->scene);
|
||||||
auto test = canvas->addElement<UISprite>();
|
// auto test = canvas->addElement<UISprite>();
|
||||||
test->setTransform(
|
// test->setTransform(
|
||||||
UI_COMPONENT_ALIGN_START,
|
// UI_COMPONENT_ALIGN_START,
|
||||||
UI_COMPONENT_ALIGN_START,
|
// UI_COMPONENT_ALIGN_START,
|
||||||
glm::vec4(0, 0, 32, 32),
|
// glm::vec4(0, 0, 32, 32),
|
||||||
0
|
// 0
|
||||||
);
|
// );
|
||||||
|
|
||||||
|
asset = this->assetManager.load<TrueTypeAsset>("truetype_ark");
|
||||||
|
assetTexture = this->assetManager.load<TextureAsset>("texture_test");
|
||||||
|
while(!asset->loaded || !assetTexture->loaded) {
|
||||||
|
this->assetManager.update();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
auto text = this->scene->createSceneItem();
|
||||||
|
auto meshRenderer = text->addComponent<MeshRenderer>();
|
||||||
|
auto material = text->addComponent<Material>();
|
||||||
|
meshRenderer->mesh = std::make_shared<Mesh>();
|
||||||
|
// meshRenderer->mesh->createBuffers(QUAD_VERTICE_COUNT, QUAD_INDICE_COUNT);
|
||||||
|
// QuadMesh::bufferQuadMesh(*meshRenderer->mesh, glm::vec2(0, 0), glm::vec2(0, 0), glm::vec2(1, 1), glm::vec2(1, 1), 0, 0);
|
||||||
|
|
||||||
|
struct FontMeasure measure;
|
||||||
|
asset->font.buffer("Test", 16.0f, -1, *meshRenderer->mesh, &measure);
|
||||||
|
material->textureValues[material->getShader()->getParameterByName("u_Text")] = std::shared_ptr<Texture>(&asset->font.getTexture());
|
||||||
|
|
||||||
return DAWN_GAME_INIT_RESULT_SUCCESS;
|
return DAWN_GAME_INIT_RESULT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
@ -6,4 +6,5 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "game/DawnGame.hpp"
|
#include "game/DawnGame.hpp"
|
||||||
#include "scene/components/Components.hpp"
|
#include "scene/components/Components.hpp"
|
||||||
#include "ui/UISprite.hpp"
|
#include "ui/UISprite.hpp"
|
||||||
|
#include "asset/assets/TrueTypeAsset.hpp"
|
@ -18,7 +18,7 @@ endfunction()
|
|||||||
# TrueType Tool
|
# TrueType Tool
|
||||||
function(tool_truetype target in out width height fontSize)
|
function(tool_truetype target in out width height fontSize)
|
||||||
add_custom_target(${target}
|
add_custom_target(${target}
|
||||||
COMMAND truetypegen "${in}" "${DAWN_ASSETS_BUILD_DIR}/${out}" "${width}" "${height}" "${fontSize}"
|
COMMAND truetypegen "${DAWN_ASSETS_SOURCE_DIR}/${in}" "${DAWN_ASSETS_BUILD_DIR}/${out}" "${width}" "${height}" "${fontSize}"
|
||||||
COMMENT "Generating truetype ${target} from ${in}"
|
COMMENT "Generating truetype ${target} from ${in}"
|
||||||
DEPENDS truetypegen
|
DEPENDS truetypegen
|
||||||
)
|
)
|
||||||
|
Reference in New Issue
Block a user