Mid prog font
This commit is contained in:
@ -82,6 +82,7 @@ namespace Dawn {
|
||||
* @param color Color to fill.
|
||||
*/
|
||||
virtual void fill(struct Color) = 0;
|
||||
virtual void fill(uint8_t) = 0;
|
||||
|
||||
/**
|
||||
* Returns true only when the texture has been loaded, sized and put on
|
||||
|
@ -11,4 +11,5 @@ target_sources(${DAWN_TARGET_NAME}
|
||||
ExampleFont.cpp
|
||||
TrueTypeFont.cpp
|
||||
FontMeasure.cpp
|
||||
NewTrueType.cpp
|
||||
)
|
68
src/dawn/display/font/NewTrueType.cpp
Normal file
68
src/dawn/display/font/NewTrueType.cpp
Normal file
@ -0,0 +1,68 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "NewTrueType.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
void Dawn::_newTrueTypePlaceholder(
|
||||
FT_Face face,
|
||||
Texture &texture,
|
||||
std::map<FT_ULong, struct TrueTypeCharacterInfo> &charStore
|
||||
) {
|
||||
size_t w = 0, h = 0;
|
||||
FT_ULong c;
|
||||
|
||||
for(c = NEW_TRUETYPE_CHAR_BEGIN; c < NEW_TRUETYPE_CHAR_END; c++) {
|
||||
// Load the character
|
||||
if(FT_Load_Char(face, c, FT_LOAD_RENDER)) {
|
||||
assertUnreachable();
|
||||
}
|
||||
|
||||
// Update the width and height
|
||||
w = mathMax<size_t>(w, face->glyph->bitmap.width);
|
||||
h += face->glyph->bitmap.rows;
|
||||
}
|
||||
|
||||
|
||||
// Now buffer pixels to the texture
|
||||
float_t y = 0;
|
||||
|
||||
// I'd love to just buffer straight to the GPU, but it seems that is a bit
|
||||
// unstable right now.
|
||||
uint8_t *buffer = (uint8_t *)memoryAllocate(w * h * sizeof(uint8_t));
|
||||
memorySet(buffer, 0x00, sizeof(uint8_t) * w * h);
|
||||
|
||||
size_t offset = 0;
|
||||
for(c = NEW_TRUETYPE_CHAR_BEGIN; c < NEW_TRUETYPE_CHAR_END; c++) {
|
||||
// Load the character
|
||||
if(FT_Load_Char(face, c, FT_LOAD_RENDER)) {
|
||||
assertUnreachable();
|
||||
}
|
||||
|
||||
// Store the character information
|
||||
struct TrueTypeCharacterInfo info;
|
||||
info.advance = glm::vec2(face->glyph->advance.x, face->glyph->advance.y);
|
||||
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.textureY = y;
|
||||
charStore[c] = info;
|
||||
|
||||
// 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++) {
|
||||
memoryCopy(
|
||||
(void *)(face->glyph->bitmap.buffer + (i * face->glyph->bitmap.width)),
|
||||
(void *)(buffer + offset),
|
||||
face->glyph->bitmap.width * sizeof(uint8_t)
|
||||
);
|
||||
offset += w * sizeof(uint8_t);
|
||||
}
|
||||
y += face->glyph->bitmap.rows;
|
||||
}
|
||||
|
||||
texture.setSize(w, h, TEXTURE_FORMAT_R);
|
||||
texture.buffer(buffer);
|
||||
memoryFree(buffer);
|
||||
}
|
27
src/dawn/display/font/NewTrueType.hpp
Normal file
27
src/dawn/display/font/NewTrueType.hpp
Normal file
@ -0,0 +1,27 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "dawnlibs.hpp"
|
||||
#include "util/mathutils.hpp"
|
||||
#include "display/Texture.hpp"
|
||||
|
||||
#define NEW_TRUETYPE_CHAR_BEGIN 0x00
|
||||
#define NEW_TRUETYPE_CHAR_END 0xFF
|
||||
|
||||
namespace Dawn {
|
||||
struct TrueTypeCharacterInfo {
|
||||
glm::vec2 advance;
|
||||
glm::vec2 bitmapSize;
|
||||
glm::vec2 bitmapPosition;
|
||||
float_t textureY;
|
||||
};
|
||||
|
||||
void _newTrueTypePlaceholder(
|
||||
FT_Face face,
|
||||
Texture &texture,
|
||||
std::map<FT_ULong, struct TrueTypeCharacterInfo> &charStore
|
||||
);
|
||||
}
|
@ -10,6 +10,5 @@
|
||||
using namespace Dawn;
|
||||
|
||||
Scene * Dawn::dawnGameGetInitialScene(DawnGame *game) {
|
||||
// return new Scene1Prologue(game);
|
||||
return new HelloWorldScene(game);
|
||||
}
|
@ -10,16 +10,50 @@
|
||||
#include "scene/components/ui/UIImage.hpp"
|
||||
#include "display/font/BitmapFont.hpp"
|
||||
|
||||
#include "display/font/NewTrueType.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
class HelloWorldScene : public Scene {
|
||||
protected:
|
||||
Camera *camera;
|
||||
SimpleSpinningCubePrefab *cube;
|
||||
FT_Face face;
|
||||
Texture texture;
|
||||
std::map<FT_ULong, struct TrueTypeCharacterInfo> charStore;
|
||||
|
||||
SceneItem *item;
|
||||
|
||||
void stage() override {
|
||||
camera = Camera::create(this);
|
||||
camera->transform->lookAt(glm::vec3(3, 3, 3), glm::vec3(0, 0, 0));
|
||||
cube = SimpleSpinningCubePrefab::create(this);
|
||||
|
||||
// cube = SimpleSpinningCubePrefab::create(this);
|
||||
|
||||
item = this->createSceneItem();
|
||||
auto meshRenderer = item->addComponent<MeshRenderer>();
|
||||
auto quadMeshHost = item->addComponent<QuadMeshHost>();
|
||||
auto material = item->addComponent<SimpleTexturedMaterial>();
|
||||
|
||||
if(FT_New_Face(
|
||||
this->game->renderManager.getFontManager()->fontLibrary,
|
||||
"C:\\Windows\\Fonts\\Arial.ttf",
|
||||
0,
|
||||
&face
|
||||
)) {
|
||||
assertUnreachable();
|
||||
}
|
||||
if(FT_Set_Pixel_Sizes(face, 0, 16)) {
|
||||
assertUnreachable();
|
||||
}
|
||||
|
||||
_newTrueTypePlaceholder(face, texture, charStore);
|
||||
FT_ULong c = 'B';
|
||||
auto x = charStore[c];
|
||||
glm::vec2 wh = glm::vec2(texture.getWidth(), texture.getHeight());
|
||||
quadMeshHost->uv0 = glm::vec2(0.0f, x.textureY) / wh;
|
||||
quadMeshHost->uv1 = (glm::vec2)quadMeshHost->uv0 + (x.bitmapSize / wh);
|
||||
std::cout << "Done" << std::endl;
|
||||
material->texture = &texture;
|
||||
}
|
||||
|
||||
std::vector<Asset*> getRequiredAssets() override {
|
||||
|
@ -22,6 +22,10 @@ float_t BackBufferRenderTarget::getHeight() {
|
||||
|
||||
void BackBufferRenderTarget::setSize(float_t width, float_t height) {
|
||||
if(this->width == width && this->height == height) return;
|
||||
|
||||
// Fixes a new bug that it seems GLFW has introduced.
|
||||
if(width == 0) width = 1;
|
||||
if(height == 0) height = 1;
|
||||
|
||||
this->width = width;
|
||||
this->height = height;
|
||||
|
@ -28,6 +28,7 @@ void RenderManager::init() {
|
||||
this->fontShader = this->shaderManager.getShader<FontShader>(this->lockFontShader);
|
||||
|
||||
this->renderPipeline.init();
|
||||
this->fontManager.init();
|
||||
|
||||
// Prepare the initial values
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
|
@ -62,6 +62,14 @@ void Texture::fill(struct Color color) {
|
||||
memoryFree(pixels);
|
||||
}
|
||||
|
||||
void Texture::fill(uint8_t color) {
|
||||
uint8_t *pixels = (uint8_t *)memoryAllocate(
|
||||
sizeof(uint8_t) * this->width * this->height
|
||||
);
|
||||
this->buffer(pixels);
|
||||
memoryFree(pixels);
|
||||
}
|
||||
|
||||
bool_t Texture::isReady() {
|
||||
return this->id != -1;
|
||||
}
|
||||
|
@ -30,6 +30,7 @@ namespace Dawn {
|
||||
int32_t getHeight() override;
|
||||
void setSize(int32_t width, int32_t height, enum TextureFormat format) override;
|
||||
void fill(struct Color) override;
|
||||
void fill(uint8_t) override;
|
||||
bool_t isReady() override;
|
||||
void buffer(struct Color pixels[]) override;
|
||||
void buffer(uint8_t pixels[]) override;
|
||||
|
Reference in New Issue
Block a user