mirror of
https://github.com/ApfelTeeSaft/vb01.git
synced 2026-08-26 19:33:45 +00:00
implemented font reader
This commit is contained in:
+1
-1
@@ -18,7 +18,7 @@ set(RENDER lineRenderer.cpp particleEmitter.cpp camera.cpp light.cpp material.cp
|
||||
set(MODEL modelReader.cpp assimpModelReader.cpp vbModelReader.cpp)
|
||||
set(ANIM animationController.cpp animationChannel.cpp animation.cpp animatable.h keyframeChannel.cpp driver.cpp)
|
||||
set(ARMATURE skeleton.cpp bone.cpp ikSolver.cpp)
|
||||
set(ASSET_READERS abstractAssetReader.cpp imageReader.cpp)
|
||||
set(ASSET_READERS abstractAssetReader.cpp imageReader.cpp fontReader.cpp)
|
||||
set(ASSET_MANAGER assetManager.cpp textAsset.h imageAsset.h modelAsset.h fontAsset.h)
|
||||
set(LIB_SRC ${RENDER} ${MATH} ${MODEL} ${UTILS} ${GUI} ${ARMATURE} ${ASSET_MANAGER} ${ASSET_READERS} ${ANIM})
|
||||
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
#include "abstractAssetReader.h"
|
||||
|
||||
namespace vb01{
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
#ifndef ABSTRACT_ASSET_READER_H
|
||||
#define ABSTRACT_ASSET_READER_H
|
||||
|
||||
#include "asset.h"
|
||||
|
||||
namespace vb01{
|
||||
class AbstractAssetReader{
|
||||
public:
|
||||
virtual Asset* readAsset(std::string){return nullptr;}
|
||||
protected:
|
||||
AbstractAssetReader(){}
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
+1
-1
@@ -5,7 +5,7 @@
|
||||
|
||||
namespace vb01{
|
||||
struct FontAsset : public Asset{
|
||||
u32 **glyphImages;
|
||||
FT_Face face;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
#include "fontReader.h"
|
||||
#include "fontAsset.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include "glad.h"
|
||||
#include <glfw3.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace vb01{
|
||||
FontReader *fontReader = nullptr;
|
||||
|
||||
FontReader* FontReader::getSingleton(){
|
||||
if(!fontReader)
|
||||
fontReader = new FontReader();
|
||||
|
||||
return fontReader;
|
||||
}
|
||||
|
||||
FontReader::FontReader() : AbstractAssetReader(){
|
||||
if(FT_Init_FreeType(&ft))
|
||||
cout << "Couldn't init Freetype\n";
|
||||
}
|
||||
|
||||
Asset* FontReader::readAsset(string path){
|
||||
if(FT_New_Face(ft, path.c_str(), 0, &face))
|
||||
cout << "Could not load font\n";
|
||||
|
||||
FT_Set_Pixel_Sizes(face, pixelWidth, pixelHeight);
|
||||
|
||||
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
||||
|
||||
FontAsset *font = new FontAsset;
|
||||
font->path = path;
|
||||
font->face = face;
|
||||
|
||||
return font;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
#ifndef FONT_READER_H
|
||||
#define FONT_READER_H
|
||||
|
||||
#include "abstractAssetReader.h"
|
||||
#include "util.h"
|
||||
|
||||
#include <ft2build.h>
|
||||
#include FT_FREETYPE_H
|
||||
|
||||
namespace vb01{
|
||||
class FontReader : public AbstractAssetReader{
|
||||
public:
|
||||
static FontReader* getSingleton();
|
||||
Asset* readAsset(std::string);
|
||||
inline void setPixelWidth(int w){this->pixelWidth = w;}
|
||||
inline void setPixelHeight(int h){this->pixelHeight = h;}
|
||||
inline int getPixelWidth(){return pixelWidth;}
|
||||
inline int getPixelHeight(){return pixelHeight;}
|
||||
inline FT_Library& getFT(){return ft;}
|
||||
private:
|
||||
FontReader();
|
||||
|
||||
int pixelWidth = 0, pixelHeight = 100;
|
||||
FT_Library ft;
|
||||
FT_Face face;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -4,6 +4,9 @@
|
||||
#include "texture.h"
|
||||
#include "node.h"
|
||||
#include "material.h"
|
||||
#include "fontReader.h"
|
||||
#include "fontAsset.h"
|
||||
#include "assetManager.h"
|
||||
|
||||
#include "glad.h"
|
||||
#include <glfw3.h>
|
||||
@@ -26,18 +29,10 @@ namespace vb01{
|
||||
}
|
||||
|
||||
void Text::initFont(string fontPath, u16 firstChar, u16 lastChar){
|
||||
FT_Library ft;
|
||||
FT_Face face;
|
||||
|
||||
if(FT_Init_FreeType(&ft))
|
||||
cout << "Couldn't init Freetype\n";
|
||||
|
||||
if(FT_New_Face(ft, fontPath.c_str(), 0, &face))
|
||||
cout << "Could not load font\n";
|
||||
|
||||
FT_Set_Pixel_Sizes(face, 0, 100);
|
||||
|
||||
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
||||
FontReader *fontReader = FontReader::getSingleton();
|
||||
FT_Library &ft = fontReader->getFT();
|
||||
FontAsset *font = (FontAsset*)AssetManager::getSingleton()->getAsset(fontPath);
|
||||
FT_Face face = font->face;
|
||||
|
||||
for(u16 i = firstChar; i < lastChar; i++){
|
||||
if(FT_Load_Char(face, i, FT_LOAD_RENDER)){
|
||||
@@ -53,9 +48,6 @@ namespace vb01{
|
||||
c.advance = face->glyph->advance.x;
|
||||
characters.push_back(c);
|
||||
}
|
||||
|
||||
FT_Done_Face(face);
|
||||
FT_Done_FreeType(ft);
|
||||
}
|
||||
|
||||
void Text::update(){
|
||||
|
||||
@@ -6,6 +6,9 @@
|
||||
#include "node.h"
|
||||
#include "animationController.h"
|
||||
#include "animationChannel.h"
|
||||
#include "imageReader.h"
|
||||
#include "fontReader.h"
|
||||
#include "assetManager.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace vb01;
|
||||
@@ -55,10 +58,14 @@ int main(){
|
||||
textMat->addBoolUniform("texturingEnabled", true);
|
||||
|
||||
string frames[]{TEX_PATH + "bricks.jpg", TEX_PATH + "defaultTexture.jpg"};
|
||||
AssetManager::getSingleton()->load(ImageReader::getSingleton(), frames[0]);
|
||||
AssetManager::getSingleton()->load(ImageReader::getSingleton(), frames[1]);
|
||||
Texture *texture = new Texture(frames, 2, false);
|
||||
textMat->addTexUniform("textures[0]", texture, true);
|
||||
|
||||
for(int i = 0; i < numTexts; i++){
|
||||
AssetManager::getSingleton()->load(FontReader::getSingleton(), FONT_PATH + fonts[i]);
|
||||
|
||||
Text *text = new Text(FONT_PATH + fonts[i], texts[i], 0, 60000);
|
||||
text->setLeftToRight(leftToRight[i]);
|
||||
text->setScale(.5);
|
||||
|
||||
Reference in New Issue
Block a user