diff --git a/src/gpufont/font.hpp b/src/gpufont/font.hpp index 98b63c1..27c71fa 100644 --- a/src/gpufont/font.hpp +++ b/src/gpufont/font.hpp @@ -169,7 +169,11 @@ class Font { // If hinting is enabled, worldSize must be an integer and defines the font size in pixels used for hinting. // Otherwise, worldSize can be an arbitrary floating-point value. - Font(FT_Face face, float worldSize = 1.0f, bool hinting = false) : face(face), worldSize(worldSize), hinting(hinting){ + Font(FT_Face face, int gpuTextureOffset, float worldSize = 1.0f, bool hinting = false) : + face(face), + gpuTextureOffset(gpuTextureOffset), + worldSize(worldSize), + hinting(hinting){ // TODO: modularize init, so we can initialize with settings and text if(hinting){ @@ -340,6 +344,9 @@ class Font { private: bool initializedGlyphsBufferTexture = false; bool initializedCurvesBufferTexture = false; + int calcTextureOffset(){ + return gpuTextureOffset * 2; + } void uploadBuffers(){ //cout << "bufferGlyphs.size(): " << bufferGlyphs.size() << endl; //cout << "bufferCurves.size(): " << bufferCurves.size() << endl; @@ -356,7 +363,7 @@ class Font { if(!isPowerOfTwo(bufferGlyphsSize)){ bufferGlyphsSize = calculateUpperPowerOfTwo(bufferGlyphsSize); } - glActiveTexture(GL_TEXTURE3); + glActiveTexture(GL_TEXTURE3 + calcTextureOffset()); glBindTexture(GL_TEXTURE_2D, glyphBuffer); if(!initializedGlyphsBufferTexture){ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); @@ -383,7 +390,7 @@ class Font { if(!isPowerOfTwo(bufferCurvesSize)){ bufferCurvesSize = calculateUpperPowerOfTwo(bufferCurvesSize); } - glActiveTexture(GL_TEXTURE4); + glActiveTexture(GL_TEXTURE4 + calcTextureOffset()); glBindTexture(GL_TEXTURE_2D, curveBuffer); if(!initializedCurvesBufferTexture){ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); @@ -686,14 +693,14 @@ class Font { // 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, 3); + glUniform1i(glyphBufferLocation, 3 + calcTextureOffset()); curveBufferLocation = glGetUniformLocation(program, "curves"); - glUniform1i(curveBufferLocation, 4); + glUniform1i(curveBufferLocation, 4 + calcTextureOffset()); - glActiveTexture(GL_TEXTURE3); + glActiveTexture(GL_TEXTURE3 + calcTextureOffset()); glBindTexture(GL_TEXTURE_2D, glyphBuffer); - glActiveTexture(GL_TEXTURE4); + glActiveTexture(GL_TEXTURE4 + calcTextureOffset()); glBindTexture(GL_TEXTURE_2D, curveBuffer); glActiveTexture(GL_TEXTURE0); @@ -992,9 +999,14 @@ class Font { // The glyph quads are expanded by this amount to enable proper // anti-aliasing. Value is relative to emSize. float dilation = 0; + int gpuTextureOffset = 0; }; -static std::shared_ptr loadFont(FT_Library & library, const std::string & filename, float worldSize = 1.0f, bool hinting = false){ +static std::shared_ptr loadFont(FT_Library & library, + const std::string & filename, + int gpuTextureOffset = 0, + float worldSize = 1.0f, + bool hinting = false){ std::string error; FT_Face face = Font::loadFace(library, filename, error); if(error != ""){ @@ -1002,30 +1014,28 @@ static std::shared_ptr loadFont(FT_Library & library, const std::string & return std::shared_ptr {}; } - return std::make_shared (face, worldSize, hinting); + return std::make_shared (face, gpuTextureOffset, worldSize, hinting); } static void tryUpdateMainFont(FT_Library & library, const std::string & filename, const string & mainText, shared_ptr & mainFont, - Font::BoundingBox & bb){ + int gpuTextureOffset){ { cout << "tryUpdateMainFont" << endl; - auto font = loadFont(library, filename, 1.0f); + auto font = loadFont(library, filename, gpuTextureOffset); if(!font){ return; } font->dilation = 0.1f; - font->prepareGlyphsForText(mainText); + if(mainText != ""){ + font->prepareGlyphsForText(mainText); + } mainFont = std::move(font); - bb = mainFont->measure(0, 0, mainText); - cout << "tryUpdateMainFont loaded font" << endl; - cout << "mainText: " << mainText << endl; - cout << bb.minX << "-" << bb.maxX << endl; } } }