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