end binding mayhem? do not generate ascii glyphs on start

This commit is contained in:
jrkb 2023-04-03 15:44:42 +02:00
parent eeb211844e
commit 0ef89aac10

View file

@ -150,9 +150,7 @@ class Font {
#ifndef TARGET_OPENGLES #ifndef TARGET_OPENGLES
glGenTextures(1, &glyphTexture); glGenTextures(1, &glyphTexture);
glGenTextures(1, &curveTexture); glGenTextures(1, &curveTexture);
#endif
#ifndef TARGET_OPENGLES
glGenBuffers(1, &glyphBuffer); glGenBuffers(1, &glyphBuffer);
glGenBuffers(1, &curveBuffer); glGenBuffers(1, &curveBuffer);
#else #else
@ -171,32 +169,32 @@ class Font {
glVertexAttribIPointer(2, 1, GL_INT, sizeof(BufferVertex), (void *)offsetof(BufferVertex, bufferIndex)); glVertexAttribIPointer(2, 1, GL_INT, sizeof(BufferVertex), (void *)offsetof(BufferVertex, bufferIndex));
glBindVertexArray(0); glBindVertexArray(0);
{ //{
uint32_t charcode = 0; //uint32_t charcode = 0;
FT_UInt glyphIndex = 0; //FT_UInt glyphIndex = 0;
FT_Error error = FT_Load_Glyph(face, glyphIndex, loadFlags); //FT_Error error = FT_Load_Glyph(face, glyphIndex, loadFlags);
if(error){ //if(error){
std::cerr << "[font] error while loading undefined glyph: " << error << std::endl; //std::cerr << "[font] error while loading undefined glyph: " << error << std::endl;
// Continue, because we always want an entry for the undefined glyph in our glyphs map! //// Continue, because we always want an entry for the undefined glyph in our glyphs map!
} //}
buildGlyph(charcode, glyphIndex); //buildGlyph(charcode, glyphIndex);
} //}
for(uint32_t charcode = 32; charcode < 128; charcode++){ //for(uint32_t charcode = 32; charcode < 128; charcode++){
FT_UInt glyphIndex = FT_Get_Char_Index(face, charcode); //FT_UInt glyphIndex = FT_Get_Char_Index(face, charcode);
if(!glyphIndex){ //if(!glyphIndex){
continue; //continue;
} //}
FT_Error error = FT_Load_Glyph(face, glyphIndex, loadFlags); //FT_Error error = FT_Load_Glyph(face, glyphIndex, loadFlags);
if(error){ //if(error){
std::cerr << "[font] error while loading glyph for character " << charcode << ": " << error << std::endl; //std::cerr << "[font] error while loading glyph for character " << charcode << ": " << error << std::endl;
continue; //continue;
} //}
buildGlyph(charcode, glyphIndex); //buildGlyph(charcode, glyphIndex);
} //}
uploadBuffers(); uploadBuffers();
@ -306,10 +304,13 @@ class Font {
for(const char * textIt = text.c_str(); *textIt != '\0';){ for(const char * textIt = text.c_str(); *textIt != '\0';){
uint32_t charcode = decodeCharcode(&textIt); uint32_t charcode = decodeCharcode(&textIt);
//cout << "yes, this is running" << endl;
if(charcode == '\r' || charcode == '\n'){ if(charcode == '\r' || charcode == '\n'){
//cout << "but charcode is r or n" << endl;
continue; continue;
} }
if(glyphs.count(charcode) != 0){ if(glyphs.count(charcode) != 0){
//cout << "but count is not 0?" << endl;
continue; continue;
} }
@ -333,11 +334,13 @@ class Font {
// dynamic, the buffers could be overallocated and only the added // dynamic, the buffers could be overallocated and only the added
// data could be uploaded. // data could be uploaded.
uploadBuffers(); uploadBuffers();
//cout << "glyphs changed" << endl;
}else{
//cout << "glyphs not changed" << endl;
} }
} }
private: private:
bool done = false;
void uploadBuffers(){ void uploadBuffers(){
cout << "bufferGlyphs.size(): " << bufferGlyphs.size() << endl; cout << "bufferGlyphs.size(): " << bufferGlyphs.size() << endl;
cout << "bufferCurves.size(): " << bufferCurves.size() << endl; cout << "bufferCurves.size(): " << bufferCurves.size() << endl;
@ -426,6 +429,9 @@ class Font {
GL_RG, GL_RG,
GL_FLOAT, GL_FLOAT,
bufferCurves.data()); bufferCurves.data());
glActiveTexture(GL_TEXTURE0);
//glBindTexture(GL_TEXTURE_2D, 0);
//unsigned char * data = new unsigned char[3 * size * sizeof(unsigned char)]; //unsigned char * data = new unsigned char[3 * size * sizeof(unsigned char)];
//for(unsigned int i = 0; i < size; i++){ //for(unsigned int i = 0; i < size; i++){
@ -735,18 +741,20 @@ class Font {
glActiveTexture(GL_TEXTURE0); glActiveTexture(GL_TEXTURE0);
#else #else
location = glGetUniformLocation(program, "glyphs"); // Important! The GLint for the location needs to stick around
glUniform1i(location, 2); // we cannot reuse a location as in Desktop for some reason
location = glGetUniformLocation(program, "curves"); glyphBufferLocation = glGetUniformLocation(program, "glyphs");
glUniform1i(location, 1); glUniform1i(glyphBufferLocation, 2);
curveBufferLocation = glGetUniformLocation(program, "curves");
glUniform1i(curveBufferLocation, 1);
glActiveTexture(GL_TEXTURE2); glActiveTexture(GL_TEXTURE2);
glBindTexture(GL_TEXTURE_2D, glyphBuffer); glBindTexture(GL_TEXTURE_2D, glyphBuffer);
glActiveTexture(GL_TEXTURE1); glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_BUFFER, curveBuffer); glBindTexture(GL_TEXTURE_2D, curveBuffer);
//glActiveTexture(GL_TEXTURE0); glActiveTexture(GL_TEXTURE0);
#endif #endif
} }
@ -923,6 +931,8 @@ class Font {
GLuint vao, vbo, ebo; GLuint vao, vbo, ebo;
#ifndef TARGET_OPENGLES #ifndef TARGET_OPENGLES
GLuint glyphTexture, curveTexture; GLuint glyphTexture, curveTexture;
#else
GLint glyphBufferLocation, curveBufferLocation;
#endif #endif
GLuint glyphBuffer, curveBuffer; GLuint glyphBuffer, curveBuffer;