Как растушевать текст, раскрыть эффект - PullRequest
0 голосов
/ 29 апреля 2020

Я рендеринг текста с использованием freetype.

Рендеринг выполняется в типичном стиле рисования прямоугольника и отображения изображения текста на нем.

enter image description here

Я хочу раскрыть приведенный выше текст на основе переменной "effectAlphaValue"

, если значение для "effectAlphaValue" равно 100, чем весь текст должен быть виден.

когда значение «effectAlphaValue» равно 55, то так должен выглядеть текст.

enter image description here

Я смог достичь этого эффекта.

Проблема в том, что я не могу добавить этот эффект перо, как показано на рисунке ниже.

Здесь «effectAlphaValue» равно 55, но оно закрашено. enter image description here

Это код, в котором я раскрываю текстовые прямоугольники по отдельности на основе эффекта. псевдокод для реализации эффекта пера.

int currentCharNumber = 1;
int eachCharValue = 100 / totalNumberOfChars;  // what should be the value of each char for alpha opacity(spaces not included)
for (c = str.begin(); c != str.end(); c++)
        {
            Character ch = Characters[*c]; // get the char from the character map
            // Calculate the xPos and the yPos for the rectangle vbo here
            //////////////////////////////////////////////////////
            // Update VBO for each character
            GLfloat vertices[6][5] = {

                { xpos ,     ypos - h , 0.0 ,     0.0, 1.0 },
                { xpos + w , ypos ,     0.0 ,     1.0, 0.0 },
                { xpos ,     ypos,     0.0 ,    0.0, 0.0 },

                { xpos ,     ypos - h , 0.0,      0.0, 1.0 },
                { xpos + w , ypos - h , 0.0,      1.0, 1.0 },
                { xpos + w , ypos ,     0.0,       1.0, 0.0 }
            };

            // Render glyph texture over quad
            glBindTexture(GL_TEXTURE_2D, ch.TextureID);
            // Update content of VBO memory
            glBindBuffer(GL_ARRAY_BUFFER, this->VBO);
            glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(vertices), vertices);
            glBindBuffer(GL_ARRAY_BUFFER, 0);
            //============UPDate the alpha value for current char=======================

            if (*c != ' ') // only calculate alpha for non spaces
            {
                int startValue = (currentCharNumber - 1) * eachCharValue; // 
                int currentValue = effectAlphaValue - startValue;   
                float finalOpacity;
                float percentValueCurrent = ((float)currentValue  / (float)eachCharValue) * 100;                
                finalOpacity = ((float)percentValueCurrent / 100.0f);   
                finalOpacity = ceil(finalOpacity);
                lastAlphaValue = finalOpacity;              
                if (finalOpacity > 100.0)
                    finalOpacity = 100.0;

                ShaderManager::GetShader("TextShader").SetFloat("opacity", finalOpacity / 100.0f);  // set the current opacity
                currentCharNumber++;
            }
            // Render quad
            glDrawArrays(GL_TRIANGLES, 0, 6);
            // Now advance cursors for next glyph
            x += (ch.Advance >> 6); // Bitshift by 6 to get value in pixels (1/64th times 2^6 = 64)
            x += this->Kerning;             
        }   
    }
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...