mirror of
https://github.com/ApfelTeeSaft/vb01.git
synced 2026-08-26 19:33:45 +00:00
generating VAO and VBO only once
This commit is contained in:
@@ -16,9 +16,9 @@
|
|||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
namespace vb01{
|
namespace vb01{
|
||||||
Text::Text(string fontPath, wstring entry, u16 firstChar, u16 lastChar){
|
Text::Text(string fontPath, wstring e, u16 firstChar, u16 lastChar) : entry(e){
|
||||||
|
init();
|
||||||
applyFont(fontPath, firstChar, lastChar);
|
applyFont(fontPath, firstChar, lastChar);
|
||||||
setText(entry);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Text::~Text(){
|
Text::~Text(){
|
||||||
@@ -26,6 +26,21 @@ namespace vb01{
|
|||||||
glDeleteBuffers(1, &VBO);
|
glDeleteBuffers(1, &VBO);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Text::init(){
|
||||||
|
glGenVertexArrays(1, &VAO);
|
||||||
|
glGenBuffers(1, &VBO);
|
||||||
|
|
||||||
|
glBindVertexArray(VAO);
|
||||||
|
glBindBuffer(GL_ARRAY_BUFFER, VBO);
|
||||||
|
|
||||||
|
glBufferData(GL_ARRAY_BUFFER, sizeof(float) * 6 * 4, NULL, GL_DYNAMIC_DRAW);
|
||||||
|
glEnableVertexAttribArray(0);
|
||||||
|
glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 4 * sizeof(float), (void*)0);
|
||||||
|
|
||||||
|
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||||
|
glBindVertexArray(0);
|
||||||
|
}
|
||||||
|
|
||||||
//TODO ensure destruction of textures when unloading the asset
|
//TODO ensure destruction of textures when unloading the asset
|
||||||
void Text::applyFont(string fontPath, u16 firstChar, u16 lastChar){
|
void Text::applyFont(string fontPath, u16 firstChar, u16 lastChar){
|
||||||
characters.clear();
|
characters.clear();
|
||||||
@@ -120,20 +135,6 @@ namespace vb01{
|
|||||||
glDrawArrays(GL_TRIANGLES, 0, 6);
|
glDrawArrays(GL_TRIANGLES, 0, 6);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Text::setText(wstring text){
|
|
||||||
this->entry = text;
|
|
||||||
|
|
||||||
glGenVertexArrays(1, &VAO);
|
|
||||||
glGenBuffers(1, &VBO);
|
|
||||||
glBindVertexArray(VAO);
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, VBO);
|
|
||||||
glBufferData(GL_ARRAY_BUFFER, sizeof(float) * 6 * 4, NULL, GL_DYNAMIC_DRAW);
|
|
||||||
glEnableVertexAttribArray(0);
|
|
||||||
glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 4 * sizeof(float), (void*)0);
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
|
||||||
glBindVertexArray(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
Text::Glyph* Text::getGlyph(u16 ch){
|
Text::Glyph* Text::getGlyph(u16 ch){
|
||||||
Glyph *glyph = nullptr;
|
Glyph *glyph = nullptr;
|
||||||
|
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ namespace vb01{
|
|||||||
Text(std::string, std::wstring, u16 = 0, u16 = 256);
|
Text(std::string, std::wstring, u16 = 0, u16 = 256);
|
||||||
~Text();
|
~Text();
|
||||||
void update();
|
void update();
|
||||||
void setText(std::wstring);
|
void setText(std::wstring e){this->entry = e;}
|
||||||
inline void setScale(float s){this->scale = s;}
|
inline void setScale(float s){this->scale = s;}
|
||||||
inline float getScale(){return scale;}
|
inline float getScale(){return scale;}
|
||||||
inline int getLength(){return entry.length();}
|
inline int getLength(){return entry.length();}
|
||||||
@@ -39,6 +39,7 @@ namespace vb01{
|
|||||||
inline void setMaterial(Material *mat){this->material = mat;}
|
inline void setMaterial(Material *mat){this->material = mat;}
|
||||||
Glyph* getGlyph(u16);
|
Glyph* getGlyph(u16);
|
||||||
private:
|
private:
|
||||||
|
void init();
|
||||||
void applyFont(std::string, u16, u16 = 256);
|
void applyFont(std::string, u16, u16 = 256);
|
||||||
void clearFont();
|
void clearFont();
|
||||||
void prepareGlyphs(Glyph, int, Vector2);
|
void prepareGlyphs(Glyph, int, Vector2);
|
||||||
|
|||||||
Reference in New Issue
Block a user