GUI quad rendering

improved font and image readers
different mesh VAOs for spatial and GUI quads
This commit is contained in:
devZoGok
2026-07-06 13:01:31 +03:00
parent 3193c61036
commit e448f7003e
15 changed files with 406 additions and 269 deletions
+51 -24
View File
@@ -1,40 +1,67 @@
#include "fontReader.h"
#include "fontAsset.h"
#include "root.h"
#include "stb_image.h"
#include <iostream>
#include "glad.h"
#include <glad.h>
#include <glfw3.h>
using namespace std;
namespace vb01{
FontReader *fontReader = nullptr;
FontReader *fontReader = nullptr;
FontReader* FontReader::getSingleton(){
if(!fontReader)
fontReader = new FontReader();
FontReader* FontReader::getSingleton(){
if(!fontReader)
fontReader = new FontReader();
return 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);
vector<FontAsset::Glyph> glyphs;
Root *root = Root::getSingleton();
u32 *buffer = root->getGuiTextureBuffer();
for(u16 i = firstChar; i < lastChar; i++){
if(FT_Load_Char(face, i, FT_LOAD_RENDER)){
cout << "Could not load glyph\n";
continue;
}
FontAsset::Glyph glyph = FontAsset::Glyph(
i,
face->glyph->bitmap.buffer,
Vector2(face->glyph->bitmap.width, face->glyph->bitmap.rows),
Vector2(face->glyph->bitmap_left, face->glyph->bitmap_top),
face->glyph->advance.x,
-1
);
root->initTextureDataOnGpu(buffer, glyph.data, glyph.size.x, glyph.size.y, glyph.layerId);
glyphs.push_back(glyph);
}
FontReader::FontReader() : AbstractAssetReader(){
if(FT_Init_FreeType(&ft))
cout << "Couldn't init Freetype\n";
}
FontAsset *font = new FontAsset;
font->path = path;
font->face = face;
font->glyphs = glyphs;
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;
}
return font;
}
}