About 3/4 done with new font system
This commit is contained in:
@ -12,6 +12,7 @@
|
|||||||
#include "assets/TextureAsset.hpp"
|
#include "assets/TextureAsset.hpp"
|
||||||
#include "assets/TilesetAsset.hpp"
|
#include "assets/TilesetAsset.hpp"
|
||||||
#include "assets/TrueTypeAsset.hpp"
|
#include "assets/TrueTypeAsset.hpp"
|
||||||
|
#include "assets/NewTrueTypeAsset.hpp"
|
||||||
|
|
||||||
namespace Dawn {
|
namespace Dawn {
|
||||||
class AssetManager {
|
class AssetManager {
|
||||||
|
@ -11,4 +11,5 @@ target_sources(${DAWN_TARGET_NAME}
|
|||||||
TextureAsset.cpp
|
TextureAsset.cpp
|
||||||
TilesetAsset.cpp
|
TilesetAsset.cpp
|
||||||
TrueTypeAsset.cpp
|
TrueTypeAsset.cpp
|
||||||
|
NewTrueTypeAsset.cpp
|
||||||
)
|
)
|
@ -4,6 +4,7 @@
|
|||||||
// https://opensource.org/licenses/MIT
|
// https://opensource.org/licenses/MIT
|
||||||
|
|
||||||
#include "NewTrueTypeAsset.hpp"
|
#include "NewTrueTypeAsset.hpp"
|
||||||
|
#include "asset/AssetManager.hpp"
|
||||||
|
|
||||||
using namespace Dawn;
|
using namespace Dawn;
|
||||||
|
|
||||||
@ -21,20 +22,19 @@ void NewTrueTypeAsset::updateSync() {
|
|||||||
void NewTrueTypeAsset::updateAsync() {
|
void NewTrueTypeAsset::updateAsync() {
|
||||||
if(this->state != NEW_TRUE_TYPE_ASSET_STATE_INITIAL) return;
|
if(this->state != NEW_TRUE_TYPE_ASSET_STATE_INITIAL) return;
|
||||||
|
|
||||||
|
|
||||||
this->state = NEW_TRUE_TYPE_ASSET_STATE_OPEN;
|
this->state = NEW_TRUE_TYPE_ASSET_STATE_OPEN;
|
||||||
this->loader.open();
|
this->loader.open();
|
||||||
|
|
||||||
this->state = NEW_TRUE_TYPE_ASSET_STATE_VALIDATE_HEADER;
|
this->state = NEW_TRUE_TYPE_ASSET_STATE_VALIDATE_HEADER;
|
||||||
|
|
||||||
char buffer[1024];
|
uint8_t buffer[64];
|
||||||
this->loader.rewind();
|
this->loader.rewind();
|
||||||
size_t read = this->loader.read(buffer, sizeof(char) * 6);
|
size_t read = this->loader.read(buffer, sizeof(char) * 6);
|
||||||
assertTrue(read == (6 * sizeof(char)));
|
assertTrue(read == (6 * sizeof(char)));
|
||||||
buffer[6] = '\0';
|
buffer[6] = '\0';
|
||||||
|
|
||||||
// Confirm "DE_TTF"
|
// Confirm "DE_TTF"
|
||||||
assertTrue(std::string(buffer) == "DE_TTF");
|
assertTrue(std::string((char *)buffer) == "DE_TTF");
|
||||||
|
|
||||||
// Vertical bar
|
// Vertical bar
|
||||||
this->loader.read(buffer, 1);
|
this->loader.read(buffer, 1);
|
||||||
@ -50,6 +50,7 @@ void NewTrueTypeAsset::updateAsync() {
|
|||||||
assertTrue(buffer[4] == '|');
|
assertTrue(buffer[4] == '|');
|
||||||
|
|
||||||
// Read the count of font styles / variants.
|
// Read the count of font styles / variants.
|
||||||
|
size_t styleListBegin = this->loader.getPosition();
|
||||||
this->state = NEW_TRUE_TYPE_ASSET_STATE_READ_VARIANT_COUNT;
|
this->state = NEW_TRUE_TYPE_ASSET_STATE_READ_VARIANT_COUNT;
|
||||||
read = this->loader.read(buffer, 64);
|
read = this->loader.read(buffer, 64);
|
||||||
assertTrue(read > 0);
|
assertTrue(read > 0);
|
||||||
@ -58,16 +59,121 @@ void NewTrueTypeAsset::updateAsync() {
|
|||||||
size_t i = 0;
|
size_t i = 0;
|
||||||
while(buffer[i] != '|' && i < 64) i++;
|
while(buffer[i] != '|' && i < 64) i++;
|
||||||
assertTrue(buffer[i] == '|');
|
assertTrue(buffer[i] == '|');
|
||||||
|
styleListBegin += i + 1;
|
||||||
buffer[i] = '\0';
|
buffer[i] = '\0';
|
||||||
|
|
||||||
int32_t count = atoi(buffer);
|
int32_t count = atoi((char *)buffer);
|
||||||
assertTrue(count > 0);
|
assertTrue(count > 0);
|
||||||
|
|
||||||
// Now begin parsing each font style
|
// Now begin parsing each font style.
|
||||||
while(true) {
|
this->state = NEW_TRUE_TYPE_ASSET_STATE_READ_VARIANT;
|
||||||
|
assetStyles.clear();
|
||||||
|
while(assetStyles.size() != count) {
|
||||||
|
struct NewTrueTypeAssetStyle style;
|
||||||
|
|
||||||
|
// Buffer
|
||||||
|
this->loader.rewind();
|
||||||
|
this->loader.setPosition(styleListBegin);
|
||||||
|
read = this->loader.read(buffer, 32);
|
||||||
|
assertTrue(read == 32);
|
||||||
|
|
||||||
|
// Read style
|
||||||
|
i = 0;
|
||||||
|
while(buffer[i] != ':' && i < 64) i++;
|
||||||
|
buffer[i] = '\0';
|
||||||
|
style.style = atoi((char *)buffer);
|
||||||
|
styleListBegin += i + 1;
|
||||||
|
|
||||||
|
// Buffer
|
||||||
|
this->loader.rewind();
|
||||||
|
this->loader.setPosition(styleListBegin);
|
||||||
|
read = this->loader.read(buffer, 32);
|
||||||
|
assertTrue(read == 32);
|
||||||
|
|
||||||
|
// Read length
|
||||||
|
i = 0;
|
||||||
|
while(buffer[i] != '|' && i < 64) i++;
|
||||||
|
buffer[i] = '\0';
|
||||||
|
styleListBegin += i + 1;
|
||||||
|
style.dataSize = atol((char *)buffer);
|
||||||
|
|
||||||
|
// Push
|
||||||
|
assetStyles.push_back(style);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Now we are at the first byte of the first style.
|
||||||
|
this->state = NEW_TRUE_TYPE_ASSET_STATE_ADJUSTING_OFFSETS;
|
||||||
|
auto itStyle = assetStyles.begin();
|
||||||
|
while(itStyle != assetStyles.end()) {
|
||||||
|
(*itStyle).dataOffset = styleListBegin;
|
||||||
|
styleListBegin += (*itStyle).dataSize;
|
||||||
|
styleListBegin += 1; // Vertical bar
|
||||||
|
++itStyle;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Init FreeType
|
||||||
|
this->state = NEW_TRUE_TYPE_ASSET_STATE_INIT_FREETYPE;
|
||||||
|
int32_t ret = FT_Init_FreeType(&fontLibrary);
|
||||||
|
assertTrue(ret == 0);
|
||||||
|
|
||||||
|
// Convert to truetype faces
|
||||||
|
this->state = NEW_TRUE_TYPE_ASSET_STATE_CONVERTING_TO_FACES;
|
||||||
|
itStyle = assetStyles.begin();
|
||||||
|
while(itStyle != assetStyles.end()) {
|
||||||
|
struct NewTrueTypeAssetStyle &style = (*itStyle);
|
||||||
|
|
||||||
|
uint8_t *dataBuffer = (uint8_t*)memoryAllocate(sizeof(uint8_t) * style.dataSize);
|
||||||
|
this->loader.rewind();
|
||||||
|
this->loader.setPosition(style.dataOffset);
|
||||||
|
read = this->loader.read(dataBuffer, style.dataSize);
|
||||||
|
assertTrue(read == style.dataSize);
|
||||||
|
|
||||||
|
// Create the face
|
||||||
|
NewTrueTypeFace *face = new NewTrueTypeFace();
|
||||||
|
ret = FT_New_Memory_Face(this->fontLibrary, (FT_Byte*)dataBuffer, style.dataSize, 0, &face->face);
|
||||||
|
memoryFree(dataBuffer);
|
||||||
|
assertTrue(ret == 0);
|
||||||
|
|
||||||
|
// Push
|
||||||
|
this->faces[style.style] = face;
|
||||||
|
++itStyle;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Done parsing!
|
||||||
|
this->state = NEW_TRUE_TYPE_ASSET_STATE_READY;
|
||||||
|
this->loaded = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
usagelockid_t NewTrueTypeAsset::lock(struct NewTrueTypeFaceTextureStyle style) {
|
||||||
|
// Try find style
|
||||||
|
auto it = this->faces.find(style.style);
|
||||||
|
assertTrue(it != this->faces.end());
|
||||||
|
|
||||||
|
auto lock = it->second->lock(style);
|
||||||
|
this->locks[lock] = style;
|
||||||
|
return lock;
|
||||||
|
}
|
||||||
|
|
||||||
|
NewTrueTypeFaceTexture * NewTrueTypeAsset::getTexture(usagelockid_t id) {
|
||||||
|
auto existing = this->locks.find(id);
|
||||||
|
assertTrue(existing != this->locks.end());
|
||||||
|
return this->faces[existing->second.style]->getTexture(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
void NewTrueTypeAsset::unlock(usagelockid_t id) {
|
||||||
|
auto existing = this->locks.find(id);
|
||||||
|
assertTrue(existing != this->locks.end());
|
||||||
|
this->faces[existing->second.style]->unlock(id);
|
||||||
|
this->locks.erase(existing);
|
||||||
}
|
}
|
||||||
|
|
||||||
NewTrueTypeAsset::~NewTrueTypeAsset() {
|
NewTrueTypeAsset::~NewTrueTypeAsset() {
|
||||||
|
auto it = this->faces.begin();
|
||||||
|
while(it != this->faces.end()) {
|
||||||
|
FT_Done_Face(it->second->face);
|
||||||
|
delete it->second;
|
||||||
|
it++;
|
||||||
|
}
|
||||||
|
|
||||||
|
FT_Done_FreeType(this->fontLibrary);
|
||||||
}
|
}
|
@ -6,26 +6,55 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "../Asset.hpp"
|
#include "../Asset.hpp"
|
||||||
#include "../AssetLoader.hpp"
|
#include "../AssetLoader.hpp"
|
||||||
|
#include "util/flag.hpp"
|
||||||
|
#include "display/font/truetype/NewTrueTypeFace.hpp"
|
||||||
|
|
||||||
namespace Dawn {
|
namespace Dawn {
|
||||||
enum NewTrueTypeAssetState {
|
enum NewTrueTypeAssetState {
|
||||||
NEW_TRUE_TYPE_ASSET_STATE_INITIAL,
|
NEW_TRUE_TYPE_ASSET_STATE_INITIAL,
|
||||||
NEW_TRUE_TYPE_ASSET_STATE_OPEN,
|
NEW_TRUE_TYPE_ASSET_STATE_OPEN,
|
||||||
// NEW_TRUE_TYPE_ASSET_STATE_LOAD_RAW,
|
|
||||||
NEW_TRUE_TYPE_ASSET_STATE_VALIDATE_HEADER,
|
NEW_TRUE_TYPE_ASSET_STATE_VALIDATE_HEADER,
|
||||||
NEW_TRUE_TYPE_ASSET_STATE_VALIDATE_VERSION,
|
NEW_TRUE_TYPE_ASSET_STATE_VALIDATE_VERSION,
|
||||||
NEW_TRUE_TYPE_ASSET_STATE_READ_VARIANT_COUNT,
|
NEW_TRUE_TYPE_ASSET_STATE_READ_VARIANT_COUNT,
|
||||||
}
|
NEW_TRUE_TYPE_ASSET_STATE_READ_VARIANT,
|
||||||
|
NEW_TRUE_TYPE_ASSET_STATE_ADJUSTING_OFFSETS,
|
||||||
|
NEW_TRUE_TYPE_ASSET_STATE_INIT_FREETYPE,
|
||||||
|
NEW_TRUE_TYPE_ASSET_STATE_CONVERTING_TO_FACES,
|
||||||
|
NEW_TRUE_TYPE_ASSET_STATE_READY
|
||||||
|
};
|
||||||
|
|
||||||
|
struct NewTrueTypeAssetStyle {
|
||||||
|
flag_t style;
|
||||||
|
size_t dataSize;
|
||||||
|
size_t dataOffset;
|
||||||
|
};
|
||||||
|
|
||||||
class NewTrueTypeAsset : public Asset {
|
class NewTrueTypeAsset : public Asset {
|
||||||
protected:
|
protected:
|
||||||
AssetLoader loader;
|
AssetLoader loader;
|
||||||
|
FT_Library fontLibrary;
|
||||||
enum NewTrueTypeAssetState state = NEW_TRUE_TYPE_ASSET_STATE_INITIAL;
|
enum NewTrueTypeAssetState state = NEW_TRUE_TYPE_ASSET_STATE_INITIAL;
|
||||||
|
std::vector<struct NewTrueTypeAssetStyle> assetStyles;
|
||||||
|
std::map<flag_t, NewTrueTypeFace*> faces;
|
||||||
|
std::map<usagelockid_t, struct NewTrueTypeFaceTextureStyle> locks;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
NewTrueTypeAsset(AssetManager *assMan, std::string name);
|
NewTrueTypeAsset(AssetManager *assMan, std::string name);
|
||||||
void updateSync() override;
|
void updateSync() override;
|
||||||
void updateAsync() override;
|
void updateAsync() override;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Locks a specific style for use later.
|
||||||
|
*
|
||||||
|
* @param style Style you want to lock.
|
||||||
|
* @return A unique lock ID for this style.
|
||||||
|
*/
|
||||||
|
usagelockid_t lock(struct NewTrueTypeFaceTextureStyle style);
|
||||||
|
|
||||||
|
NewTrueTypeFaceTexture * getTexture(usagelockid_t lock);
|
||||||
|
|
||||||
|
void unlock(usagelockid_t lock);
|
||||||
|
|
||||||
~NewTrueTypeAsset();
|
~NewTrueTypeAsset();
|
||||||
};
|
};
|
||||||
}
|
}
|
@ -15,7 +15,6 @@ namespace Dawn {
|
|||||||
class DawnGame;
|
class DawnGame;
|
||||||
class RenderPipeline;
|
class RenderPipeline;
|
||||||
class ShaderManager;
|
class ShaderManager;
|
||||||
class FontManager;
|
|
||||||
|
|
||||||
class IRenderManager {
|
class IRenderManager {
|
||||||
protected:
|
protected:
|
||||||
@ -56,13 +55,6 @@ namespace Dawn {
|
|||||||
* @return Reference to the shader manager.
|
* @return Reference to the shader manager.
|
||||||
*/
|
*/
|
||||||
virtual ShaderManager * getShaderManager() = 0;
|
virtual ShaderManager * getShaderManager() = 0;
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the font manager that this render manager uses.
|
|
||||||
*
|
|
||||||
* @return Reference ot the font manager.
|
|
||||||
*/
|
|
||||||
virtual FontManager * getFontManager() = 0;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the render flags for the render manager to use.
|
* Sets the render flags for the render manager to use.
|
||||||
|
@ -6,7 +6,6 @@
|
|||||||
# Sources
|
# Sources
|
||||||
target_sources(${DAWN_TARGET_NAME}
|
target_sources(${DAWN_TARGET_NAME}
|
||||||
PRIVATE
|
PRIVATE
|
||||||
FontManager.cpp
|
|
||||||
BitmapFont.cpp
|
BitmapFont.cpp
|
||||||
ExampleFont.cpp
|
ExampleFont.cpp
|
||||||
TrueTypeFont.cpp
|
TrueTypeFont.cpp
|
||||||
|
@ -1,24 +0,0 @@
|
|||||||
// Copyright (c) 2023 Dominic Masters
|
|
||||||
//
|
|
||||||
// This software is released under the MIT License.
|
|
||||||
// https://opensource.org/licenses/MIT
|
|
||||||
|
|
||||||
#include "FontManager.hpp"
|
|
||||||
|
|
||||||
using namespace Dawn;
|
|
||||||
|
|
||||||
FontManager::FontManager() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void FontManager::init() {
|
|
||||||
// Init FreeType
|
|
||||||
if(FT_Init_FreeType(&fontLibrary)) {
|
|
||||||
std::cout << "ERROR::FREETYPE: Could not init FreeType Library" << std::endl;
|
|
||||||
assertUnreachable();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
FontManager::~FontManager() {
|
|
||||||
|
|
||||||
}
|
|
@ -1,23 +0,0 @@
|
|||||||
// Copyright (c) 2023 Dominic Masters
|
|
||||||
//
|
|
||||||
// This software is released under the MIT License.
|
|
||||||
// https://opensource.org/licenses/MIT
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
#include "dawnlibs.hpp"
|
|
||||||
#include "assert/assert.hpp"
|
|
||||||
|
|
||||||
namespace Dawn {
|
|
||||||
class FontManager {
|
|
||||||
protected:
|
|
||||||
|
|
||||||
public:
|
|
||||||
FT_Library fontLibrary;
|
|
||||||
|
|
||||||
FontManager();
|
|
||||||
|
|
||||||
void init();
|
|
||||||
|
|
||||||
~FontManager();
|
|
||||||
};
|
|
||||||
}
|
|
@ -6,7 +6,6 @@
|
|||||||
# Sources
|
# Sources
|
||||||
target_sources(${DAWN_TARGET_NAME}
|
target_sources(${DAWN_TARGET_NAME}
|
||||||
PRIVATE
|
PRIVATE
|
||||||
NewTrueType.cpp
|
|
||||||
NewTrueTypeFace.cpp
|
NewTrueTypeFace.cpp
|
||||||
NewTrueTypeFaceTexture.hpp
|
NewTrueTypeFaceTexture.cpp
|
||||||
)
|
)
|
@ -1,28 +0,0 @@
|
|||||||
// Copyright (c) 2023 Dominic Masters
|
|
||||||
//
|
|
||||||
// This software is released under the MIT License.
|
|
||||||
// https://opensource.org/licenses/MIT
|
|
||||||
|
|
||||||
#include "NewTrueType.hpp"
|
|
||||||
|
|
||||||
using namespace Dawn;
|
|
||||||
|
|
||||||
NewTrueType::NewTrueType(FontManager *fontMan) {
|
|
||||||
assertNotNull(fontMan);
|
|
||||||
this->fontManager = fontMan;
|
|
||||||
}
|
|
||||||
|
|
||||||
void NewTrueType::addStyle(flag_t style) {
|
|
||||||
assertTrue(this->faces.find(style) == this->faces.end());
|
|
||||||
|
|
||||||
//Create the face
|
|
||||||
this->faces[style] = new NewTrueTypeFace();
|
|
||||||
}
|
|
||||||
|
|
||||||
NewTrueType::~NewTrueType() {
|
|
||||||
auto it = this->faces.begin();
|
|
||||||
while(it != this->faces.end()) {
|
|
||||||
delete it->second;
|
|
||||||
it++;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,24 +0,0 @@
|
|||||||
// Copyright (c) 2023 Dominic Masters
|
|
||||||
//
|
|
||||||
// This software is released under the MIT License.
|
|
||||||
// https://opensource.org/licenses/MIT
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
#include "NewTrueTypeFace.hpp"
|
|
||||||
#include "display/font/FontManager.hpp"
|
|
||||||
|
|
||||||
namespace Dawn {
|
|
||||||
class NewTrueType {
|
|
||||||
protected:
|
|
||||||
std::map<flag_t, NewTrueTypeFace*> faces;
|
|
||||||
FontManager *fontManager;
|
|
||||||
|
|
||||||
public:
|
|
||||||
NewTrueType(FontManager *fontMan);
|
|
||||||
void addStyle(flag_t style);
|
|
||||||
NewTrueTypeFace * getFace(flag_t style);
|
|
||||||
~NewTrueType();
|
|
||||||
|
|
||||||
friend class NewTrueTypeFace;
|
|
||||||
};
|
|
||||||
}
|
|
@ -3,7 +3,7 @@
|
|||||||
// This software is released under the MIT License.
|
// This software is released under the MIT License.
|
||||||
// https://opensource.org/licenses/MIT
|
// https://opensource.org/licenses/MIT
|
||||||
|
|
||||||
#include "NewTrueType.hpp"
|
#include "asset/assets/NewTrueTypeAsset.hpp"
|
||||||
|
|
||||||
using namespace Dawn;
|
using namespace Dawn;
|
||||||
|
|
||||||
@ -15,17 +15,10 @@ usagelockid_t NewTrueTypeFace::lock(struct NewTrueTypeFaceTextureStyle style) {
|
|||||||
NewTrueTypeFaceTexture *texture = nullptr;
|
NewTrueTypeFaceTexture *texture = nullptr;
|
||||||
auto existing = this->texturesByStyle.find(style);
|
auto existing = this->texturesByStyle.find(style);
|
||||||
if(existing == this->texturesByStyle.end()) {
|
if(existing == this->texturesByStyle.end()) {
|
||||||
// Load face
|
|
||||||
FT_Face face;
|
|
||||||
assertUnreachable();
|
|
||||||
|
|
||||||
// Does not exist, create it.
|
// Does not exist, create it.
|
||||||
texture = new NewTrueTypeFaceTexture(this, face, style);
|
texture = new NewTrueTypeFaceTexture(this, face, style);
|
||||||
this->textures.push_back(texture);
|
this->textures.push_back(texture);
|
||||||
this->texturesByStyle[style] = texture;
|
this->texturesByStyle[style] = texture;
|
||||||
|
|
||||||
// Cleanup face
|
|
||||||
FT_Done_Face(face);
|
|
||||||
} else {
|
} else {
|
||||||
texture = existing->second;
|
texture = existing->second;
|
||||||
}
|
}
|
||||||
@ -48,6 +41,7 @@ NewTrueTypeFaceTexture * NewTrueTypeFace::getTexture(usagelockid_t lock) {
|
|||||||
|
|
||||||
void NewTrueTypeFace::unlock(usagelockid_t lock) {
|
void NewTrueTypeFace::unlock(usagelockid_t lock) {
|
||||||
auto texture = this->getTexture(lock);
|
auto texture = this->getTexture(lock);
|
||||||
|
assertNotNull(texture);
|
||||||
texture->locks.removeLock(lock);
|
texture->locks.removeLock(lock);
|
||||||
this->stylesByLock.erase(lock);
|
this->stylesByLock.erase(lock);
|
||||||
auto it = std::find(this->locksByStyle[texture->style].begin(), this->locksByStyle[texture->style].end(), lock);
|
auto it = std::find(this->locksByStyle[texture->style].begin(), this->locksByStyle[texture->style].end(), lock);
|
||||||
@ -59,6 +53,5 @@ NewTrueTypeFace::~NewTrueTypeFace() {
|
|||||||
auto it = this->textures.begin();
|
auto it = this->textures.begin();
|
||||||
while(it != this->textures.end()) {
|
while(it != this->textures.end()) {
|
||||||
delete *it;
|
delete *it;
|
||||||
it = this->textures.erase(it);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -8,13 +8,13 @@
|
|||||||
|
|
||||||
namespace Dawn {
|
namespace Dawn {
|
||||||
class NewTrueTypeFace {
|
class NewTrueTypeFace {
|
||||||
protected:
|
public:
|
||||||
std::vector<NewTrueTypeFaceTexture*> textures;
|
std::vector<NewTrueTypeFaceTexture*> textures;
|
||||||
std::map<struct NewTrueTypeFaceTextureStyle, NewTrueTypeFaceTexture*> texturesByStyle;
|
std::map<struct NewTrueTypeFaceTextureStyle, NewTrueTypeFaceTexture*> texturesByStyle;
|
||||||
std::map<struct NewTrueTypeFaceTextureStyle, std::vector<usagelockid_t>> locksByStyle;
|
std::map<struct NewTrueTypeFaceTextureStyle, std::vector<usagelockid_t>> locksByStyle;
|
||||||
std::map<usagelockid_t, struct NewTrueTypeFaceTextureStyle> stylesByLock;
|
std::map<usagelockid_t, struct NewTrueTypeFaceTextureStyle> stylesByLock;
|
||||||
|
FT_Face face;
|
||||||
|
|
||||||
public:
|
|
||||||
/**
|
/**
|
||||||
* Create a new TrueTypeFace object. TrueType face holds multiple textures
|
* Create a new TrueTypeFace object. TrueType face holds multiple textures
|
||||||
* of various styles of this face. This face may be "Arial Bold" and have
|
* of various styles of this face. This face may be "Arial Bold" and have
|
||||||
@ -51,7 +51,5 @@ namespace Dawn {
|
|||||||
* Destroys this TrueTypeFace object, and all textures associated with it.
|
* Destroys this TrueTypeFace object, and all textures associated with it.
|
||||||
*/
|
*/
|
||||||
~NewTrueTypeFace();
|
~NewTrueTypeFace();
|
||||||
|
|
||||||
friend class NewTrueType;
|
|
||||||
};
|
};
|
||||||
}
|
}
|
@ -3,7 +3,7 @@
|
|||||||
// This software is released under the MIT License.
|
// This software is released under the MIT License.
|
||||||
// https://opensource.org/licenses/MIT
|
// https://opensource.org/licenses/MIT
|
||||||
|
|
||||||
#include "NewTrueTypeFaceTexture.hpp"
|
#include "NewTrueTypeFace.hpp"
|
||||||
|
|
||||||
using namespace Dawn;
|
using namespace Dawn;
|
||||||
|
|
||||||
@ -13,11 +13,15 @@ NewTrueTypeFaceTexture::NewTrueTypeFaceTexture(
|
|||||||
struct NewTrueTypeFaceTextureStyle style
|
struct NewTrueTypeFaceTextureStyle style
|
||||||
) {
|
) {
|
||||||
assertNotNull(trueTypeFace);
|
assertNotNull(trueTypeFace);
|
||||||
assertTrue(this->style.fontSize < 256);
|
assertTrue(style.fontSize < 256);
|
||||||
|
|
||||||
this->trueTypeFace = trueTypeFace;
|
this->trueTypeFace = trueTypeFace;
|
||||||
this->face = &face;
|
this->face = &face;
|
||||||
this->style = style;
|
this->style = style;
|
||||||
|
|
||||||
|
this->locks.onEmpty = [&]() {
|
||||||
|
delete this;
|
||||||
|
};
|
||||||
|
|
||||||
// Set freetype font size prior to baking.
|
// Set freetype font size prior to baking.
|
||||||
if(FT_Set_Pixel_Sizes(face, 0, this->style.fontSize)) {
|
if(FT_Set_Pixel_Sizes(face, 0, this->style.fontSize)) {
|
||||||
@ -85,4 +89,14 @@ NewTrueTypeFaceTexture::NewTrueTypeFaceTexture(
|
|||||||
|
|
||||||
struct NewTrueTypeCharacter NewTrueTypeFaceTexture::getCharacterData(FT_ULong c) {
|
struct NewTrueTypeCharacter NewTrueTypeFaceTexture::getCharacterData(FT_ULong c) {
|
||||||
return this->characterData[c];
|
return this->characterData[c];
|
||||||
|
}
|
||||||
|
|
||||||
|
NewTrueTypeFaceTexture::~NewTrueTypeFaceTexture() {
|
||||||
|
auto it = std::find(
|
||||||
|
this->trueTypeFace->textures.begin(),
|
||||||
|
this->trueTypeFace->textures.end(),
|
||||||
|
this
|
||||||
|
);
|
||||||
|
assertTrue(it != this->trueTypeFace->textures.end());
|
||||||
|
this->trueTypeFace->textures.erase(it);
|
||||||
}
|
}
|
@ -11,7 +11,6 @@
|
|||||||
|
|
||||||
namespace Dawn {
|
namespace Dawn {
|
||||||
class NewTrueTypeFace;
|
class NewTrueTypeFace;
|
||||||
class NewTrueType;
|
|
||||||
|
|
||||||
typedef uint32_t newtruetypelock_t;
|
typedef uint32_t newtruetypelock_t;
|
||||||
|
|
||||||
@ -26,17 +25,19 @@ namespace Dawn {
|
|||||||
struct NewTrueTypeFaceTextureStyle {
|
struct NewTrueTypeFaceTextureStyle {
|
||||||
uint32_t fontSize;
|
uint32_t fontSize;
|
||||||
flag_t style;
|
flag_t style;
|
||||||
|
|
||||||
|
bool operator < (const struct NewTrueTypeFaceTextureStyle& r) const {
|
||||||
|
return std::tie(fontSize, style) < std::tie(r.fontSize, r.style);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class NewTrueTypeFaceTexture {
|
class NewTrueTypeFaceTexture {
|
||||||
protected:
|
public:
|
||||||
FT_Face *face;
|
FT_Face *face;
|
||||||
NewTrueTypeFace *trueTypeFace;
|
NewTrueTypeFace *trueTypeFace;
|
||||||
std::map<FT_ULong, struct NewTrueTypeCharacter> characterData;
|
std::map<FT_ULong, struct NewTrueTypeCharacter> characterData;
|
||||||
struct NewTrueTypeFaceTextureStyle style;
|
struct NewTrueTypeFaceTextureStyle style;
|
||||||
UsageLock locks;
|
UsageLock locks;
|
||||||
|
|
||||||
public:
|
|
||||||
Texture texture;
|
Texture texture;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -66,6 +67,5 @@ namespace Dawn {
|
|||||||
~NewTrueTypeFaceTexture();
|
~NewTrueTypeFaceTexture();
|
||||||
|
|
||||||
friend class NewTrueTypeFace;
|
friend class NewTrueTypeFace;
|
||||||
friend class NewTrueType;
|
|
||||||
};
|
};
|
||||||
}
|
}
|
@ -8,87 +8,94 @@
|
|||||||
|
|
||||||
using namespace Dawn;
|
using namespace Dawn;
|
||||||
|
|
||||||
UILabelNew::UILabelNew(SceneItem *item) : UIComponentRenderable(item) {
|
UILabelNew::UILabelNew(SceneItem *item) :
|
||||||
|
UIComponentRenderable(item),
|
||||||
|
font(nullptr),
|
||||||
|
fontSize(16),
|
||||||
|
style(0)
|
||||||
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void UILabelNew::rebufferQuads() {
|
||||||
|
this->mesh.createBuffers(QUAD_VERTICE_COUNT * 128, QUAD_INDICE_COUNT * 128);
|
||||||
|
|
||||||
|
auto texture = this->font->getTexture(this->fontLock);
|
||||||
|
texture.
|
||||||
|
}
|
||||||
|
|
||||||
void UILabelNew::onStart() {
|
void UILabelNew::onStart() {
|
||||||
this->shaderBuffer.init();
|
this->shaderBuffer.init();
|
||||||
|
|
||||||
if(FT_New_Face(
|
useEffect([&]{
|
||||||
getGame()->renderManager.getFontManager()->fontLibrary,
|
if(fontLock != -1) {
|
||||||
"/usr/share/fonts/TTF/arial.ttf",
|
font.previous->unlock(fontLock);
|
||||||
// "C:\\Windows\\Fonts\\arial.ttf",
|
fontLock = -1;
|
||||||
0,
|
}
|
||||||
&face
|
|
||||||
)) {
|
|
||||||
assertUnreachable();
|
|
||||||
}
|
|
||||||
UILabelNew::bakeTexture(defFace, face, 32);
|
|
||||||
|
|
||||||
|
|
||||||
if(FT_New_Face(
|
if(font == nullptr) return;
|
||||||
getGame()->renderManager.getFontManager()->fontLibrary,
|
|
||||||
"/usr/share/fonts/TTF/arialbd.ttf",
|
|
||||||
// "C:\\Windows\\Fonts\\arialbd.ttf",
|
|
||||||
0,
|
|
||||||
&faceBold
|
|
||||||
)) {
|
|
||||||
assertUnreachable();
|
|
||||||
}
|
|
||||||
UILabelNew::bakeTexture(defFaceBold, faceBold, 32);
|
|
||||||
|
|
||||||
|
fontLock = font->lock(NewTrueTypeFaceTextureStyle{
|
||||||
|
fontSize,
|
||||||
|
style
|
||||||
|
});
|
||||||
|
}, font);
|
||||||
|
|
||||||
if(FT_New_Face(
|
useEffect([&]{
|
||||||
getGame()->renderManager.getFontManager()->fontLibrary,
|
if(font == nullptr) return;
|
||||||
"/usr/share/fonts/TTF/ariali.ttf",
|
|
||||||
// "C:\\Windows\\Fonts\\ariali.ttf",
|
|
||||||
0,
|
|
||||||
&faceItalics
|
|
||||||
)) {
|
|
||||||
assertUnreachable();
|
|
||||||
}
|
|
||||||
UILabelNew::bakeTexture(defFaceItalics, faceItalics, 32);
|
|
||||||
|
|
||||||
struct FontShaderBufferData fontData;
|
if(fontLock != -1) {
|
||||||
glm::vec2 position = glm::vec2(32, 32);
|
font->unlock(fontLock);
|
||||||
|
fontLock = -1;
|
||||||
|
}
|
||||||
|
|
||||||
mesh.createBuffers(QUAD_VERTICE_COUNT * 128, QUAD_INDICE_COUNT * 128);
|
fontLock = font->lock(NewTrueTypeFaceTextureStyle{
|
||||||
auto x = UILabelNew::bufferQuads(
|
fontSize,
|
||||||
"Hello ",
|
style
|
||||||
fontData,
|
});
|
||||||
defFace,
|
}, { &fontSize, &style });
|
||||||
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;
|
// struct FontShaderBufferData fontData;
|
||||||
fontData.textures[0] = 0;
|
// glm::vec2 position = glm::vec2(32, 32);
|
||||||
fontData.colors[1] = COLOR_RED;
|
|
||||||
fontData.textures[1] = 1;
|
// mesh.createBuffers(QUAD_VERTICE_COUNT * 128, QUAD_INDICE_COUNT * 128);
|
||||||
fontData.colors[2] = COLOR_GREEN;
|
// auto x = UILabelNew::bufferQuads(
|
||||||
fontData.textures[2] = 2;
|
// "Hello ",
|
||||||
shaderBuffer.buffer(&fontData);
|
// 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() {
|
std::vector<struct ShaderPassItem> UILabelNew::getUIRenderPasses() {
|
||||||
|
if(this->fontLock == -1) return {};
|
||||||
|
|
||||||
auto canvas = this->getCanvas();
|
auto canvas = this->getCanvas();
|
||||||
auto shader = getGame()->renderManager.fontShader;
|
auto shader = getGame()->renderManager.fontShader;
|
||||||
|
|
||||||
@ -99,12 +106,12 @@ std::vector<struct ShaderPassItem> UILabelNew::getUIRenderPasses() {
|
|||||||
item.parameterBuffers[shader->bufferUiCanvas] = &canvas->shaderBuffer;
|
item.parameterBuffers[shader->bufferUiCanvas] = &canvas->shaderBuffer;
|
||||||
item.parameterBuffers[shader->bufferFont] = &this->shaderBuffer;
|
item.parameterBuffers[shader->bufferFont] = &this->shaderBuffer;
|
||||||
item.renderFlags = RENDER_MANAGER_RENDER_FLAG_BLEND;
|
item.renderFlags = RENDER_MANAGER_RENDER_FLAG_BLEND;
|
||||||
item.textureSlots[0] = &defFace.texture;
|
// item.textureSlots[0] = &defFace.texture;
|
||||||
item.textureSlots[1] = &defFaceItalics.texture;
|
// item.textureSlots[1] = &defFaceItalics.texture;
|
||||||
item.textureSlots[2] = &defFaceBold.texture;
|
// item.textureSlots[2] = &defFaceBold.texture;
|
||||||
item.textureValues[shader->paramTexture0] = 0;
|
// item.textureValues[shader->paramTexture0] = 0;
|
||||||
item.textureValues[shader->paramTexture1] = 1;
|
// item.textureValues[shader->paramTexture1] = 1;
|
||||||
item.textureValues[shader->paramTexture2] = 2;
|
// item.textureValues[shader->paramTexture2] = 2;
|
||||||
|
|
||||||
return { item };
|
return { item };
|
||||||
}
|
}
|
||||||
@ -126,115 +133,115 @@ float_t UILabelNew::getContentHeight() {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void UILabelNew::bakeTexture(
|
// void UILabelNew::bakeTexture(
|
||||||
struct UILabelFontDef &fontDef,
|
// struct UILabelFontDef &fontDef,
|
||||||
FT_Face &face,
|
// FT_Face &face,
|
||||||
uint32_t fontSize
|
// uint32_t fontSize
|
||||||
) {
|
// ) {
|
||||||
fontDef.face = &face;
|
// fontDef.face = &face;
|
||||||
fontDef.fontSize = fontSize;
|
// fontDef.fontSize = fontSize;
|
||||||
|
|
||||||
if(FT_Set_Pixel_Sizes(face, 0, fontSize)) {
|
// if(FT_Set_Pixel_Sizes(face, 0, fontSize)) {
|
||||||
assertUnreachable();
|
// assertUnreachable();
|
||||||
}
|
// }
|
||||||
|
|
||||||
size_t w = 0, h = 0;
|
// size_t w = 0, h = 0;
|
||||||
FT_ULong c;
|
// FT_ULong c;
|
||||||
|
|
||||||
for(c = NEW_LABEL_CHAR_BEGIN; c < NEW_LABEL_CHAR_END; c++) {
|
// for(c = NEW_LABEL_CHAR_BEGIN; c < NEW_LABEL_CHAR_END; c++) {
|
||||||
// Load the character
|
// // Load the character
|
||||||
if(FT_Load_Char(face, c, FT_LOAD_RENDER | FT_LOAD_MONOCHROME)) {
|
// if(FT_Load_Char(face, c, FT_LOAD_RENDER | FT_LOAD_MONOCHROME)) {
|
||||||
assertUnreachable();
|
// assertUnreachable();
|
||||||
}
|
// }
|
||||||
|
|
||||||
// Update the width and height
|
// // Update the width and height
|
||||||
w = mathMax<size_t>(w, face->glyph->bitmap.width);
|
// w = mathMax<size_t>(w, face->glyph->bitmap.width);
|
||||||
h += face->glyph->bitmap.rows;
|
// h += face->glyph->bitmap.rows;
|
||||||
}
|
// }
|
||||||
|
|
||||||
assertTrue(w > 0);
|
// assertTrue(w > 0);
|
||||||
assertTrue(h > 0);
|
// assertTrue(h > 0);
|
||||||
|
|
||||||
// Now buffer pixels to the texture
|
// // Now buffer pixels to the texture
|
||||||
float_t y = 0;
|
// float_t y = 0;
|
||||||
|
|
||||||
// I'd love to just buffer straight to the GPU, but it seems that is a bit
|
// // I'd love to just buffer straight to the GPU, but it seems that is a bit
|
||||||
// unstable right now.
|
// // unstable right now.
|
||||||
uint8_t *buffer = (uint8_t *)memoryFillWithZero(w * h * sizeof(uint8_t));
|
// uint8_t *buffer = (uint8_t *)memoryFillWithZero(w * h * sizeof(uint8_t));
|
||||||
|
|
||||||
size_t offset = 0;
|
// size_t offset = 0;
|
||||||
for(c = NEW_LABEL_CHAR_BEGIN; c < NEW_LABEL_CHAR_END; c++) {
|
// for(c = NEW_LABEL_CHAR_BEGIN; c < NEW_LABEL_CHAR_END; c++) {
|
||||||
// Load the character
|
// // Load the character
|
||||||
if(FT_Load_Char(face, c, FT_LOAD_RENDER)) {
|
// if(FT_Load_Char(face, c, FT_LOAD_RENDER)) {
|
||||||
assertUnreachable();
|
// assertUnreachable();
|
||||||
}
|
// }
|
||||||
|
|
||||||
// Store the character information
|
// // Store the character information
|
||||||
struct UILabelChar info;
|
// struct UILabelChar info;
|
||||||
info.advanceX = face->glyph->advance.x;
|
// info.advanceX = face->glyph->advance.x;
|
||||||
info.advanceY = face->glyph->advance.y;
|
// info.advanceY = face->glyph->advance.y;
|
||||||
info.bitmapSize = glm::vec2(face->glyph->bitmap.width, face->glyph->bitmap.rows);
|
// info.bitmapSize = glm::vec2(face->glyph->bitmap.width, face->glyph->bitmap.rows);
|
||||||
info.bitmapPosition = glm::vec2(face->glyph->bitmap_left, -face->glyph->bitmap_top);
|
// info.bitmapPosition = glm::vec2(face->glyph->bitmap_left, -face->glyph->bitmap_top);
|
||||||
info.textureY = y;
|
// info.textureY = y;
|
||||||
fontDef.charStore[c] = info;
|
// fontDef.charStore[c] = info;
|
||||||
|
|
||||||
// Buffer the pixels, oh dear GOD there has to be a more efficient way.
|
// // Buffer the pixels, oh dear GOD there has to be a more efficient way.
|
||||||
for(int32_t i = 0; i < face->glyph->bitmap.rows; i++) {
|
// for(int32_t i = 0; i < face->glyph->bitmap.rows; i++) {
|
||||||
memoryCopy(
|
// memoryCopy(
|
||||||
(void *)(face->glyph->bitmap.buffer + (i * face->glyph->bitmap.width)),
|
// (void *)(face->glyph->bitmap.buffer + (i * face->glyph->bitmap.width)),
|
||||||
(void *)(buffer + offset),
|
// (void *)(buffer + offset),
|
||||||
face->glyph->bitmap.width * sizeof(uint8_t)
|
// face->glyph->bitmap.width * sizeof(uint8_t)
|
||||||
);
|
// );
|
||||||
offset += w * sizeof(uint8_t);
|
// offset += w * sizeof(uint8_t);
|
||||||
assertTrue(offset <= (w * h * sizeof(uint8_t)));
|
// assertTrue(offset <= (w * h * sizeof(uint8_t)));
|
||||||
}
|
// }
|
||||||
y += face->glyph->bitmap.rows;
|
// y += face->glyph->bitmap.rows;
|
||||||
}
|
// }
|
||||||
|
|
||||||
fontDef.texture.setSize(w, h, TEXTURE_FORMAT_R);
|
// fontDef.texture.setSize(w, h, TEXTURE_FORMAT_R);
|
||||||
fontDef.texture.buffer(buffer);
|
// fontDef.texture.buffer(buffer);
|
||||||
memoryFree(buffer);
|
// memoryFree(buffer);
|
||||||
}
|
// }
|
||||||
|
|
||||||
int32_t UILabelNew::bufferQuads(
|
// int32_t UILabelNew::bufferQuads(
|
||||||
std::string text,
|
// std::string text,
|
||||||
struct FontShaderBufferData &bufferData,
|
// struct FontShaderBufferData &bufferData,
|
||||||
struct UILabelFontDef &fontDef,
|
// struct UILabelFontDef &fontDef,
|
||||||
glm::vec2 &position,
|
// glm::vec2 &position,
|
||||||
int32_t quadStart,
|
// int32_t quadStart,
|
||||||
int32_t partIndex
|
// int32_t partIndex
|
||||||
) {
|
// ) {
|
||||||
// Get string length
|
// // Get string length
|
||||||
int32_t len = text.length();
|
// int32_t len = text.length();
|
||||||
|
|
||||||
glm::vec2 wh = glm::vec2(fontDef.texture.getWidth(), fontDef.texture.getHeight());
|
// glm::vec2 wh = glm::vec2(fontDef.texture.getWidth(), fontDef.texture.getHeight());
|
||||||
|
|
||||||
// For each char
|
// // For each char
|
||||||
for(int32_t i = 0; i < len; i++) {
|
// for(int32_t i = 0; i < len; i++) {
|
||||||
char ch = text[i];
|
// char ch = text[i];
|
||||||
int32_t j = quadStart + i;
|
// int32_t j = quadStart + i;
|
||||||
FT_ULong c = ch;
|
// FT_ULong c = ch;
|
||||||
auto &charInfo = fontDef.charStore[c];
|
// auto &charInfo = fontDef.charStore[c];
|
||||||
|
|
||||||
// Determine texture coordinates.
|
// // Determine texture coordinates.
|
||||||
glm::vec2 uv0 = glm::vec2(0.0f, charInfo.textureY) / wh;
|
// glm::vec2 uv0 = glm::vec2(0.0f, charInfo.textureY) / wh;
|
||||||
glm::vec2 uv1 = uv0 + (charInfo.bitmapSize / wh);
|
// glm::vec2 uv1 = uv0 + (charInfo.bitmapSize / wh);
|
||||||
|
|
||||||
// Buffer the quad.
|
// // Buffer the quad.
|
||||||
QuadMesh::bufferQuadMeshWithZ(&this->mesh,
|
// QuadMesh::bufferQuadMeshWithZ(&this->mesh,
|
||||||
position + charInfo.bitmapPosition, uv0,
|
// position + charInfo.bitmapPosition, uv0,
|
||||||
position + charInfo.bitmapPosition + charInfo.bitmapSize, uv1,
|
// position + charInfo.bitmapPosition + charInfo.bitmapSize, uv1,
|
||||||
0.0f,
|
// 0.0f,
|
||||||
j * QUAD_VERTICE_COUNT, j * QUAD_INDICE_COUNT
|
// j * QUAD_VERTICE_COUNT, j * QUAD_INDICE_COUNT
|
||||||
);
|
// );
|
||||||
|
|
||||||
// Move the current position along.
|
// // Move the current position along.
|
||||||
position.x += (float_t)(charInfo.advanceX >> 6);
|
// position.x += (float_t)(charInfo.advanceX >> 6);
|
||||||
position.y += (float_t)(charInfo.advanceY >> 6);
|
// position.y += (float_t)(charInfo.advanceY >> 6);
|
||||||
|
|
||||||
// Set the part index to the quad mappings
|
// // Set the part index to the quad mappings
|
||||||
bufferData.fontQuadMappings[j] = partIndex;
|
// bufferData.fontQuadMappings[j] = partIndex;
|
||||||
}
|
// }
|
||||||
|
|
||||||
return len;
|
// return len;
|
||||||
}
|
// }
|
@ -6,11 +6,12 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "scene/components/ui/UIComponentRenderable.hpp"
|
#include "scene/components/ui/UIComponentRenderable.hpp"
|
||||||
#include "display/mesh/QuadMesh.hpp"
|
#include "display/mesh/QuadMesh.hpp"
|
||||||
|
#include "asset/assets/NewTrueTypeAsset.hpp"
|
||||||
|
|
||||||
namespace Dawn {
|
namespace Dawn {
|
||||||
struct UILabelStyle {
|
struct UILabelStyle {
|
||||||
struct Color;
|
struct Color;
|
||||||
UILabelFontDef *fontDef;
|
// UILabelFontDef *fontDef;
|
||||||
};
|
};
|
||||||
|
|
||||||
class UILabelNew : public UIComponentRenderable {
|
class UILabelNew : public UIComponentRenderable {
|
||||||
@ -18,13 +19,15 @@ namespace Dawn {
|
|||||||
Mesh mesh;
|
Mesh mesh;
|
||||||
FontShaderBuffer shaderBuffer;
|
FontShaderBuffer shaderBuffer;
|
||||||
|
|
||||||
FT_Face face;
|
usagelockid_t fontLock = -1;
|
||||||
FT_Face faceBold;
|
|
||||||
FT_Face faceItalics;
|
|
||||||
|
|
||||||
struct UILabelFontDef defFace;
|
// FT_Face face;
|
||||||
struct UILabelFontDef defFaceBold;
|
// FT_Face faceBold;
|
||||||
struct UILabelFontDef defFaceItalics;
|
// FT_Face faceItalics;
|
||||||
|
|
||||||
|
// struct UILabelFontDef defFace;
|
||||||
|
// struct UILabelFontDef defFaceBold;
|
||||||
|
// struct UILabelFontDef defFaceItalics;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Buffers the quads for the given text and updates the progressing values
|
* Buffers the quads for the given text and updates the progressing values
|
||||||
@ -38,16 +41,22 @@ namespace Dawn {
|
|||||||
* @param partIndex The part index to store for each quad buffered.
|
* @param partIndex The part index to store for each quad buffered.
|
||||||
* @return The number of quads buffered, not the string length.
|
* @return The number of quads buffered, not the string length.
|
||||||
*/
|
*/
|
||||||
int32_t bufferQuads(
|
// int32_t bufferQuads(
|
||||||
std::string text,
|
// std::string text,
|
||||||
struct FontShaderBufferData &bufferData,
|
// struct FontShaderBufferData &bufferData,
|
||||||
struct UILabelFontDef &fontDef,
|
// struct UILabelFontDef &fontDef,
|
||||||
glm::vec2 &position,
|
// glm::vec2 &position,
|
||||||
int32_t quadStart,
|
// int32_t quadStart,
|
||||||
int32_t partIndex
|
// int32_t partIndex
|
||||||
);
|
// );
|
||||||
|
|
||||||
|
void rebufferQuads();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
StateProperty<NewTrueTypeAsset*> font;
|
||||||
|
StateProperty<uint32_t> fontSize;
|
||||||
|
StateProperty<flag_t> style;
|
||||||
|
|
||||||
UILabelNew(SceneItem *item);
|
UILabelNew(SceneItem *item);
|
||||||
|
|
||||||
void onStart() override;
|
void onStart() override;
|
||||||
|
@ -24,10 +24,14 @@ tool_texture(texture_eth FILE=${LIMINAL_ASSETS_DIR}/textures/eth.png)
|
|||||||
tool_texture(texture_border FILE=${LIMINAL_ASSETS_DIR}/textures/texture_test.png)
|
tool_texture(texture_border FILE=${LIMINAL_ASSETS_DIR}/textures/texture_test.png)
|
||||||
|
|
||||||
tool_newtruetype(font_arial
|
tool_newtruetype(font_arial
|
||||||
REGULAR="C:\\Windows\\Fonts\\arial.ttf"
|
REGULAR="/usr/share/fonts/TTF/arial.ttf"
|
||||||
BOLD="C:\\Windows\\Fonts\\arialbd.ttf"
|
BOLD="/usr/share/fonts/TTF/arialbd.ttf"
|
||||||
ITALICS="C:\\Windows\\Fonts\\ariali.ttf"
|
ITALICS="/usr/share/fonts/TTF/ariali.ttf"
|
||||||
BOLD_ITALICS="C:\\Windows\\Fonts\\arialbi.ttf"
|
BOLD_ITALICS="/usr/share/fonts/TTF/arialbi.ttf"
|
||||||
|
# REGULAR="C:\\Windows\\Fonts\\arial.ttf"
|
||||||
|
# BOLD="C:\\Windows\\Fonts\\arialbd.ttf"
|
||||||
|
# ITALICS="C:\\Windows\\Fonts\\ariali.ttf"
|
||||||
|
# BOLD_ITALICS="C:\\Windows\\Fonts\\arialbi.ttf"
|
||||||
)
|
)
|
||||||
|
|
||||||
tool_scene(${LIMINAL_ASSETS_DIR}/scenes/SceneBase.xml)
|
tool_scene(${LIMINAL_ASSETS_DIR}/scenes/SceneBase.xml)
|
||||||
|
@ -28,6 +28,12 @@ namespace Dawn {
|
|||||||
newLabelItem->transform.setParent(canvas->transform);
|
newLabelItem->transform.setParent(canvas->transform);
|
||||||
auto newLabel = newLabelItem->addComponent<UILabelNew>();
|
auto newLabel = newLabelItem->addComponent<UILabelNew>();
|
||||||
|
|
||||||
|
auto font = this->game->assetManager.get<NewTrueTypeAsset>("font_arial");
|
||||||
|
|
||||||
|
struct NewTrueTypeFaceTextureStyle style;
|
||||||
|
style.fontSize = 16;
|
||||||
|
style.style = 0;
|
||||||
|
|
||||||
// item = this->createSceneItem();
|
// item = this->createSceneItem();
|
||||||
// auto meshRenderer = item->addComponent<MeshRenderer>();
|
// auto meshRenderer = item->addComponent<MeshRenderer>();
|
||||||
// auto quadMeshHost = item->addComponent<QuadMeshHost>();
|
// auto quadMeshHost = item->addComponent<QuadMeshHost>();
|
||||||
@ -59,6 +65,7 @@ namespace Dawn {
|
|||||||
auto assMan = &this->game->assetManager;
|
auto assMan = &this->game->assetManager;
|
||||||
std::vector<Asset*> assets;
|
std::vector<Asset*> assets;
|
||||||
vectorAppend(&assets, SimpleSpinningCubePrefab::getRequiredAssets(assMan));
|
vectorAppend(&assets, SimpleSpinningCubePrefab::getRequiredAssets(assMan));
|
||||||
|
assets.push_back(assMan->get<NewTrueTypeAsset>("font_arial"));
|
||||||
return assets;
|
return assets;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,7 +28,6 @@ void RenderManager::init() {
|
|||||||
this->fontShader = this->shaderManager.getShader<FontShader>(this->lockFontShader);
|
this->fontShader = this->shaderManager.getShader<FontShader>(this->lockFontShader);
|
||||||
|
|
||||||
this->renderPipeline.init();
|
this->renderPipeline.init();
|
||||||
this->fontManager.init();
|
|
||||||
|
|
||||||
// Prepare the initial values
|
// Prepare the initial values
|
||||||
glEnable(GL_TEXTURE_2D);
|
glEnable(GL_TEXTURE_2D);
|
||||||
@ -52,10 +51,6 @@ ShaderManager * RenderManager::getShaderManager() {
|
|||||||
return &this->shaderManager;
|
return &this->shaderManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
FontManager * RenderManager::getFontManager() {
|
|
||||||
return &this->fontManager;
|
|
||||||
}
|
|
||||||
|
|
||||||
void RenderManager::setRenderFlags(renderflag_t flags) {
|
void RenderManager::setRenderFlags(renderflag_t flags) {
|
||||||
this->renderFlags = flags;
|
this->renderFlags = flags;
|
||||||
|
|
||||||
|
@ -10,7 +10,6 @@
|
|||||||
#include "display/shader/shaders/FontShader.hpp"
|
#include "display/shader/shaders/FontShader.hpp"
|
||||||
#include "display/shader/shaders/UIShader.hpp"
|
#include "display/shader/shaders/UIShader.hpp"
|
||||||
#include "display/RenderPipeline.hpp"
|
#include "display/RenderPipeline.hpp"
|
||||||
#include "display/font/FontManager.hpp"
|
|
||||||
#include "display/font/ExampleFont.hpp"
|
#include "display/font/ExampleFont.hpp"
|
||||||
|
|
||||||
namespace Dawn {
|
namespace Dawn {
|
||||||
@ -18,7 +17,6 @@ namespace Dawn {
|
|||||||
private:
|
private:
|
||||||
RenderPipeline renderPipeline;
|
RenderPipeline renderPipeline;
|
||||||
ShaderManager shaderManager;
|
ShaderManager shaderManager;
|
||||||
FontManager fontManager;
|
|
||||||
shaderlock_t lockSimpleTextured = -1;
|
shaderlock_t lockSimpleTextured = -1;
|
||||||
shaderlock_t lockUIShaderProgram = -1;
|
shaderlock_t lockUIShaderProgram = -1;
|
||||||
shaderlock_t lockFontShader = -1;
|
shaderlock_t lockFontShader = -1;
|
||||||
@ -38,7 +36,6 @@ namespace Dawn {
|
|||||||
RenderTarget * getBackBuffer() override;
|
RenderTarget * getBackBuffer() override;
|
||||||
RenderPipeline * getRenderPipeline() override;
|
RenderPipeline * getRenderPipeline() override;
|
||||||
ShaderManager * getShaderManager() override;
|
ShaderManager * getShaderManager() override;
|
||||||
FontManager * getFontManager() override;
|
|
||||||
void setRenderFlags(renderflag_t renderFlags) override;
|
void setRenderFlags(renderflag_t renderFlags) override;
|
||||||
void init() override;
|
void init() override;
|
||||||
void update() override;
|
void update() override;
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
#include "assert/assert.hpp"
|
#include "assert/assert.hpp"
|
||||||
|
|
||||||
namespace Dawn {
|
namespace Dawn {
|
||||||
typedef uint32_t usagelockid_t;
|
typedef int32_t usagelockid_t;
|
||||||
|
|
||||||
class UsageLock {
|
class UsageLock {
|
||||||
protected:
|
protected:
|
||||||
|
@ -77,7 +77,6 @@ int32_t NewTrueTypeTool::start() {
|
|||||||
cleanupFiles();
|
cleanupFiles();
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
std::cout << "Push back" << std::endl;
|
|
||||||
++itFlag;
|
++itFlag;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user