opengl - 如何羽化文字显示效果
问题描述
我正在使用 freetype 渲染文本。
渲染以绘制矩形并将文本图像映射到其上的典型样式完成。
我想根据变量“effectAlphaValue”显示上述文本
如果“effectAlphaValue”的值为 100,那么整个文本应该是可见的。
当“effectAlphaValue”的值为 55 时,文本应该是这样的。
我已经能够达到这个效果。
问题是我无法添加羽化这种效果,如下图所示。
这里的“effectAlphaValue”是 55,但它是羽化的。
这是我根据 effectAlphaValue 单独显示文本矩形的代码。
如果有人可以指导我或向我展示如何实现羽毛效果的伪代码,我会非常高兴。
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;
}
}
}
解决方案
推荐阅读
- php - 需要基于php中的列值分组值的mysql数据
- javascript - 在 JSON 教科书中搜索
- r - 如何更改ggplot中的轴标签?
- android - Firebase 数据库实时时钟学习
- java - 如何在我的 Java 程序中找到 n=5033 的错误?
- bash - 如何通过bash将文件所有者mod编号复制到文件组?
- javascript - 使用 fetch 和 await 时如何将用户重定向到不同的页面?
- ios - 如何在 iOS 中仅获取可见日历
- php - 如何使用 AMQPMessage 发送数组 - RabbitMQ
- angular - 如何使用量角器测试日期选择器?